Prometheus-自定义Node_Exporter
标量(Scalar):一个浮点型的数字值
标量只有一个数字,没有时序。
需要注意的是,当使用表达式count(http_requests_total),返回的数据类型,依然是瞬时向量。用户可以通过内置函数scalar()将单个瞬时向量转换为标量。
Prometheus-自定义Exporter-使用flask
#!/usr/bin/python
# -*- coding:utf-8 -*-
from flask import Flask,request,render_template,jsonify,Markup
import json import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
#定义一个全局字典
Show_Prometheus_Handler = { } app = Flask(__name__) @app.route('/send_data',methods={'GET','POST'})
def send_data_to_dict():
if request.method == "GET":
return "method error,please use post method!"
else:
# 向dict里注册
global Show_Prometheus_Handler message = request.data
#print(request.data)
message_to_json = json.loads(message)
metric = message_to_json.get("metric",None)
type_staus = message_to_json.get("counterType",None)
value = message_to_json.get("value",None)
tags = message_to_json.get("tags",None)
endpoint = message_to_json.get("endpoint",None)
# 生成字段
tag_list = []
for tag in tags.split(","):
t1,t2 = tag.split("=")
tag_list.append('{0}="{1}"'.format(t1,t2))
else:
tag_list.append('%s="%s"' %("endpoint",endpoint)) Show_Prometheus_Handler[metric] = '# HELP %s prometheus collected metric.\n# TYPE %s %s\n%s{%s} %s' %(metric,metric,type_staus.lower(),metric,",".join(tag_list),value)
#print(Show_Prometheus_Handler[metric]) return "ok" @app.route('/metrics',methods=['GET','POST'])
def get_metrics():
if request.method == "GET":
metric_list = []
for _,value in Show_Prometheus_Handler.items():
metric_list.append(value)
content_msg = Markup('{0}'.format("\n".join(metric_list)))
return render_template('status.html',content=content_msg), {'Content-Type': 'text/plain; version=0.0.4'} @app.route("/clean_metrics",methods=["GET","POST"])
def clean_metrics():
if request.method == "GET":
global Show_Prometheus_Handler
Show_Prometheus_Handler = {}
return "clean_ok" if __name__ == '__main__':
app.run("0.0.0.0",port=7777,threaded=True)
需要注意的点 当Prometheus 出现Navtive Token的时候 需要在返回html的时候 加上 {'Content-Type': 'text/plain; version=0.0.4'} Prometheus才能正常拉取数据.
Prometheus-自定义Node_Exporter的更多相关文章
- Prometheus 自定义exporter 监控key
当Prometheus的node_exporter中没有我们需要的一些监控项时,就可以如zabbix一样定制一些key,让其支持我们所需要的监控项. 例如,我要根据 逻辑cpu核数 来确定load的告 ...
- Prometheus自定义监控内容
Prometheus自定义监控内容 一.io.micrometer的使用 1.1 Counter 1.2 Gauge 1.3 Timer 1.4 Summary 二.扩展 相关内容原文地址: 博客园: ...
- Grafana+Prometheus通过node_exporter监控Linux服务器信息
Grafana+Prometheus通过node_exporter监控Linux服务器信息 一.Grafana+Prometheus通过node_exporter监控Linux服务器信息 1.1nod ...
- prometheus、node_exporter设置开机自启动
方法一.写入rc.local 在/etc/rc.local文件中编辑需要执行的脚本或者命令,我个人习惯用这个,因人而异,有的项目可能需要热加载配置文件,用服务会更好 #普罗米修斯启动,需要后面接con ...
- prometheus + grafana + node_exporter + alertmanager 的安装部署与邮件报警 (一)
大家一定要先看详细的理论教程,再开始搭建,这样报错后才容易找到突破口 参考文档 https://www.cnblogs.com/afterdawn/p/9020129.html https://www ...
- prometheus、node_exporter、cAdvisor常用参数
本节将介绍一下我在使用过程中用到的promethues.node_exporter.cAdvisor的常用参数,做一个总结 一.prometheus prometheus分为容器安装和二进制文件安装, ...
- prometheus自定义监控指标——实战
上一节介绍了pushgateway的作用.优劣以及部署使用,本机通过几个实例来重温一下自定义监控指标是如何使用的. 一.监控容器启动时间(shell) 使用prometheus已经两个月了,但从未找到 ...
- prometheus自定义监控指标——入门
grafana结合prometheus提供了大量的模板,虽然这些模板几乎监控到了常见的监控指标,但是有些特殊的指标还是没能提供(也可能是我没找到指标名称).受zabbix的影响,自然而然想到了自定义监 ...
- Prometheus自定义指标
1. 自定义指标 为了注册自定义指标,请将MeterRegistry注入到组件中,例如: public class Dictionary { private final List<String ...
- Prometheus【node_exporter】+grafana监控云主机
下面说一下这个开源软件的安装实践过程,目标如下: 在监控服务器上安装prometheus 在被监控环境上安装exporter 安装grafana 在监控服务器上安装prometheus 开始安装pro ...
随机推荐
- word公式大小
下面给出MathType与Word对应的字体关系,大家可以根据自己的实际需求,调整自己的公式大小. MathType与Word对应的字体关系示例 以上给大家详细介绍了调整MathType公式字体大小 ...
- a标签实现锚点功能
a标签实现锚点功能 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- System.Diagnostics.Process启动Civil 3D及AutoCAD
QQ群友提出问题, 如何启动Civil 3D或者AutoCAD, Kean的博客里有相关的文章 http://through-the-interface.typepad.com/through_the ...
- HDU 4256 翻译罗马数字
参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6414173.html The Famous Clock Time Limit: 2000/1000 ...
- idea maven +spring mvc
1.步骤一 2.目录结构 3.maven <!--测试--> <dependency> <groupId>junit</groupId> <art ...
- IDEA 安装 Sonalint失败
1.直接在线安装[Plugins]-[Browse reponsitories...],安不上,FQ了以后还是安不上 2.下载了离线的Sonalint 插件包,通过引用外部插件的方式,[Install ...
- php unset对json_encode的影响
先运行一段php代码: $a = Array(0=>'hello world', 1=>'girl', 2=>'boy'); var_dump(json_encode($a)); u ...
- Android ListView item 点击事件失效问题的解决
关于ListView点击无效,item无法相应点击事件的问题,网上有很多, 大致可分为俩种情况, 一种是 item中存在 ImageButton 等可以点击的组件,这会抢先获得ListView的焦点. ...
- 【CF833D】Red-Black Cobweb(点分治)
[CF833D]Red-Black Cobweb(点分治) 题面 CF 有一棵树,每条边有一个颜色(黑白)和一个权值,定义一条路径是好的,当且仅当这条路径上所有边的黑白颜色个数a,b满足2min(a, ...
- stm32使用rt-thread在文件《stm32f1xx_hal.h》中头文件包含顺序引出的错误
@2019-01-24 [小记] 在学习 rt-thread BSP制作过程中,发现文件<stm32f1xx_hal.h>中 Env工具生成的原始顺序 1. #include " ...