【prometheus】Pushgateway安装和使用

ops/2024/10/18 12:25:20/

目录

一、Pushgateway概述

1.1 Pushgateway简介

1.2 Pushgateway优点

1.3 pushgateway缺点

二、测试环境

三、安装测试

3.1 pushgateway安装

3.2 prometheus添加pushgateway

3.3 推送指定的数据格式到pushgateway

1.添加单条数据

2.添加复杂数据

3.SDk-prometheus-client使用



【Prometheus】概念和工作原理介绍_prometheus工作原理-CSDN博客

【Prometheus】k8s集群部署node-exporter_kubectl 安装 promethues node-exporter-CSDN博客

prometheus】k8s集群部署prometheus server-CSDN博客

prometheus】k8s集群部署Grafana安装和配置|Prometheus监控K8S

prometheus】k8s集群部署AlertManager实现邮件和钉钉告警-CSDN博客

prometheus监控MySQL并实现可视化-CSDN博客

prometheus监控nginx-CSDN博客


一、Pushgateway概述


1.1 Pushgateway简介


Pushgateway是prometheus的一个组件,prometheus server默认是通过exporter主动获取数据(默认采取pull拉取数据),pushgateway则是通过被动方式推送数据到prometheus server,用户可以写一些自定义的监控脚本把需要监控的数据发送给pushgateway, 然后pushgateway再把数据发送给Prometheus server。

1.2 Pushgateway优点


  • Prometheus 默认采用定时pull 模式拉取targets数据,但是如果不在一个子网或者防火墙,prometheus就拉取不到targets数据,所以可以采用各个target往pushgateway上push数据,然后prometheus去pushgateway上定时pull数据
  • 监控业务数据的时候,需要将不同数据汇总, 汇总之后的数据可以由pushgateway统一收集,然后由 Prometheus 统一拉取。

1.3 pushgateway缺点


  • Prometheus拉取状态只针对 pushgateway, 不能对每个节点都有效;
  • Pushgateway出现问题,整个采集到的数据都会出现问题
  • 监控下线,prometheus还会拉取到旧的监控数据,需要手动清理 pushgateway不要的数据。

二、测试环境


IP

主机名

192.168.2.139

master1

192.168.40.140

node1


三、安装测试


3.1 pushgateway安装


在node1节点操作

docker pull prom/pushgateway
docker run -d --name pushgateway -p 9091:9091 prom/pushgateway

在浏览器访问192.168.2.140:9091出现如下ui界面

3.2 prometheus添加pushgateway


修改prometheus-cfg.yaml文件

- job_name: 'pushgateway'scrape_interval: 5sstatic_configs:- targets: ['192.168.2.140:9091']honor_labels: true

更新

kubectl apply -f prometheus-alertmanager-cfg.yaml
kubectl delete -f prometheus-alertmanager-deploy.yaml
kubectl apply  -f prometheus-alertmanager-deploy.yaml

登录prometheus http://192.168.2.139:30242/targets

3.3 推送指定的数据格式到pushgateway


1.添加单条数据

# 向 {job="test_job"} 添加单条数据:
echo " metric 3.6" | curl --data-binary @- http://192.168.2.140:9091/metrics/job/test_job

这里需要注意的是将<key & value>推送给pushgateway,curl --data-binary是将HTTP POST请求中的数据发送给HTTP服务器(pushgateway),和用户提交THML表单时浏览器的行为是一样的,HTTP POST请求中的数据为纯二进制数据。

prometheus web中查询

2.添加复杂数据

# 添加复杂数据
cat <<EOF | curl --data-binary @- http://192.168.2.140:9091/metrics/job/test_job/instance/test_instance
# TYPE node_memory_usage gauge
node_memory_usage 26
# TYPE memory_total gauge
node_memory_total 26000
EOF

这条连接主要分为三个部分:

  • http://192.168.2.143:9091/metrics/job/test_job:这是URL的主location,发送到哪个URL
  • job/test_job:表示是推送到哪个prometheus定义的job里面,上面我们定义的job_name为pushgateway
  • instance/test_instance:表示推送后显示的主机名称是什么,从上面pushgateway图也可以看出

如下是删除某个实例

# 删除某个组下某个实例的所有数据
curl -X DELETE http://192.168.2.140:9091/metrics/job/test_job/instance/test_instance# 删除某个组下的所有数据:
curl -X DELETE http://192.168.2.140:9091/metrics/job/test_job

3.SDk-prometheus-client使用


python安装 prometheus_client

使用 pip 工具可以非常方便地安装 prometheus_client:

测试脚本

