Reset Prometheus counter once
Hello. Are there any ways to reset the Prometheus counter once? I can do something like this, but counter will be reset on each request loadmodule "xhttp_prom.so"
modparam("xhttp_prom", "prom_counter", "name=mycounter;") route { prom_counter_reset("mycounter"); }
Otherwise, I will not receive the counter until a special and rare event occurs. Regards, Marat
Hello Marat, modparam only declares a counter because it only defines label names. When a counter is added or reset then label values are set so the counter is actually created. If you want a counter to be reset once, you could use a trick. May be setting a shared variable, change that variable first time used and execute prom_counter_reset inside an if to check the value of that variable. Sure other kamailio users could tell you other ways to initialize something once. Regards, Vicente. On 7/15/20 11:06 AM, Marat Gareev wrote:
Hello.
Are there any ways to reset the Prometheus counter once? I can do something like this, but counter will be reset on each request
loadmodule "xhttp_prom.so" modparam("xhttp_prom", "prom_counter", "name=mycounter;") route { prom_counter_reset("mycounter"); }
Otherwise, I will not receive the counter until a special and rare event occurs.
Regards, Marat
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Hello, you can e.g. use a timer route to periodically reset this. Or just filter for a special custom SIP request method that you send to your server. Cheers, Henning -- Henning Westerholt – https://skalatan.de/blog/ Kamailio services – https://gilawa.com<https://gilawa.com/> From: sr-users <sr-users-bounces@lists.kamailio.org> On Behalf Of Marat Gareev Sent: Wednesday, July 15, 2020 11:07 AM To: Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org> Subject: [SR-Users] Reset Prometheus counter once Hello. Are there any ways to reset the Prometheus counter once? I can do something like this, but counter will be reset on each request loadmodule "xhttp_prom.so" modparam("xhttp_prom", "prom_counter", "name=mycounter;") route { prom_counter_reset("mycounter"); } Otherwise, I will not receive the counter until a special and rare event occurs. Regards, Marat
Hello Marat, (my previous email did not pass moderation filter) modparam only declares a counter because it only defines label names. When a counter is added or reset then label values are set so the counter is actually created. If you want a counter to be reset once, you could use a trick. May be setting a shared variable, change that variable first time used and execute prom_counter_reset inside an if to check the value of that variable. Regards, Vicente. On 7/15/20 11:06 AM, Marat Gareev wrote:
Hello.
Are there any ways to reset the Prometheus counter once? I can do something like this, but counter will be reset on each request
loadmodule "xhttp_prom.so" modparam("xhttp_prom", "prom_counter", "name=mycounter;") route { prom_counter_reset("mycounter"); }
Otherwise, I will not receive the counter until a special and rare event occurs.
Regards, Marat
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Hi, guys, many thanks for your interesting solutions. I have implemented Vicente's suggestion, it works as expected. loadmodule "xhttp_prom.so"
modparam("xhttp_prom", "prom_counter", "name=mycounter;") modparam("pv", "shvset", "is_prometheus_init=i:0") route { if ($shv(is_prometheus_init) == 0) { xlog("L_NOTICE", "Initialization of Prometheus counters\n"); prom_counter_reset("mycounter"); $shv(is_prometheus_init) = 1; } }
Regards, Marat
participants (3)
-
Henning Westerholt -
Marat Gareev -
Vicente Hernando