首页 > 其他分享 >Prometheus-pushgateway自定义监控项

Prometheus-pushgateway自定义监控项

时间:2023-03-11 22:35:00浏览次数:54  
标签:自定义 netstat Prometheus job pushgateway 推送 prometheus localhost

目录

一、前言

pushgateway相比较exporter是主动向服务器发送请求,pushgateway本身也是一个程序,可以运行在任意节点上(不是必须在被监控端),运行本身没有抓取数据的功能,它只是被动的等待推送过来,然后发现服务端。

二、pushgateway安装

1、GitHub下载解压
下载地址:https://github.com/prometheus/pushgateway/releases

wget https://github.com/prometheus/pushgateway/releases/download/v1.5.0/pushgateway-1.5.0.linux-amd64.tar.gz

2、运行pushgateway 默认端口是9091,可以使用--web.listen-address更改默认端口

tar zxf pushgateway-1.5.0.linux-amd64.tar.gz 
mv pushgateway-1.5.0.linux-amd64 /usr/local/pushgateway
cd /usr/local/pushgateway
./pushgateway --web.listen-address=:19091

3、配置system管理

cat >> /usr/lib/systemd/system/pushgateway.service << EOF
[Unit]
Description=prometheus pushgateway
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/pushgateway/pushgateway --web.listen-address=:19091
ExecStop=/usr/bin/kill -HUP \$MAINPID

[Install]
WantedBy=multi-user.target
EOF
systemctl  start pushgateway.service

4、Prometheus配置


  - job_name: "prometheus gateway"
    static_configs:
      - targets: ["localhost:19091"]
systemctl restart prometheus.service
systemctl status prometheus.service

5、验证
浏览器访问 IP:19091 验证pushgateway页面

验证Prometheus页面

三、pushgateway的使用

1、推送单个样本

echo "test_metric 1314521" | curl --data-binary @- http://localhost:19091/metrics/job/test_job

pushgateway页面可以看到推送的数据 如下图所示:

  • test_metric 1314521: 推送的键 值
  • job/test_job:标签job=test_job,多个标签直接往后添加即可
  • data-binary:发送post请求 以二进制数据

四、pushgateway脚本思路

使用shell脚本推送 netstat wait数量

#!/bin/bash
pushgateway="localhost:19091"
lable="count_netstat_wait_connections"
count_netstat_wait_connections=$(netstat -an|grep -i wait|wc -l)

if [ ${HOSTNAME} == "localhost" ];then
	echo "主机名不可使用 'localhost'" && exit 5
fi

# 这里定义了两个标签 job=pushgateway-1 hostname=${HOSTNAME}
echo "${lable} $count_netstat_wait_connections"|curl --data-binary @- http://${pushgateway}/metrics/job/pushgateway-1/hostname/${HOSTNAME}

执行脚本 检查是否能推送到pushgateway页面

使用定时任务执执行脚本,每3秒推送一次数据

crontab -e
* * * * * /usr/bin/sleep 3; /bin/bash /root/qinzt/pushgateway.sh

prometheus中查询数据

标签:自定义,netstat,Prometheus,job,pushgateway,推送,prometheus,localhost
From: https://www.cnblogs.com/qinziteng/p/17206858.html

相关文章

  • 为application.yml创建自定义配置并进行自动提示
    第一步:导入依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency>......
  • prometheus监控系统
    准备官网:https://prometheus.iohttps://grafana.com创建命名空间:mkdir-p/root/prometheus&&cd/root/prometheuscat>monitor-sa.yaml<<"EOF"kind:Nam......
  • vue 自定义组件 实现v-model双向绑定
    父组件:<childCompv-model="aaa"/><script>...data(){return{aaa:123}}...</script>自定义组件:childComp.vue<script>...props:......
  • 自定义返回接口类型
    ResponseResultpackagecom.mao.common;publicclassR<T>{//状态码IntegerresultCode;//具体结果Tresult;//响应的信息Stringre......
  • 自定义控件 QOpenGLWidget并实现缩放(纯代码)
    QScrollArea+QOpenGLWidget实现缩放,用于显示QImage。先自定义QOpenGLWidget,然后自定义QWidget(上图)glwidget.h#ifndefGLWIDGET_H#defineGLWIDGET_H#include<QO......
  • ORACLE自定义实现FIND_IN_SET函数
    FIND_IN_SET是mysql中的函数,见:MySQL中FIND_IN_SET函数oracle中没有FIND_IN_SET函数,oracle自定义实现FIND_IN_SET函数sql如下:--FIND_IN_SET函数CREATEORREPLACEFUN......
  • java自定义类数组的初始化
    也就是说,在声明了自定义类的数组之后,对每一个数组元素的初始化,都要为其new一个对象出来使得指针指向该对象,Java语言本身是不提供在自定义类数组声明时候自动创建新对象的方......
  • java自定义注解实现字段格式化(二)
    上篇java自定义注解实现字段格式化 我们自定义了另一个浮点数格式化的注解一、格式化处理器接口但在实际生产中,处理浮点数的格式化,可能还会有其他数据的格式化,比如日期......
  • LayoutAnimationController,补间动画,属性动画,值动画,自定义动画,帧动画
    最好的代码永远是自己写出来的布局<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools......
  • 6.prometheus监控mysql多实例
    一、背景介绍公司采用prometheus作为监控平台,经过资料查找,mysqld_exporter和mysql是[1:1],既每个mysql实例都需要起一个exporter进程来采集mysql监控数据,不过最近看github......