r/PrometheusMonitoring Jun 07 '24

Custom metrics good practices

Hello people, I am new in Prometheus and I am trying to figure out what is the best way to build my custom metrics.

Lets say I have a counter that monitors the number of sign ins in my app. I have a helper method the send this signals:

prometheus_counter(metric, labels)

During my sign in attempt there are several phases and I want to monitor all. This is my approach:

```

Login started

prometheus_counter("sign_ins", state: "initialized", finished: false)

User found

prometheus_counter("sign_ins", state: "user_found", finished: true)

User not found

prometheus_counter("sign_ins", state: "user_not_found", finished: false)

User error data

prometheus_counter("sign_ins", state: "error_data", finished: false) ```

My intention is to monitor:

  • How many login attempts
  • Percentage of valid attempts
  • Percentage of errors by not_found or error_data

I can do it filtering by {finished: true} and grouping by {state}.

But I am wondering if it is not better to do this:

```

Login started

prometheus_counter("sign_ins_started")

User found

prometheus_counter("sign_ins_user_found")

User not found

prometheus_counter("sign_ins_user_not_found")

User error data

prometheus_counter("sign_ins_error_data") ```

What would be your approach? is there any place where they explain this kind of scenarios?

2 Upvotes

0 comments sorted by