Instrumenting applications and alerting with Prometheus
Simon Pasquier / Senior Software Engineer @ Red Hat
@SimonHiker
Who am I?
“Prometheus is a systems and service monitoring system”
source: https://github.com/prometheus/prometheus/blob/master/README.md
Server
Application
Application
# HELP http_requests_total Total number of HTTP requests.
# TYPE http_requests_total gauge
http_requests_total{code=”200”,method=”GET”} 10
http_requests_total{code=”500”,method=”GET”} 0
...
HTTP
Timeseries data model
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”}
Timeseries data model
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”}
name
Timeseries data model
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”}
labels
Timeseries data model
timeseries
samples
| t |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 |
Timeseries data model
| t | t+1m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 |
Timeseries data model
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
http_requests_total{code=”400”}
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
http_requests_total{code=”400”}
http_requests_total{code=”500”}[5m]
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
http_requests_total{code=”400”}
http_requests_total{code=”500”}[5m]
rate(http_requests_total{code=”500”}[5m])
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
http_requests_total{code=”400”}
http_requests_total{code=”500”}[5m]
rate(http_requests_total{code=”500”}[5m]) =~ 0.0267 req/sec
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Querying
http_requests_total
http_requests_total{code=”400”}
http_requests_total{code=”500”}[5m]
rate(http_requests_total{code=”500”}[5m])
sum(rate(http_requests_total{code=~”5..”}[5m])) / sum(rate(http_requests_total[5m])) > 0.05
| t | t+1m | t+2m | t+3m | t+4m |
http_requests_total{code=”200”,method=”GET”,job=”app”,instance=”foo:8080”} | 10 | 20 | 40 | 50 | 58 |
http_requests_total{code=”400”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 0 | 0 | 1 | 2 |
http_requests_total{code=”500”,method=”GET”,job=”app”,instance=”foo:8080”} | 0 | 2 | 2 | 5 | 8 |
Prometheus in a nutshell
Prometheus in a nutshell
Prometheus in a nutshell
Prometheus in a nutshell
Why instrument?
Why instrument?
Why instrument?
Why choose Prometheus?
Why choose Prometheus?
Why choose Prometheus?
Example of code instrumentation
Server
Hello app
Alertmanager
Alerts
Instrumentation methods
Instrumentation methods
Instrumentation methods
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Good practices of instrumentation
Alerting
Alerting
Alerting
Alerting
Conclusion
Conclusion
Conclusion
We’re hiring!