Prometheus PushGateway 脚本推送:
安装PushGateway:
cd /opt
sudo wget https://github.com/prometheus/pushgateway/releases/download/v1.5.1/pushgateway-1.5.1.linux-amd64.tar.gz
sudo tar -xvzf pushgateway-1.5.1.linux-amd64.tar.gz
sudo mv pushgateway-1.5.1.linux-amd64 pushgateway
启动 Pushgateway:
sudo vim /etc/systemd/system/pushgateway.service
[Unit]
Description=Prometheus Pushgateway
After=network.target
[Service]
User=root
ExecStart=/opt/pushgateway/pushgateway
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start pushgateway
sudo systemctl enable pushgateway
配置Prometheus server:
sudo vim /opt/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'pushgateway'
honor_labels: true
static_configs:
- targets: ['localhost:9091']
注意:honor_labels: true 是为了让 Prometheus 尊重 Pushgateway 提供的标签。
重启prometheus :
systemctl restart prometheus
1.手动自定义推送:
echo "some_metric 3.14" | curl --data-binary @- http://103.104.xxx.xxx:9091/metrics/job/some_job
2.explorter推送:
#!/bin/bash
# 配置参数
MYSQLD_EXPORTER_URL="http://103.104.xxx.xxx:9104/metrics" # mysqld_exporter 的指标地址
PUSHGATEWAY_URL="http://103.104.xxx.xxx:9091/metrics/job/mysql_metrics" # Pushgateway 地址
# 获取 mysqld_exporter 的指标
METRICS=$(curl -s $MYSQLD_EXPORTER_URL)
# 将指标推送到 Pushgateway
echo "$METRICS" | curl --data-binary @- $PUSHGATEWAY_URL
pushgatteway地址:http://103.104.xxx.xxx:9091/#