Pushgetway安装和使用

news/2024/5/18 23:41:50 标签: prometheus

1、Pushgetway安装和使用

在这里插入图片描述

1.1 Pushgateway是什么

pushgateway 是另一种数据采集的方式,采用被动推送来获取监控数据的prometheus插件,它可以单独运行在

任何节点上,并不一定要运行在被监控的客户端。

首先通过用户自定义编写的脚本把需要监控的数据发送给 pushgateway,pushgateway 再将数据推送给对应的

Prometheus 服务。

对于短时运行、不支持轮询的任务,可以引入 pushgateway,将指标数值以 push 的方式推送到 pushgateway暂

存,然后 prometheus 从 pushgateway 中轮询。

PushGateway:短期存储指标数据。主要用于临时性的任务,各个目标主机可以上报数据到 pushgateway,然后

prometheus server 统一从 pushgateway 拉取数据。

Pushgateway 是 prometheus 的一个组件,prometheus server 默认是通过 exporter 主动获取数据(默认采取

pull 拉取数据),pushgateway 则是通过被动方式推送数据到 prometheus server,用户可以写一些自定义的监控

脚本把需要监控的数据发送给 pushgateway, 然后 pushgateway 再把数据发送给 Prometheus server。

1.2 使用Pushgateway的主要原因

1、因为Prometheus 采用 pull 模式,可能由于不在一个子网或者防火墙,导致 Prometheus 无法直接拉取各个

target 数据。

Prometheus 在一些情况下无法直接拉取各个 target 数据。

2、在监控业务数据的时候,需要将不同数据汇总,由 Prometheus 统一收集。

1.3 使用Pushgateway的弊端

由于以上原因,不得不使用 pushgateway,但在使用之前,有必要了解一下它的一些弊端:

1、将多个节点数据汇总到 pushgateway,如果pushgateway 挂了,受影响比多个 target 大。

通过单个 Pushgateway 监控多个实例时, Pushgateway 将会成为单点故障和潜在瓶颈。

2、Prometheus 拉取状态 up 只针对 pushgateway, 无法做到对每个节点有效。

3、Pushgateway 可以持久化推送给它的所有监控数据。 因此,即使你的监控已经下线,prometheus 还会拉取

到旧的监控数据,需要手动清理 pushgateway 不要的数据。

总:

  • Prometheus拉取状态只针对 pushgateway,不能对每个节点都有效。

  • Pushgateway出现问题,整个采集到的数据都会出现问题。

  • 监控下线,prometheus还会拉取到旧的监控数据,需要手动清理 pushgateway不要的数据。

1.4 Pushgateway流程图

在这里插入图片描述

我们编写脚本将数据发送到 Pushgateway,Pushgateway将数据 push 到 Prometheus。

1.5 与Prometheus结合使用流程图

通过客户端 POST数据至pushgateway,prometheus拉取pushgateway里数据,经过alertmanager报警规则触

发,到prometheusalert自定义模板,最后飞书机器人发送该报警信息。

在这里插入图片描述

1.6 Pushgateway使用

1.6.1 下载部署包

下载地址:

https://github.com/prometheus/pushgateway/releases/

这里下载 pushgateway-1.4.3.linux-amd64.tar.gz

https://github.com/prometheus/pushgateway/releases/download/v1.4.3/pushgateway-1.4.3.linux-amd64.tar.gz

1.6.2 解压

tar -xvf pushgateway-1.4.3.linux-amd64.tar.gz

1.6.3 启动

nohup ./pushgateway >> nohup.out 2>&1 &

1.6.4 测试

访问:http://192.168.54.195:9091/

在这里插入图片描述

1.6.5 在Prometheus配置

- job_name: pushgateway
  static_configs:
    - targets: ['192.168.54.195:9091']
      labels:
        instance: pushgateway

重新启动 Prometheus:

nohup ./prometheus --config.file=prometheus.yml >> nohup.out 2>&1 &

在这里插入图片描述

1.6.6 测试发送数据

# 推送指定的数据格式到pushgateway
# 将"metrics"字节赋值"3.6",向{job="test_job"}添加单条数据
$ echo "metric 3.6" | curl --data-binary @- http://192.168.54.195:9091/metrics/job/test_job

查看结果:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

# 添加复杂数据
cat <<EOF | curl --data-binary @- http://192.168.54.195:9091/metrics/job/test_job/instance/test_instance
node_memory_usage 36
node_memory_total 36000
EOF

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

# 利用shell脚本完成数据推送
$ vim push.sh
# 内容
node_memory_usages=$(free -m | grep Mem | awk '{print $3/$2*100}')
job_name="memory"
instance_name="192.168.54.195"
cat <<EOF | curl --data-binary @- http://192.168.54.195:9091/metrics/job/$job_name/instance/$instance_name
# TYPE node_memory_usages gauge
node_memory_usages $node_memory_usages
EOF
# 执行
./push.sh

在这里插入图片描述

1.6.7 定时任务定时推送数据

# 新建定时任务
crontab -e 
或者
vim /etc/crontab

第一种方式 crontab -e

  • 输入 crontab -e
  • 按下 a 键进入到编辑模式
  • 输入定时任务
  • 同时按下 ctrl+c 退出编辑模式
  • 按下 shift+: 输入 wq 退出 crontab

第二种方式 vim /etc/crontab

$ vim /etc/crontab
# 写入如下内容
1 * * * * sh /home/zhangshixing/prometheus/prometheus-2.34.0-rc.2.linux-amd64/push.sh
# 查看定时任务
# 第一种方式
$ crontab -l
1 * * * * sh /home/zhangshixing/prometheus/prometheus-2.34.0-rc.2.linux-amd64/push.sh
# 第二种方式
$ cat /var/log/cron
Mar  3 09:23:01 zsx crond[27252]: (root) RELOAD (/var/spool/cron/root)
$ cat /var/spool/cron/root
1 * * * * sh /home/zhangshixing/prometheus/prometheus-2.34.0-rc.2.linux-amd64/push.sh

