Prometheus pushgateway学习
- 
- [1. Pushgateway 介绍](#1. Pushgateway 介绍)
 - [2. prometheus和pushgateway安装](#2. prometheus和pushgateway安装)
 - [3. 创建自定义监控指标](#3. 创建自定义监控指标)
 
 
1. Pushgateway 介绍
Pushgateway是Prometheus 提供的一个自定义监控指标的工具,主要是创建自定义监控指标然后推送给pushgateway,Prometheus从pushgateway中获取数据
2. prometheus和pushgateway安装
通过docker安装
 docker pull prom/pushgateway
 docker pull prom/prometheus
        创建配置文件:
prometheus.yml:
            
            
              clike
              
              
            
          
          global:
alerting:
  alertmanagers:
    - static_configs:
        - targets:
rule_files:
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
        labels:
          app: "prometheus"
  # pushgateway配置
  - job_name: "pushgateway"
    honor_labels: true
    static_configs:
    - targets:
      - 192.168.25.250:9091
        honor_labels: true:当配置中的指标与抓取目标中的指标冲突优先使用目标指标
启动prometheus:
docker run -d --name prometheus --net host  -v ./prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus
        启动pushgateway :
docker run -d --name pushgateway --net host  prom/pushgateway
        访问prometheus和pushgateway web ui:


3. 创建自定义监控指标
指标值必须是数值型
推送格式:
curl --data-binary @- "http://IP:9091/metrics/job/${JOB_NAME}/instance/${INSTANCE_NAME}"
echo "docker_live_info{status=\"running\"} $(ps -ef | grep -v grep | grep docker | wc -l)" | curl --data-binary @- "http://192.168.25.250:9091/metrics/job/test/instance/192.168.25.250"
        指标格式:指标名{key} value
查看指标:

通过Prometheus抓取数据:

可以通过定时执行指标推送命令来更新指标的数据。
推送到pushgateway的指标的数据,如果没有持续更新会一直保持上次的值,并且只能手动删除指标。
