【Prometheus & Pushgateway】 推送数据踩坑

度量指标值 只允许 数字类型

报错text format parsing error in line 1: expected float as value, got “1.1.1.1”

原因:
为了可以更好地画图,所以只允许返回 数字类型 指标值

$ echo ipaddr 1.1.1.1 curl --data-binary @- -g http://ip:9090/metrics/job/pushgateway/instance/test

ipaddr 值为 1.1.1.1 是会报错
text format parsing error in line 1: expected float as value, got "1.1.1.1"

解决方法:
将1.1.1.1 转为数字

function checkIP()
{
    ip=$1
    if [ $ip != "${1#*[0-9].[0-9]}" ]; then
        # IPv4
        a=`echo $ip | awk -F'.' '{print $1}'`
        b=`echo $ip | awk -F'.' '{print $2}'`
        c=`echo $ip | awk -F'.' '{print $3}'`
        d=`echo $ip | awk -F'.' '{print $4}'`
    
        echo "$(((a<<24)+(b<<16)+(c<<8)+d))"
    elif [ "$ip" != "${1#*:[0-9a-fA-F]}" ]; then
        # IPv6
        echo $ip
    else
        echo 0
    fi
}

参考链接: https://github.com/prometheus/prometheus/issues/2227

度量指标值为 只能接受最长16位,16位之后数字转为 0

“FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF”:340282366920938463463374607431768211455

$ echo ipaddr 340282366920938463463374607431768211455 \ 
curl --data-binary @- -g http://ip:9090/metrics/job/pushgateway/instance/test

实际结果:
ipaddr{instance="test"}  340282366920938500000000000000000000000

pushgateway 数据持久化

为了防止 pushgateway 重启或意外挂掉,导致数据丢失,我们可以通过 -persistence.file-persistence.interval 参数将数据持久化下来。


prometheus 官网解释

度量标签和标签命名

度量标准名称和标签数据模型

exceeded maximum resolution of 11,000 points per timeseries. Try decreasing the query resolution

当执行 该操作时:
GET http://xxx/prometheus/api/v1/query_range?query=bps{mac=~‘xx:xx:xx:xx:xx:xx’}&start=2019-09-19T09:29:26Z&end=2019-09-20T09:29:26Z&step=15s&timeout=60s

原因:prometheus 为每个查询设置了11k数据点的硬限制。
参考链接:
https://github.com/prometheus/prometheus/issues/1968
https://github.com/prometheus/prometheus/issues/2253

docker-compose restart 不会生效新改的docker-compose.yml

必须 docker-compose down

然后 docker-compose up 

开启热更新

从 2.0 开始,hot reload 功能是默认关闭的,
如需开启,需要在启动 Prometheus 的时候,添加 --web.enable-lifecycle 参数

热更新加载方法有两种:
kill -HUP pid
curl -X POST http://IP/-/reload  【推荐】

Blackbox_exporter 提示报错:Timeout reading from socket

解决方法:
重启 blackbox 容器

Pushgateway Delete Group 报错:Deleting metric group failed: Bad Request

如果 key="", 会报错Deleting metric group failed: Bad Request
解决:
对每个KEY 设置默认值,保证每一个 key 都有值

PushGateway 推送及 Prometheus 拉取时间设置

Prometheus 每次从 PushGateway 拉取的数据,并不是拉取周期内用户推送上来的所有数据,而是最后一次 Push 到 PushGateway 上的数据,
所以推荐设置推送时间小于或等于 Prometheus 拉取的时间,这样保证每次拉取的数据是最新 Push 上来的。

猜你喜欢

转载自blog.csdn.net/qq_22227087/article/details/100698791
今日推荐