request help: prometheus plugin loses data when APISIX restarts
Issue description
I use the prometheus plugin to collect statistics of apifix . But when I restart APISX, apisix_http_status is cleared.
For example, I:
- Use routing A 2 times
- Restart APISIX
- Use routing A 5 times
I hope to see apisix_http_status{route_name="A"} 7 in prometheus, but it will be 5.
Can anyone help ?
Environment
Request help without environment information will be ignored or closed.
- apisix version (cmd:
apisix version): 2.4 - OpenResty / Nginx version (cmd:
nginx -Voropenresty -V): openresty/1.19.3.1 - etcd version, if have (cmd: run
curl http://127.0.0.1:9090/v1/server_infoto get the info from server-info API): 3.4.0
@liuxiran @Xu-Mj : - )
@Fuchange APISIX puts all the metrics data in shared memory, while restart operation will fork another new master and the new master, in turn, forking a bunch of workers, they use a new shared memory block, so metrics data are not inherited from the old shared memory.
@Fuchange APISIX puts all the metrics data in shared memory, while restart operation will fork another new master and the new master, in turn, forking a bunch of workers, they use a new shared memory block, so metrics data are not inherited from the old shared memory.
Thanks for your answer. I understand why it happened.
Do we have a recommended solution ? A counter that always reset do not make much sense for information statistics .
You don't need to "solve" it. It should be handled by Prometheus. Please read https://www.robustperception.io/how-does-a-prometheus-counter-work, which starts from "A common question is what happens when the process restarts and the counter is reset to 0".
You don't need to "solve" it. It should be handled by Prometheus. Please read https://www.robustperception.io/how-does-a-prometheus-counter-work, which starts from "A common question is what happens when the process restarts and the counter is reset to 0".
@spacewander Thanks for your answer.
They said "What you really want to know is how fast it's counting" . But what we need is not how fast but how much .
Using rate() to get how much is difficult to get an integer (because " rate() also has logic to handle samples not quite covering the entire time range you pass to rate() ")
By the way , they said "This makes it important that it not be possible for Counters to be decremented , a Counter that has the potential to be decremented is in reality a Gauge"
Using rate() to get how much is difficult to get an integer (because " rate() also has logic to handle samples not quite covering the entire time range you pass to rate() ")
It's recommended to use rate() which solves some edge cases. Calculate the time range manually may be wrong in some situations, for example, your sample time and query time may be mismatched.
It's recommended to use
rate()which solves some edge cases. Calculate the time range manually may be wrong in some situations, for example, your sample time and query time may be mismatched.
@spacewander So is "apisix_http_status" a counter that can only provide "how fast" but not "how much" because of it possible reduced ?
The rate() should handle it. And this is a Prometheus issue, which is better to be discussed in the Prometheus community.