1. cd /opt
    2. wget https://github.com/prometheus/pushgateway/releases/download/v1.4.0/pushgateway-1.4.0.linux-amd64.tar.gz
    3. tar xvf pushgateway-1.4.0.linux-amd64.tar.gz
    4. ln -s pushgateway-1.4.0.linux-amd64 pushgateway

    服务脚本

    cat > /usr/lib/systemd/system/pushgateway.service <<EOF
    [Unit]
    Description=pushgateway
    Documentation=
    After=network.target
    
    [Service]
    Type=simple
    WorkingDirectory=/opt/pushgateway
    ExecStart=/opt/pushgateway/pushgateway --web.listen-address=:9091 --web.telemetry-path=/metrics --persistence.interval=5m --persistence.file=persistence-data
    ExecStop=/bin/kill -KILL \$MAINPID
    ExecReload=/bin/kill -HUP \$MAINPID
    KillMode=control-group
    Restart=on-failure
    RestartSec=3s
    
    [Install]
    WantedBy=multi-user.target
    EOF
    

    启动

    systemctl enable pushgateway
    systemctl start pushgateway
    systemctl status pushgateway
    

    prometheus.yml scrape_configs下面增加pushgateway配置,基于文件的自动发现

    scrape_configs:
    ...
      - job_name: 'pushgateway'
        honor_labels: true
        file_sd_configs:
          - files:
            - targets/pushgateway/*.json
            refresh_interval: 5m
    
    mkdir -p /opt/prometheus/targets/pushgateway
    
    #配置pushgateway的地址
    vim /opt/prometheus/targets/pushgateway/hosts.json
    [{
      "targets": ["192.168.50.189:9091"]
    }]