|
|
@@ -1,8 +1,12 @@
|
|
|
#if !defined(TURN_NO_PROMETHEUS)
|
|
|
|
|
|
+#include "mainrelay.h"
|
|
|
#include "prom_server.h"
|
|
|
|
|
|
int start_prometheus_server(void){
|
|
|
+ if (turn_params.prometheus == 0){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
prom_collector_registry_default_init();
|
|
|
// Create status gauge metric
|
|
|
turn_status = prom_collector_registry_must_register_metric(prom_gauge_new("turn_status", "Represents status", 5, (const char *[]) {"realm", "user", "allocation", "status", "lifetime" }));
|
|
|
@@ -42,54 +46,61 @@ int start_prometheus_server(void){
|
|
|
}
|
|
|
|
|
|
void prom_set_status(const char* realm, const char* user, unsigned long long allocation, const char* status, unsigned long lifetime){
|
|
|
- char allocation_chars[1024];
|
|
|
- char lifetime_chars[1024];
|
|
|
-
|
|
|
- snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
- snprintf(lifetime_chars, sizeof(lifetime_chars), "%lu", lifetime);
|
|
|
-
|
|
|
- prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, lifetime_chars });
|
|
|
+ if (turn_params.prometheus == 1){
|
|
|
+ char allocation_chars[1024];
|
|
|
+ char lifetime_chars[1024];
|
|
|
+
|
|
|
+ snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
+ snprintf(lifetime_chars, sizeof(lifetime_chars), "%lu", lifetime);
|
|
|
+
|
|
|
+ prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, lifetime_chars });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void prom_del_status(const char* realm, const char* user, unsigned long long allocation, const char* status){
|
|
|
- char allocation_chars[1024];
|
|
|
- snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
-
|
|
|
- prom_gauge_sub(turn_status, 1, (const char *[]) { realm , user, allocation_chars, (char *)"new", (char *)"600" });
|
|
|
- prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, NULL });
|
|
|
+ if (turn_params.prometheus == 0){
|
|
|
+ char allocation_chars[1024];
|
|
|
+ snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
|
|
|
+ prom_gauge_sub(turn_status, 1, (const char *[]) { realm , user, allocation_chars, (char *)"new", (char *)"600" });
|
|
|
+ prom_gauge_add(turn_status, 1, (const char *[]) { realm , user, allocation_chars, status, NULL });
|
|
|
+ }
|
|
|
}
|
|
|
void prom_set_traffic(const char* realm, const char* user, unsigned long long allocation, unsigned long rsvp, unsigned long rsvb, unsigned long sentp, unsigned long sentb, bool peer){
|
|
|
- char allocation_chars[1024];
|
|
|
- snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
-
|
|
|
- if (peer){
|
|
|
- prom_gauge_set(turn_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- } else {
|
|
|
- prom_gauge_set(turn_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ if (turn_params.prometheus == 1){
|
|
|
+ char allocation_chars[1024];
|
|
|
+ snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
+
|
|
|
+ if (peer){
|
|
|
+ prom_gauge_set(turn_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ } else {
|
|
|
+ prom_gauge_set(turn_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void prom_set_total_traffic(const char* realm, const char* user, unsigned long long allocation, unsigned long rsvp, unsigned long rsvb, unsigned long sentp, unsigned long sentb, bool peer){
|
|
|
- char allocation_chars[1024];
|
|
|
- snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
-
|
|
|
- if (peer){
|
|
|
- prom_gauge_set(turn_total_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- } else {
|
|
|
- prom_gauge_set(turn_total_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
- prom_gauge_set(turn_total_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ if (turn_params.prometheus == 1){
|
|
|
+ char allocation_chars[1024];
|
|
|
+ snprintf(allocation_chars, sizeof(allocation_chars), "%018llu", allocation);
|
|
|
+
|
|
|
+ if (peer){
|
|
|
+ prom_gauge_set(turn_total_traffic_peer_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_peer_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_peer_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_peer_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ } else {
|
|
|
+ prom_gauge_set(turn_total_traffic_rcvp, rsvp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_rcvb, rsvb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_sentp, sentp, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ prom_gauge_set(turn_total_traffic_sentb, sentb, (const char *[]) { realm , user, allocation_chars });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|