标量(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的更多相关文章

  1. Prometheus 自定义exporter 监控key

    当Prometheus的node_exporter中没有我们需要的一些监控项时,就可以如zabbix一样定制一些key,让其支持我们所需要的监控项. 例如,我要根据 逻辑cpu核数 来确定load的告 ...

  2. Prometheus自定义监控内容

    Prometheus自定义监控内容 一.io.micrometer的使用 1.1 Counter 1.2 Gauge 1.3 Timer 1.4 Summary 二.扩展 相关内容原文地址: 博客园: ...

  3. Grafana+Prometheus通过node_exporter监控Linux服务器信息

    Grafana+Prometheus通过node_exporter监控Linux服务器信息 一.Grafana+Prometheus通过node_exporter监控Linux服务器信息 1.1nod ...

  4. prometheus、node_exporter设置开机自启动

    方法一.写入rc.local 在/etc/rc.local文件中编辑需要执行的脚本或者命令,我个人习惯用这个,因人而异,有的项目可能需要热加载配置文件,用服务会更好 #普罗米修斯启动,需要后面接con ...

  5. prometheus + grafana + node_exporter + alertmanager 的安装部署与邮件报警 (一)

    大家一定要先看详细的理论教程,再开始搭建,这样报错后才容易找到突破口 参考文档 https://www.cnblogs.com/afterdawn/p/9020129.html https://www ...

  6. prometheus、node_exporter、cAdvisor常用参数

    本节将介绍一下我在使用过程中用到的promethues.node_exporter.cAdvisor的常用参数,做一个总结 一.prometheus prometheus分为容器安装和二进制文件安装, ...

  7. prometheus自定义监控指标——实战

    上一节介绍了pushgateway的作用.优劣以及部署使用,本机通过几个实例来重温一下自定义监控指标是如何使用的. 一.监控容器启动时间(shell) 使用prometheus已经两个月了,但从未找到 ...

  8. prometheus自定义监控指标——入门

    grafana结合prometheus提供了大量的模板,虽然这些模板几乎监控到了常见的监控指标,但是有些特殊的指标还是没能提供(也可能是我没找到指标名称).受zabbix的影响,自然而然想到了自定义监 ...

  9. Prometheus自定义指标

    1.  自定义指标 为了注册自定义指标,请将MeterRegistry注入到组件中,例如: public class Dictionary { private final List<String ...

  10. Prometheus【node_exporter】+grafana监控云主机

    下面说一下这个开源软件的安装实践过程,目标如下: 在监控服务器上安装prometheus 在被监控环境上安装exporter 安装grafana 在监控服务器上安装prometheus 开始安装pro ...

随机推荐

  1. Jquery中val方法使用的坑

    Jquery中val方法使用 val()// 取得第一个匹配元素的当前值 val(val)// 设置所有匹配元素的值 val([val1, val2])// 设置多选的checkbox.多选selec ...

  2. mysql 测试php连接问题

    <?php$servername = "shuhua.dbhost";$username = "shuhua_user";$password = &quo ...

  3. F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)

    题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树  但是没有push_up  最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段  思路是 ...

  4. 树形DP和状压DP和背包DP

    树形DP和状压DP和背包DP 树形\(DP\)和状压\(DP\)虽然在\(NOIp\)中考的不多,但是仍然是一个比较常用的算法,因此学好这两个\(DP\)也是很重要的.而背包\(DP\)虽然以前考的次 ...

  5. 用牛顿-拉弗森法定义平方根函数(Newton-Raphson method Square Root Python)

    牛顿法(Newton’s method)又称为牛顿-拉弗森法(Newton-Raphson method),是一种近似求解实数方程式的方法.(注:Joseph Raphson在1690年出版的< ...

  6. python学习日记(格式化输出,初始编码,运算符)

    格式化输出 顾名思义,按照个人意愿定制想输出的格式. name = input('请输入姓名:') age = int(input('请输入年龄:')) job = input('请输入工作:') h ...

  7. Add Zabbix Agent

    添加第三方源进行安装CentOS/RHEL 7:# rpm -Uvh http://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2. ...

  8. 【比赛】NOIP2018 保卫王国

    DDP模板题 #include<bits/stdc++.h> #define ui unsigned int #define ll long long #define db double ...

  9. BZOJ1095 [ZJOI2007] Hide 捉迷藏 (括号序列 + 线段树)

    题意 给你一颗有 \(n\) 个点的树 , 共有 \(m\) 次操作 有两种类别qwq 将树上一个点染黑/白; 询问树上最远的两个黑点的距离. \((n \le 200000, m ≤500000)\ ...

  10. 牛客练习赛31 D神器大师泰兹瑞与威穆

    双链表搞完了 #include<bits/stdc++.h> using namespace std; #define maxn 1000005 int tot,bac[maxn],fa[ ...