获取 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/
获取 Rancher 中 Prometheus 的数据的更多相关文章
- 在ASP.NET MVC控制器中获取链接中的路由数据
在ASP.NET MVC中,在链接中附加路由数据有2种方式.一种是把路由数据放在匿名对象中传递: <a href="@Url.Action("GetRouteData&quo ...
- Go net/http获取body中json格式数据
Go net/http获取body中json格式数据 package main import ( "encoding/json" "fmt" "io/ ...
- 数组:获取数组中最后一个数据end()函数
今天来学习一下end()函数 1.案例:直接获取数组中最后一个数据 代码部分 结果: 2.案例:从url中获取最后一个数据 代码部分: 结果: 总结: 1.有时候我们需要去获取数据库中,id最大的那个 ...
- HTML中获取input中单选按钮radio数据(性别例子)
个人学习整理 1.编写HTML <!doctype html> <html> <head> <meta charset="utf-8"&g ...
- 使用phpword获取doc中的表格数据
1. 首先确定使用phpword是可以读取word文档中表格里面的数据, 使用的phpword版本0.17.0 2.理解word文档内容的存储逻辑规则(这里只做简单概述) 一般做博文喜欢直接贴代码,直 ...
- php获取post中的json数据的实现方法
最近用到腾讯微博与PHP交互,腾讯把json数据post给PHP(腾讯推送数据时,每条数据是一个json格式的数据包,作为post的数据体(请注意post数据体没有参数,不是key=value形式,整 ...
- [SoapUI] 在SoapUI里获取Excel中多行数据并存入List
ArrayList<ArrayList<String>> getCellValuesH( String filePath, String sheetName,int tr1,i ...
- 9.SpringMVC和json结合传递数据 && 10.SpringMVC获取controller中json的数据
- 使用 UEditor 编辑器获取数据库中的数据
在 ThinkPHP 3.2.2 中,使用 UEditor 编辑器获取数据库中保存的数据,可以使用 UEditor 自身提供的方法. 首先在视图模板中实例化编辑器,这是出现编辑器界面的必须的行为: & ...
随机推荐
- 大一结业项目之一(C#晨曦超市管理系统 )
C#晨曦超市管理系统 我现是湖南工程职业技术学院大一的学生,很快 ...
- Redis命令geoXXX
1. Redis命令geoXXX 1.1. 介绍 自Redis 3.2开始,Redis基于geohash和有序集合提供了地理位置相关功能. Redis Geo模块包含了以下6个命令: GEOADD: ...
- 尝试在iOS上使用gRPC
简介 gRPC,google的远程过程调用框架,传输协议使用 HTTP2, 序列化协议使用 protobuf.gRPC 使用 HTTP2 传输协议传输 protobuf 序列化的二进制数据,有极高的效 ...
- Jetty启动报Error scanning entry META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class
近日在项目中集成Elasticsearch后,Jetty启动报错. 错误日志如下: Suppressed: |java.lang.RuntimeException: Error scanning en ...
- ngx-echarts 图表数据动态更新
使用echarts绘制图表时,初次赋值数据正常展示,重新获取数据之后,图表没有跟着动态刷新.解决的办法是: html文件 <div echarts [options]="chartOp ...
- adb命令之解锁打卡
adb devicesadb shell input keyevent 26 按手机电源键adb shell input swipe 400 1080 40 ...
- pdfium:创建CreateNewDoc
CreateNewDoc //创建文档 https://github.com/PureFusionOS/android_external_pdfium/blob/040b899a933cdb37 ...
- Revit 2019 下载链接
[安装环境]:win7/win8/win10 [64位下载] 百度网盘链接:pan.baidu.com/s/1Vq5Cnyj1G-oMNup_sXvxfQ 提取码:d6xd
- 【使用篇二】SpringBoot整合Filter(2)
两种方式: 通过注解扫描完成 Filter 组件的注册 通过方法完成 Filter 组件的注册 一.通过注解扫描完成 Filter 组件的注册 1. 编写Filter类 /** * SpringBoo ...
- 【Mybatis】CDATA
忽视内部尖括号那些东西