prometheus 表达式

avg_over_time(my_inprogress_requests{job="mhc"}[5m] offset 3m)

返回time=1550664637开始向前偏移3分钟之前的五分钟的平均值

curl -X GET
  'http://mhc-linux:9090/api/v1/query?query=avg_over_time%28my_inprogress_requests{job=%22mhc%22}[5m]%20%20offset%203m%29&time=1550664637'
  -H 'Postman-Token: eeede4b6-e57b-42b1-92e1-d2dec4558f0e'
  -H 'cache-control: no-cache'

{
    "status": "success",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    "instance": "192.168.121.58:8000",
                    "job": "mhc"
                },
                "value": [
                    1550664637,
                    "425.1333333333333"
                ]
            }
        ]
    }
}

curl -X GET
  'http://mhc-linux:9090/api/v1/query_range?query=avg_over_time%28my_inprogress_requests{job=%22mhc%22}[5m]%20%20offset%2010m%29&start=1550664637&end=1550664937&step=60'
  -H 'Postman-Token: b274b534-eede-4d4b-b85c-2f0ad8dbd44e'
  -H 'cache-control: no-cache'

{
    "status": "success",
    "data": {
        "resultType": "matrix",
        "result": [
            {
                "metric": {
                    "instance": "192.168.121.58:8000",
                    "job": "mhc"
                },
                "values": [
                    [
                        1550664637,
                        "474.0666666666666"
                    ],
                    [
                        1550664697,
                        "511.11666666666673"
                    ],
                    [
                        1550664757,
                        "468.6666666666667"
                    ],
                    [
                        1550664817,
                        "464.03333333333313"
                    ],
                    [
                        1550664877,
                        "494.83333333333326"
                    ],
                    [
                        1550664937,
                        "491.38333333333327"
                    ]
                ]
            }
        ]
    }
}

sum(avg_over_time(my_inprogress_requests{user="mhc"}[1m]))

原文地址:https://www.cnblogs.com/mhc-fly/p/10409009.html