Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

Prometheus: How to get SUM of all unique records for a time period? Not a SUM of VALUES

Is it possible to get SUM of all unique records for a time period? Not the SUM of values.

For example, I have these records for a few days

awsec2_api{alias="awsec2metrics", instance_id="i-05a7d9e565ac8b7" reachability="initializing", state="running", systemstatus="initializing", zone="us-east-1c"}16

One instance can have different statuses for 24 hours.

I would like to get SUM of instances for 24 hours like this:

Total istances = 17
Initializing instances = 12
Running = 5
question from:https://stackoverflow.com/questions/66059626/prometheus-how-to-get-sum-of-all-unique-records-for-a-time-period-not-a-sum-of

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have modified metric output and separate into three metrics: instancestate, instancestatus, systemstatus.

For example Instance State:

ec2_inststate{alias="awsec2metrics", application="name", aws_autoscaling_groupName="name", exported_job="monitoring", instance="localhost:9091", instance_id="ide8", instancestate="16", job="pushgateway", role="name" zone="us-east-1"}16

Responce codes

  • 0 : pending
  • 16 : running
  • 32 : shutting-down
  • 48 : terminated
  • 64 : stopping
  • 80 : stopped

This request calculate SUM of instances with code 16 for 1 hour.

(sum by (value) (sum_over_time(ec2_inststate{alias="awsec2metrics",instancestate="16"}[1h])))/16

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...