0.pushgateway的安装和配置
tar -zxf pushgateway-1.2.0.linux-amd64.tar.gz
./pushgateway &
在Prometheus添加配置
- job_name: 'node_111' static_configs: - targets: ['10.0.0.111:9100']labels:instance: 111_9100- targets: ['10.0.0.134:9100']labels:instance: 134_9100 - job_name: 'pushgateway_test' #这个名称可以自定义,后面会用到 static_configs: - targets: ['10.0.0.111:9091'] #这里是pushgateway的地址
1.pushgateway发送数据的API格式
http://pustgatewayIP/metrices/job/job名/标签名/标签值 echo "metricname 120" | curl --data-binary @- http://10.0.0.111:9091/metrics/job/myjobname/labels/mylabelname
2.数据类型
1、counter类型 #counter是可增长的,重启时候会被置成0,用于任务个数,只增不减 cat <<EOF | curl --data-binary @- http://pushgatewayIP:9091/metrics/job/docker_runtime/instance/xa-lsr-billubuntu # TYPE docker_runtime counter docker_runtime{name="cadvisor"} 33 docker_runtime{name="nginx"} 331 docker_runtime{name="abc"} 332 EOF 2.发送gauage类型 "Random value of the request" cat <<EOF | curl --data-binary @- http://pushgatewayIP:9091/metrics/job/docker_runtime/instance/xa-lsr-billubuntu # TYPE docker_runtime gauge # HELP docker_runtime time sec docker_runtime{name="nginx"} 22 docker_runtime{name="cadvisor"} 22 docker_runtime{name="bbc"} 22 EOF
参考:https://www.cnblogs.com/zqj-blog/archive/2004/01/13/11024834.html https://www.cnblogs.com/zqj-blog/p/11106724.html
3.promql简单例子
cat <<EOF | curl --data-binary @- http://pushgatewayIP:9091/metrics/job/docker_runtime/instance/xa-lsr-billubuntu
# TYPE docker_runtime counter
docker_runtime{name="abc"} 332
EOF
rate(docker_runtime{name='abc'}[1m])