标量(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. java中值类型与引用类型的关系

    值类型:就是java的基本类型.byte.short.int.long.float.char.double.boolean 引用类型:类(class).接口(Interface).数组(Array) ...

  2. [Codeforces741D]Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths——dsu on tree

    题目链接: Codeforces741D 题目大意:给出一棵树,根为$1$,每条边有一个$a-v$的小写字母,求每个点子树中的一条最长的简单路径使得这条路径上的边上的字母重排后是一个回文串. 显然如果 ...

  3. android最最基础简单的保存xml代码

    y偶遇非常基础,我想直接上代码: MainActivity.java: package com.lgqchinese.xmlcreate; import android.support.v7.app. ...

  4. [国家集训队]排队 [cdq分治]

    题面 洛谷 和动态逆序对那道题没有什么区别 把一个交换换成两个删除和两个插入 #include <cstdio> #include <cstdlib> #include < ...

  5. Hdoj 1905.Pseudoprime numbers 题解

    Problem Description Fermat's theorem states that for any prime number p and for any integer a > 1 ...

  6. 【Luogu2197】NIM游戏(博弈论)

    题面 洛谷 题解 \(Nim\)游戏模板题 #include<iostream> #include<cstdio> #include<cstdlib> using ...

  7. THUSC2017题解

    THUSC2017题解 题目都是在LOJ上交的. chocolate LOJ#2977巧克力 这题看着就让人想起了百度之星复赛的\(T5\),就是这题. 因为种类的个数很多,所以把每个种类随意\(ra ...

  8. [luogu5004]专心OI - 跳房子【矩阵加速+动态规划】

    传送门:https://www.luogu.org/problemnew/show/P5004 分析 动态规划转移方程是这样的\(f[i]=\sum^{i-m-1}_{j=0}f[j]\). 那么很明 ...

  9. Asp.Net Output.Write()

    string name="张三" <div> <label>@Output.Write(name)</label> </div> 在 ...

  10. PWM实现ADC和DAC

    一.PWM实现AD 利用普通单片机的2个IO及一个运算放大器即可实现AD转换电路,而且很容易扩展成多通道.其占用资源少,成本低,AD 转换精度可以达到8位甚至更高,因此具有一定的实用价值. 1.1 硬 ...