# How to calculate the time a service has been up using promql?

**URL:** <https://discuss.prometheus.io/t/how-to-calculate-the-time-a-service-has-been-up-using-promql/2379>\
**Category:** PromQL\
**Created:** [August 20, 2024, 9:45am UTC](https://discuss.prometheus.io/t/how-to-calculate-the-time-a-service-has-been-up-using-promql/2379 "2024-08-20T09:45:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![epodegrid](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.prometheus.io/epodegrid/32/1031_2.png) [@epodegrid](https://discuss.prometheus.io/u/epodegrid)\
**Post date:** [August 20, 2024, 9:45am UTC](https://discuss.prometheus.io/t/how-to-calculate-the-time-a-service-has-been-up-using-promql/2379/1 "2024-08-20T09:45:25Z")

</div>

Hello!

I have a service that returns status 1 if the application is up, or status 0 if the application is down. I’m trying to have a graph in grafana that shows the the total time the application is online at a stretch. For example, if the application is running for 3 hours straight, then the grafana visualization should have a “triangle” where the peak is at number 3, and then the line should go down to 0 if the application went down. And then if the application is back up again after 5 hours, then the line should again go up.

So far, I’ve tried using sum\_over\_time, but I that’s just for adding up the values.

How can I the result I’m trying to achieve? Thanks in advance!
