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 的数据的更多相关文章

  1. 在ASP.NET MVC控制器中获取链接中的路由数据

    在ASP.NET MVC中,在链接中附加路由数据有2种方式.一种是把路由数据放在匿名对象中传递: <a href="@Url.Action("GetRouteData&quo ...

  2. Go net/http获取body中json格式数据

    Go net/http获取body中json格式数据 package main import ( "encoding/json" "fmt" "io/ ...

  3. 数组:获取数组中最后一个数据end()函数

    今天来学习一下end()函数 1.案例:直接获取数组中最后一个数据 代码部分 结果: 2.案例:从url中获取最后一个数据 代码部分: 结果: 总结: 1.有时候我们需要去获取数据库中,id最大的那个 ...

  4. HTML中获取input中单选按钮radio数据(性别例子)

    个人学习整理 1.编写HTML <!doctype html> <html> <head> <meta charset="utf-8"&g ...

  5. 使用phpword获取doc中的表格数据

    1. 首先确定使用phpword是可以读取word文档中表格里面的数据, 使用的phpword版本0.17.0 2.理解word文档内容的存储逻辑规则(这里只做简单概述) 一般做博文喜欢直接贴代码,直 ...

  6. php获取post中的json数据的实现方法

    最近用到腾讯微博与PHP交互,腾讯把json数据post给PHP(腾讯推送数据时,每条数据是一个json格式的数据包,作为post的数据体(请注意post数据体没有参数,不是key=value形式,整 ...

  7. [SoapUI] 在SoapUI里获取Excel中多行数据并存入List

    ArrayList<ArrayList<String>> getCellValuesH( String filePath, String sheetName,int tr1,i ...

  8. 9.SpringMVC和json结合传递数据 && 10.SpringMVC获取controller中json的数据

  9. 使用 UEditor 编辑器获取数据库中的数据

    在 ThinkPHP 3.2.2 中,使用 UEditor 编辑器获取数据库中保存的数据,可以使用 UEditor 自身提供的方法. 首先在视图模板中实例化编辑器,这是出现编辑器界面的必须的行为: & ...

随机推荐

  1. charles注册码及中文版本,支持window和mac

    安装证书: 安装完证书之后设置代理 2个* ,代表全部 注册码: Registered Name: https://zhile.io License Key: 48891cf209c6d32bf4 破 ...

  2. ES6 入门系列 ArrayBuffer

    由来 推荐在这里阅读 js操作二进制数据三兄弟 ArrayBuffer对象, TypeArray视图和DataView视图 它们都以数组的语法处理二进制数据,所以统称为二进制数组 ::: tip 二进 ...

  3. 剑指offer 9-10:青蛙跳台阶与Fibonacii数列

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 问题分析 我们将跳法个数y与台阶数n视为一个函数关系,即y=f(n). ...

  4. 章节十四、9-Actions类鼠标悬停、滚动条、拖拽页面上的元素

    一.鼠标悬停 1.在web网站中,有一些页面元素只需要我们将鼠标指针放在上面就会出现被隐藏的下拉框或者其它元素,在自动化的过程中我们使用Actions类对鼠标进行悬停操作. 2.案例演示 packag ...

  5. 9.为什么要进行系统拆分?如何进行系统拆分?拆分后不用 dubbo 可以吗?

    作者:中华石杉 面试题 为什么要进行系统拆分?如何进行系统拆分?拆分后不用 dubbo 可以吗? 面试官心理分析 从这个问题开始就进行分布式系统环节了,现在出去面试分布式都成标配了,没有哪个公司不问问 ...

  6. I2C 挂死,SDA一直为低问题分析【转】

    转自:https://blog.csdn.net/winitz/article/details/72460775 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csd ...

  7. packstack快速部署openstack

    环境准备 建议16GB RAM sed -i '/^SELINUX/s/enforcing/disabled/' /etc/selinux/config systemctl stop firewall ...

  8. php、mysql查询当天,查询本周,查询本月的数据实例(字段是时间戳)

    php.mysql查询当天,查询本周,查询本月的数据实例(字段是时间戳) //其中 video 是表名: //createtime 是字段: // //数据库time字段为时间戳 // //查询当天: ...

  9. opencv旋转图像

    #include <opencv2\opencv.hpp> /* @param o The customer origin @param x The customer x @Note Th ...

  10. 大宗商品市场的未来王者 | 现货贸易商PK期货风险管理子公司

    https://mp.weixin.qq.com/s/z-kkeIor6vDb9Oer73Ct6w 大宗商品市场卧虎藏龙,参与者众多,然而能称之为王者的却寥寥无几. 在国外,以嘉能可.托克.摩科瑞为代 ...