pushgateway的安装与使用
安装 使用
2023-09-11 14:21:21 时间
前言
环境:centos7.9 prometheus, version 2.5.0
pushgateway的使用
pushgateway
可以单独运行在任何节点上,并不一定要在被监控的客户端上,然后通过用户自定义开发脚本将需要监控的数据发送给pushgateway
,然后pushgateway
再把数据推送给prometheus server
。
下载安装pushgateway
GitHub
下载解压 直接运行,pushgateway
默认端口9091
,如下所示:
#pushgateway下载地址
wget wget https://github.com/prometheus/pushgateway/releases/download/v1.4.3/pushgateway-1.4.3.linux-amd64.tar.gz
tar -zxvf pushgateway-1.4.3.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/pushgateway-1.4.3.linux-amd64.tar.gz/
[root@node2 pushgateway-1.4.3.linux-amd64.tar.gz]# ll #解压之后就3个文件,一个可执行命令
total 16476
-rw-r--r-- 1 3434 3434 11357 May 31 03:07 LICENSE
-rw-r--r-- 1 3434 3434 487 May 31 03:07 NOTICE
-rwxr-xr-x 1 3434 3434 16853986 May 31 03:03 pushgateway #可执行命令
[root@node2 pushgateway-1.4.3.darwin-arm64]#
启动pushgateway,端口默认9091
#查看命令帮助,可知pushgateway的端口是9101
[root@node2 pushgateway-1.4.3.darwin-arm64]# ./pushgateway -h
#启动pushgateway
[root@node2 pushgateway-1.4.3.linux-amd64]# nohup ./pushgateway &
#查看端口
[root@node2 pushgateway-1.4.3.linux-amd64]# lsof -i:9091
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
pushgatew 79808 root 3u IPv6 16362297 0t0 TCP *:xmltec-xmlmail (LISTEN)
[root@node2 pushgateway-1.4.3.linux-amd64]#
查看pushgateway的页面
打开pushgateway
的web页面,http://192.168.118.133:9091
,发现Metrics栏没有任何数据。因为此时还没有客户端推送数据给pushgateway
。
修改Prometheus server 配置文件,定义一个job
在prometheus server
的prometheus.yml
文件中定义一个 job
,然后targets
指向pushgateway
所在的ip和9091
端口:
vim prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.118.129:9101']
- job_name: 'master'
static_configs:
- targets: ['192.168.118.131:9101']
- job_name: 'node1'
static_configs:
- targets: ['192.168.118.132:9101']
- job_name: 'node2'
static_configs:
- targets: ['192.168.118.133:9101']
- job_name: 'pushgateway' #定义一个job
static_configs:
- targets: ['192.168.118.133:9091'] #指定pushgateway所在的ip和端口
#重启 Prometheus server
[root@nginx prometheus-2.5.0.linux-amd64]# kill -9 206697 && nohup ./prometheus &
[1] 229403
[root@nginx prometheus-2.5.0.linux-amd64]# lsof -i:9090
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
prometheu 229404 root 3u IPv6 1017085 0t0 TCP *:websm (LISTEN)
prometheu 229404 root 6u IPv4 1012761 0t0 TCP localhost:50018->localhost:websm (ESTABLISHED)
prometheu 229404 root 7u IPv6 1007575 0t0 TCP localhost:websm->localhost:50018 (ESTABLISHED)
[root@nginx prometheus-2.5.0.linux-amd64]#
#这是打开http://192.168.118.129:9090/targets 就能看到pushgateway是up状态
编写脚本文件采集主机数据,然后推送给pushgateway
pushgateway启动之后本身没有任何抓取数据的功能,pushgateway只是被动的等待数据推送过来。
下面是一个简单抓取目标服务器的count_netstat_wait_connections
的脚本,然后将数据推送给pushgateway
vim pushgateway.sh #编写pushgateway脚本采集数据
#!/bin/bash
instance_name=`hostname -f | cut -d'.' -f1` #截取主机名
if [ $instance_name == "localhost" ];then
echo "Must FQDN hostname" #要求主机名不能是localhost,不要主机名区别不了
exit 1
fi
label="count_netstat_wait_connections" #定义一个key
count_netstat_wait_connections=`netstat -an| grep -i wait| wc -l` #定义values
#推送数据给pushgateway
echo "$label $count_netstat_wait_connections" | curl --data-binary @- http://192.168.118.133:9091/metrics/job/${instance_name}
#解析
curl --data-binary是将http post 请求中的二进制数据发送给http服务服务器,这里的http服务器指的就是pushgateway服务器;
指定pushgateway的ip地址和端口号,后面${instance_name}是指定job的名称,这里以主机名命名。
#指定脚本采集数据
[root@node1 opt]# bash pushgateway.sh
#写入定时任务采集
[root@node1 opt]# crontab -l
* * * * * bash /opt/pushgateway.sh
[root@node1 opt]#
#查看pushgateway的页面,这时发现Metrics已经有数据了
http://192.168.118.133:9091/#
#查看Prometheus server的页面,输入我们的key为count_netstat_wait_connections,已经能查出来数据了
http://192.168.118.129:9090/graph
count_netstat_wait_connections
相关文章
- 基于Linux命令行KVM虚拟机的安装配置与基本使用
- JMeter的下载以及安装使用
- 在Ubuntu环境下使用c++ vcpkg包管理 安装sqlite_orm包文件
- jumpserver安装详解
- 【Less】less的安装与环境配置
- ROS机器人程序设计(原书第2版)1.2.7 安装rosinstall
- 如何在 FreeBSD 10.2 上安装 Nginx 作为 Apache 的反向代理
- [转]RabbitMQ的安装与客户端的简单实用
- python从安装与使用pip到入门
- yum命令安装jenkins
- Android开发的插件Code Generator与LayoutCreator的安装与使用,提升你的开发效率
- btslab全攻略——搭建安装和sql注入
- Jenkins(持续集成)Windows版本安装
- 转 pt-online-schema-change安装使用详解
- 【npm】 npm的安装及简单使用 —— 写给初学者的编程教程(简单易懂)
- GitBook安装使用
- linux安装redis 完整步骤
- centos7;windows下安装和使用spice
- ubuntu14中 memcached安装与使用
- PL/SQL developer(绿色版)安装及配置
- node中MySQL的安装与使用
- ADB的安装与使用
- (原)使用1080Ti显卡时安装ubuntu16.04.1及驱动的步骤
- (原)ubuntu中安装tensorflow
- Windows环境安装DVWA
- ubuntu安装pytorch无法使用cuda解决方案