prometheus Learning Series XI: Use of Prometheus pushgateway

Due to network problems or security issues, our data may not be directly exposed to a entrypoint prometheus collection. This time it may need a pushgateway as a transit center to complete the work. prometheus or the use of pull mode to collect data pushgateway, our collection terminal by way of the push data to the push pushgateway, to complete the reported data.

pushgateway installation

[root@node01 src]# wget https://github.com/prometheus/pushgateway/releases/download/v0.10.0/pushgateway-0.10.0.linux-amd64.tar.gz
[root@node01 src]# tar xf pushgateway-0.10.0.linux-amd64.tar.gz 
[root@node01 src]# ll
total 8732
drwxr-xr-x. 2 root root       6 Nov  5  2016 debug
drwxr-xr-x. 2 root root       6 Nov  5  2016 kernels
drwxr-xr-x  2 3434 3434      54 Oct 10 19:29 pushgateway-0.10.0.linux-amd64
-rw-r--r--  1 root root 8940709 Oct 10 19:30 pushgateway-0.10.0.linux-amd64.tar.gz
[root@node01 src]# mv pushgateway-0.10.0.linux-amd64 /usr/local/^C
[root@node01 src]# mkdir /usr/local/prometheus
[root@node01 src]# mv pushgateway-0.10.0.linux-amd64 /usr/local/prometheus/
[root@node01 src]# cd  /usr/local/prometheus/
[root@node01 prometheus]# ls
pushgateway-0.10.0.linux-amd64
[root@node01 prometheus]# ln -s pushgateway-0.10.0.linux-amd64/ pushgateway
[root@node01 prometheus]# ll
total 0
lrwxrwxrwx 1 root root 31 Oct 11 04:00 pushgateway -> pushgateway-0.10.0.linux-amd64/
drwxr-xr-x 2 3434 3434 54 Oct 10 19:29 pushgateway-0.10.0.linux-amd64

pushgateway configuration

[root@node01 system]#  cd /usr/lib/systemd/system
[root@node01 system]#  vim pushgateway.service
[root@node01 system]# cat pushgateway.service 
[Unit]
Description=prometheus
After=network.target 

[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus/pushgateway
ExecStart=/usr/local/prometheus/pushgateway/pushgateway \
                --web.enable-admin-api  \
                --persistence.file="pushfile.txt" \
                --persistence.interval=10m 
[Install]
WantedBy=multi-user.target
[root@node01 system]# systemctl enable pushgateway 
Created symlink from /etc/systemd/system/multi-user.target.wants/pushgateway.service to /usr/lib/systemd/system/pushgateway.service.
[root@node01 system]# systemctl start pushgateway
[root@node01 system]# systemctl status pushgateway 

Test web page

 

Configuration acquisition push end

Adding a data, view results

[root@node02 ~]# !vim
vim push_memory.sh
#!/bin/bash
# desc push memory info

total_memory=$(free  |awk '/Mem/{print $2}')
used_memory=$(free  |awk '/Mem/{print $3}')

job_name="custom_memory"
instance_name="192.168.100.12"

cat <<EOF | curl --data-binary @- http://192.168.100.11:9091/metrics/job/$job_name/instance/$instance_name
#TYPE custom_memory_total  gauge
custom_memory_total $total_memory
#TYPE custom_memory_used  gauge
custom_memory_used $used_memory
EOF

# 执行导入
bash push_memory.sh

After inserting data renderings

Integrated prometheus

Add the collection pushgateway

# Add the following modifications prometheus.yml fragment 
  - job_name: " Custom-Memory-pushgateway " 
    #honor_labels: to true 
    static_configs:
     - Targets: [ " 192.168.100.11:9091 " ]

Continued to generate data

The implementation of the above push_memory.sh script that is only inserted once the data, we're using a scheduled task to push data to pushgateway the period.

 

[root@node02 ~]# crontab  -e 
no crontab for root - using an empty one
1 * * * * /root/push_memory.sh
[root@node02 ~]# chmod a+x push_memory.sh 

 

Renderings

 

And job label can be found instance bit of a problem, which is pushgateway filled, we can add honor to configure using our custom.

Modify configuration is as follows

  - job_name: "custom-memory-pushgateway"
    honor_labels: true
    static_configs:
    - targets: ["192.168.100.11:9091"]

Renderings

 to sum up

We can assist collected by pushgateway. In this scenario, we assume that this is 192.168.100.10 192.168.100.12 prometheus server to server is the network that does not make sense, but this ip address is 192.168.100.11 and two ip is through, there will be the server 192.168.100.11 deployment pushgateway above to serve as a bridge, to monitor the collection of data 192.168.100.12.

Guess you like

Origin www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_67_prometheus_pushgateway.html