文章目录
找一个Short-lived Jobs的示例,配置其向Pushgateway推送监控指标?
1)安装pushgateway
#docker pull prom/pushgateway
#docker run -d -p 9091:9091 prom/pushgateway
#访问http://172.17.0.41:9091
2) 在prometheus配置文件中添加pushgateway
...
- job_name: pushgateway
static_configs:
- targets: ['172.17.0.41:9091']
labels:
instance: pushgateway
...
3)API的方式Push数据到pushgateway
Push 数据到 PushGateway 中,可以通过其提供的 API 标准接口来添加,默认 URL 地址为:http://<ip>:9091/metrics/job/<JOBNAME>{/<LABEL_NAME>/<LABEL_VALUE>},
其中 是必填项,为 job 标签值,后边可以跟任意数量的标签对,一般我们会添加一个 instance/<INSTANCE_NAME> 实例名称标签,来方便区分各个指标。
接下来,可以 Push 一个简单的指标数据到 PushGateway 中测试一下。
#向 {job="some_job"} 添加单条数据:
#echo "some_metric 3.14" | curl --data-binary @- http://172.17.0.41:9091/metrics/job/some_job
#添加更多更复杂数据,通常数据会带上 instance, 表示来源位置:
cat <<EOF | curl --data-binary @- http://172.17.0.41:9091/metrics/job/some_job/instance/some_instance
# TYPE some_metric counter
some_metric{label="val1"} 42
# TYPE another_metric gauge
# HELP another_metric Just an example.
another_metric 2398.283
EOF
cat <<EOF | curl --data-binary @- http://172.17.0.41:9091/metrics/job/some_job/instance/some_instance
some_metric{label="val1"} 42
another_metric 2398.283
EOF
#删除某个组下的某实例的所有数据:
curl -X DELETE http:/172.17.0.41:9091/metrics/job/some_job/instance/some_instance
#删除某个组下的所有数据:
curl -X DELETE http://172.17.0.41:9091/metrics/job/some_job