admin管理员组

文章数量:1200972

Need only the top first element of the prometheus metrics.

i did topk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) but it is not only showing the displayName=7 record, but also other 6 records as well.

I need only and only this metric.

deploy_time_total{accountName="deploy-dev",displayName="7",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4X5A5MVRS28HXTZ2PYCQ7W",status="SUCCEEDED"} 1.737479079809E12 1737543094457

but bottomk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) is showing only the displayName=1 record.

Here is my grafana output. I need only and only the pink line in the grafana page(which is nothing but the displayName=7 record.

grafana screenshot.

i did topk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) but it is not only showing the displayName=7 record but also the other records.(screenshot attached)

but bottomk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) is showing only the displayName=1 record.

here is the display Name flow -- 1-> 2 -> 3-> 4 -> 5-> 6 ->7

topk(1,metric) should give me only 7
bottomk(1,metric) should give me only 1(which is showing)

see the above grafana screenshot.

deploy_time_total{accountName="deploy-dev",displayName="3",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WDDHP2R8G1DXAVVF4908E",status="SUCCEEDED"} 1.737478296332E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="5",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WV13BHBEE5HN11DKRH5P8",status="SUCCEEDED"} 1.737478742459E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="4",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WJMB9R7B4G627D4WW3YG4",status="SUCCEEDED"} 1.737478467509E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="6",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WZWBA1F3HSBDWR05TDAPX",status="SUCCEEDED"} 1.737478901437E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="2",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4W65J43T4DNTYRR41YY65R",status="SUCCEEDED"} 1.737478058649E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="7",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4X5A5MVRS28HXTZ2PYCQ7W",status="SUCCEEDED"} 1.737479079809E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="1",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4W3D4729SG71QE2QW9KYFT",status="SUCCEEDED"} 1.737477990148E12 1737543094457

Need only the top first element of the prometheus metrics.

i did topk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) but it is not only showing the displayName=7 record, but also other 6 records as well.

I need only and only this metric.

deploy_time_total{accountName="deploy-dev",displayName="7",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4X5A5MVRS28HXTZ2PYCQ7W",status="SUCCEEDED"} 1.737479079809E12 1737543094457

but bottomk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) is showing only the displayName=1 record.

Here is my grafana output. I need only and only the pink line in the grafana page(which is nothing but the displayName=7 record.

grafana screenshot.

i did topk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) but it is not only showing the displayName=7 record but also the other records.(screenshot attached)

but bottomk(1,deploy_time_total{status="SUCCEEDED"}) by (imageName) is showing only the displayName=1 record.

here is the display Name flow -- 1-> 2 -> 3-> 4 -> 5-> 6 ->7

topk(1,metric) should give me only 7
bottomk(1,metric) should give me only 1(which is showing)

see the above grafana screenshot.

deploy_time_total{accountName="deploy-dev",displayName="3",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WDDHP2R8G1DXAVVF4908E",status="SUCCEEDED"} 1.737478296332E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="5",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WV13BHBEE5HN11DKRH5P8",status="SUCCEEDED"} 1.737478742459E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="4",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WJMB9R7B4G627D4WW3YG4",status="SUCCEEDED"} 1.737478467509E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="6",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4WZWBA1F3HSBDWR05TDAPX",status="SUCCEEDED"} 1.737478901437E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="2",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4W65J43T4DNTYRR41YY65R",status="SUCCEEDED"} 1.737478058649E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="7",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4X5A5MVRS28HXTZ2PYCQ7W",status="SUCCEEDED"} 1.737479079809E12 1737543094457
deploy_time_total{accountName="deploy-dev",displayName="1",imageName="opsmx11/nginx-demo:1853",namespace="demo-dev",pipelineId="01JJ4W3D4729SG71QE2QW9KYFT",status="SUCCEEDED"} 1.737477990148E12 1737543094457
Share Improve this question asked Jan 22 at 14:09 SanjeevSanjeev 1 1
  • If you want to have a single line on ranged graph, you might try some clever queries with use of @end(). It is finicky though. If you'll go that route take a look at last_over_time also. – markalex Commented Jan 26 at 9:09
Add a comment  | 

1 Answer 1

Reset to default 0

your screenshot shows result of a query on a graph which demonstrates data points in a selected time range. that is completely normal since pink started somewhere and before that another metric had the highest value.

instead of a range query, you can use instant query to always get last top 1 in your metric.

本文标签: grafanaNeed only the top first element of the prometheus metricsStack Overflow