获取 Rancher 中 Prometheus 的数据
1、需求
在 rancher 应用商店添加集群监控,会安装 prometheus、grafana;需要从 prometheus 的 api 中收集 pod 的一些信息。
查看grafana 配置的数据源为:http://prometheus-operated:9090
遂用 curl 请求如下:
curl http://prometheus-operated:9090/api/v1/query?query=container_cpu_usage_seconds_total
unauthorized
提示没有授权。
2、查找原因
查看官网介绍了basic auth 方式,采用 nginx 作为代理,配置了验证信息。遂想着 rancher 是不是也配置了代理;查看rancher 信息:
应用商店添加集群监控 prometheus,会创建如下信息:
命名空间: cattle-prometheus,
工作负载:prometheus-cluster-monitoring,
工作负载中包含如下5个容器:
prometheus #监听9090端口
prometheus-config-reloader
rules-configmap-reloader
prometheus-proxy #监听8080端口
prometheus-agent
查看到 prometheus-proxy 代理了9090 端口,并监听8080端口,其中还配置了 Authorization
proxy_set_header Authorization "Bearer eyJhbGciOiJSL3j-89LHMtCQCzHrmk12uUP4SI425bxKJEg........";
proxy_pass_header Authorization;
这样我们只需要请求 prometheus-cluster-monitoring 的 8080 端口即可,不用配置 Authorization 就可以访问数据了。
3、解决
配置服务发现,暴露出 prometheus-cluster-monitoring 的 8080 端口
名称:http-api
命名空间: cattle-prometheus
解析到:Pod
标签:
app=prometheus
chart=prometheus-0.0.
release=cluster-monitoring
类型:Headless Service
端口映射:
端口名称:
服务端口:
协议:tcp
目标端口:
然后请求 http-api
curl http://http-api:8080/api/v1/query?query=container_cpu_usage_seconds_total
可以看到返回了数据。
4、外部访问
要想外部也想要访问该服务,还需要配置负载均衡
1)域名 api-prometheus-operated.wmq.com 指向 http-api 服务的 8080 端口;
2)配置域名解析到 ingress;
3)获取数据
curl http://api-prometheus-operated.wmq.com/api/v1/query?query=container_cpu_usage_seconds_total
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"__name__": "container_cpu_usage_seconds_total",
"container": "POD",
"endpoint": "https-metrics",
"instance": "172.16.5.74:10250",
"job": "expose-kubelets-metrics",
"namespace": "cattle-prometheus",
"node": "dev-k8s-master-server-01",
"pod": "exporter-node-cluster-monitoring-h8ph2",
"service": "expose-kubelets-metrics"
},
"value": [
1573700778.551,
"0.026998712"
]
}
}
}
参考:
官网介绍http api:https://prometheus.io/docs/prometheus/latest/querying/api/
官网介绍functions:https://prometheus.io/docs/prometheus/latest/querying/functions/
最新文章
- KD-tree(2维)
- AFNetworking菊花转圈圈
- python2 urllib 笔记
- Linux 不挂载设备,获取设备的文件系统信息
- 开发板挂载nfs服务器错误解析
- 《SDN核心技术剖析和实战指南》3.1控制器核心技术读书笔记
- IDEA12 KeyGen Download List
- android实现点击短链接进入应用 并获得整个连接的内容
- 假设给Contact的List加一个用字母排序的导航
- cookie,sessionstorage,localstorage区别
- 查找算法(I) 顺序查找 二分查找 索引查找
- BCB F12切换界面 显示异常
- mysql 生成时间序列数据 - 存储过程
- 异常:Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.che ckState(ZLjava/lang/String;I)V
- Requires: libc.so.6(GLIBC_2.14)(64bit)
- 文件描述符fd、文件指针fp和vfork()
- Docker 与 虚拟机比较
- RabbmitMQ-Publish/Subscribe
- SQL SERVER 2005 数据库置疑修复
- U盘量产大致研究思路
热门文章
- Linux nodejs 安装以及配置环境
- git did not exit cleanly (exit code 1) 的解决办法
- SAP 同一个序列号可以同时出现在2个不同的HU里?
- 初识.netCore以及如何vs2019创建项目和发布
- 【Idea】idea中编译后无法提示错误信息的解决方案
- Python的爬虫利器之urllib
- python requests访问https的链接,不打开fiddler的情况下不报错;若是打开fiddler则报ssl错误,请求中添加verify=False,会报警告;若不想看到警告,有3种方式;
- JS三座大山再学习 ---- 作用域和闭包
- VirtualBox + vagrant 使用虚拟机
- 【Spring Data JPA篇】项目环境搭建(一)