# -*- coding: utf-8 -*-# 导入所需的库
from prometheus_client import CollectorRegistry, Gauge, push_to_gatewayif __name__ == '__main__':# 定义和注册指标registry = CollectorRegistry()labels = ['req_status', 'req_method', 'req_url']g_one = Gauge('requests_total', 'url请求次数', labels, registry=registry)g_two = Gauge('avg_response_time_seconds', '1分钟内的URL平均响应时间', labels, registry=registry)# 收集和记录指标数据g_one.labels('200','GET', '/test/url').set(1) #set设定值g_two.labels('200','GET', '/test/api/url/').set(10) #set设定值# 推送指标数据到Pushgatewaypush_to_gateway('http://192.168.2.140:9091', job='SampleURLMetrics', registry=registry)

在这个示例中,我们定义了一个名为requests_total的指标,记录了一个值为1和10的示例数据,并将指标数据推送到了名为example_job的job中。


http://www.ppmy.cn/ops/39207.html

相关文章

(第15天)【leetcode题解】459、重复的子字符串

目录 459、重复的子字符串题目描述暴力匹配思路代码 字符串匹配思路代码与暴力匹配的不同 KMP解法思路代码KMP算法的核心和用途 459、重复的子字符串 题目描述 给定一个非空的字符串 s &#xff0c;检查是否可以通过由它的一个子串重复多次构成。 暴力匹配 思路 推理 如果…

内存拆解分析表:学习版[图片]

对拆解system中主要是对比测试机和对比机之间的差距&#xff0c;测试机那些地方高于对比机 拆解表&#xff0c;作为理解 在拆解表中system测试机比对比机多出113M 这说明是有问题的 对system拆解&#xff1a; system12345对比机9102294380941069391081628测试机10252010331…

服务端JavaScript(Node.js)与去IO编程:Node.js的事件驱动和非阻塞IO模型,它是如何使JavaScript走向后端的

在Node.js中&#xff0c;JavaScript代码运行在V8引擎上。由于JavaScript是单线程语言&#xff0c;一次只能处理一个事件。为了解决这个问题&#xff0c;Node.js引入了事件驱动模型。每个进行IO操作的函数都是异步的&#xff0c;当这个函数被调用的时候&#xff0c;它不会立即执…

一键追爆款,GPT一键改文‌‍‬⁣⁡​⁤⁢​⁢⁡⁣‬‍‌​​‬ ​‍⁤‬ ‬⁡⁡⁡‍‌‬⁡⁡⁢‬⁤⁢⁢⁤​‍‌​​‬ ​⁣‌,绘唐3,绘唐工具

ai画影满足你的制作要求 一键追爆款&#xff0c;GPT一键改文 AI推文小说&漫画解说&解压混剪 人物定义&#xff0c;角色定义&#xff0c;lora转换&#xff0c;模型转换&#xff0c;可视化参考满足 一键追爆款 一键挂机生成&#xff0c;效果更精彩&#xff0c;使用更方…

设计模式——享元模式(Flyweight)

享元模式&#xff08;Flyweight Pattern&#xff09;是一种软件设计模式&#xff0c;它运用共享技术来有效地支持大量细粒度对象的复用。以下是关于享元模式的详细解释&#xff1a; 定义 享元模式使用共享物件&#xff0c;以尽可能减少内存使用量以及分享信息给尽可能多的相似…

android进阶-Binder

参考&#xff1a;Android——Binder机制-CSDN博客 机制&#xff1a;Binder是一种进程间通信的机制 驱动&#xff1a;Binder是一个虚拟物理设备驱动 应用层&#xff1a;Binder是一个能发起进程间通信的JAVA类 Binder相对于传统的Socket方式&#xff0c;更加高效Binder数据拷贝…

【网络安全】一次sql注入问题的处理

目录 问题 10.60.100.194&#xff0c;修改之前 修改方案 问题解决 测试过程 问题思考与总结 问题 一次sql注入问题的筛查报告&#xff0c;主要是sql注入的问题资源-CSDN文库 doc-new\20-设计文档\34-Mesh设备管理\100-网络安全 10.60.100.194&#xff0c;修改之前 修改…

使用单片机的IO引脚直接驱动段码屏

使用单片机的IO引脚直接驱动段码屏,目的是为了降低成本。这种古老的应用,在低功耗产品中比较多见。 如:水表&#xff0c;燃气表等需要电池供电的产品。 下面纯属个人理解&#xff0c;未经测试。 1/3Duty表示LCD共有3个COM引脚,分别占显示周期的1/3 1/2BIAS表示电压0和VCC 1、…