我有Django API,我为具有所有参数的每条路线将值1的自定义api_call指标推送到Prometheus PushGateway,因此我的指标如下:
api_call{ip="45.152.122.130",job="post",password="ffff",route="CustomObtainAuthToken",username="newuser1"} 1
api_call{ip="45.152.122.130",job="post",password="ffff",route="CustomObtainAuthToken",username="newuser2"} 1
api_call{ip="45.152.122.130",job="list",pk="me",route="FUserViewSet",token="Token 35c4535f8570dd127531632f9b72affc471e0afe"} 1
api_call{ip="45.152.122.130",job="retrieve",pk="450",route="UserImageViewSet",token="Token 3deb1b01acc27a624e86e9b14f98de64ada1bf8b"} 1
api_call{ip="45.152.122.130",job="create",route="UserImageViewSet",token="Token 3deb1b01acc27a624e86e9b14f98de64ada1bf8b",url="users/dbc39b1b52be4c7b88324469bfc642df",user="https://newfashion.ehedge.xyz/fusers/880/"}
现在,我尝试绘制api_call指标图,以获取每5分钟间隔的API调用总数;如果不考虑括号中的参数而未进行调用,则为0,类似于内部计数器的图形:sum(increase(pushgateway_http_requests_total [5m]) )。我尝试过费率函数-它总是返回0,sum_over_time(api_call [5m])返回不正确的总和。唯一的工作图是sum(api_call),该图不断返回所有API调用的正确数目。我的问题是,对于具有值1和许多不同参数的指标,如何为该图增加5分钟的间隔(如果值不变,则为0)?
答案 0 :(得分:1)
最终使用sum(api_call)-sum(api_call偏移量5m)来绘制每5分钟间隔内所有API调用的计数