1.6.8 删除某个组下的某实例的所有数据

curl -X DELETE http://192.168.54.195:9091/metrics/job/some_job/instance/some_instance
curl -X DELETE http://192.168.54.195:9091/metrics/job/some_job

1.7 Pushgateway使用方法

$ ./pushgateway --help
usage: pushgateway [<flags>]

The Pushgateway

Flags:
  -h, --help                     		Show context-sensitive help (also try --help-long and --help-man).
      --web.config.file=""       		[EXPERIMENTAL] Path to configuration file that can enable TLS or uthentication.
      --web.listen-address=":9091"		Address to listen on for the web interface, API, and telemetry.
      --web.telemetry-path="/metrics"	Path under which to expose metrics.
      --web.external-url=        		The URL under which the Pushgateway is externally reachable(可从外部访问Pushgateway的URL).
      --web.route-prefix=""      		Prefix for the internal routes of web endpoints. Defaults to the path of --web.external-url(web端点内部路由的前缀,默认为-web.external-url的路径).
      --web.enable-lifecycle     		Enable shutdown via HTTP request.
      --web.enable-admin-api     		Enable API endpoints for admin control actions.
      --persistence.file=""      		le to persist metrics. If empty, metrics are only kept in memory(持久化metrics的文件,如果该文件为空,则metrics只保留在内存中).
      --persistence.interval=5m  		The minimum interval at which to write out the persistence file(写入持久性文件的最小间隔).
      --push.disable-consistency-check	Do not check consistency of pushed metrics. DANGEROUS.                  
      --log.level=info           		Only log messages with the given severity or above. One of: [debug, nfo, warn, error]
      --log.format=logfmt        		Output format of log messages. One of: [logfmt, json]
      --version                  		Show application version.

1.8 docker部署pushgateway

搜索镜像:

$ docker search pushgateway

在这里插入图片描述

$ docker search prom/pushgateway

在这里插入图片描述

拉取镜像:

$ docker pull prom/pushgateway

在这里插入图片描述

启动:

$ docker run -d --name pushgateway -p 9091:9091 --network host prom/pushgateway

在这里插入图片描述

通过http://192.168.54.195:9091/进行访问:

在这里插入图片描述


http://www.niftyadmin.cn/n/1265994.html

相关文章

升序排列C++

Description 输入五个以上的正整数&#xff0c;进行升序排列&#xff0c;并按照样例打印出排序后的结果。提示&#xff08;python&#xff09;&#xff1a;两个以逗号分隔输入的整数&#xff0c;可以采用如下方法进行转换、分离&#xff1a; strinput() numseval(str) Inpu…

将宽度赋给高度_响应式网页中的高度设计,你认真的吗?

本文已经过原作者 Ahmad Shadeed 授权翻译大家看到这个标题可能会以为小智是不是又写错别字了 &#xff0c;响应式高度设计&#xff1f;你认真的吗&#xff1f;因为“响应式Web设计”通常是在多个宽度和设备尺寸上检查浏览器。我们一般通过减小宽度调整水平方向的响应能力&…

中值滤波_OpenCV图像处理专栏九 | 基于直方图的快速中值滤波算法

前言这是OpenCV图像处理专栏的第9篇文章&#xff0c;主要介绍一个基于直方图的快速中值滤波算法&#xff0c;希望对大家有帮助。算法原理传统的中值滤波是通过滑动窗口不断在图像上移动&#xff0c;求出窗口内的中值作为中心像素点的像素。在这个过程中显然存在大量的重复计算&…

spark 获取广播变量_Spark广播变量原理分析

我们知道多进程编程中&#xff0c;进程之间可以创建共享内存&#xff0c;这是最快的进程通信的方式。那么&#xff0c;对于分布式系统&#xff0c;如何共享数据呢&#xff1f;Spark提供了两种在Spark集群中创建和使用共享变量的机制&#xff1a;广播变量和累加器。本文介绍广播…

输出杨辉三角的前N行

Description 输出杨辉三角的前N行(N<20)。 Input 输入只有一行&#xff0c;包括1个整数N。(N<20) Output 输出只有N行&#xff0c;数与数之间有空格&#xff0c;每行最后没有空格&#xff0c;每个数的场宽是5。 Sample Input 5Sample Output 11 11 2 …

怎么重置imac_[重置系统]如何重置Mac电脑到出厂状态

当我们的爱机完成了它的使命需要卖给二手平台&#xff0c;或者你只是单纯地想把整个电脑恢复为出厂状态(虽然完全没这个必要)&#xff0c;那么就需要使用macOS的内置工具来实现这个过程&#xff0c;本文就介绍一下如何重置mac电脑系统。重置前的准备工作1.在启动macOS恢复之前&…

总分和平均分

Description 有N( 1 < N < 150 )个人,M( 2 < M < 50 )科成绩&#xff0c;计算N个人的总分、平均分及M科成绩的总分、平均分。 Input 第1行&#xff1a;2个整数N M。 第2..N1行&#xff1a;每行M个整数&#xff0c;第i1行为第i个人的M科成绩。 Output 第1..NM行…

maven实战 源码_spring-cloud-kubernetes的服务发现和轮询实战(含熔断)

全文概览本文由以下段落组成&#xff1a;环境信息常见的SpringCloud注册发现服务一览分析kubernetes上如何实现服务注册发现本章实战源码下载链接实战开发Account-Service服务(服务提供方)实战开发Web-Service服务(服务消费方)扩容验证ribbon轮询能力验证熔断能力环境信息本次实…