@cryptotaxi247 / netdata-1 / commits / 46b191c4f

last access time for prometheus hosts is now per netdata host used

Costa Tsaousis (ktsaou) committed Mar 12, 2018 at 11:46 UTC 46b191c4fecf3abfffe13860630569a93ba78a81
1 file changed +13 -4
src/backend_prometheus.c
+13 -4
@@ -2,23 +2,29 @@
2
3 // ----------------------------------------------------------------------------
4 // PROMETHEUS
5 -// /api/v1/allmetrics?format=prometheus
5 +// /api/v1/allmetrics?format=prometheus and /api/v1/allmetrics?format=prometheus_all_hosts
6
7 static struct prometheus_server {
8 const char *server;
9 uint32_t hash;
10 + RRDHOST *host;
11 time_t last_access;
12 struct prometheus_server *next;
13 } *prometheus_server_root = NULL;
14
14 -static inline time_t prometheus_server_last_access(const char *server, time_t now) {
15 +static netdata_mutex_t prometheus_server_root_mutex = NETDATA_MUTEX_INITIALIZER;
16 +
17 +static inline time_t prometheus_server_last_access(const char *server, RRDHOST *host, time_t now) {
18 uint32_t hash = simple_hash(server);
19
20 + netdata_mutex_lock(&prometheus_server_root_mutex);
21 +
22 struct prometheus_server *ps;
23 for(ps = prometheus_server_root; ps ;ps = ps->next) {
19 - if (hash == ps->hash && !strcmp(server, ps->server)) {
24 + if (host == ps->host && hash == ps->hash && !strcmp(server, ps->server)) {
25 time_t last = ps->last_access;
26 ps->last_access = now;
27 + netdata_mutex_unlock(&prometheus_server_root_mutex);
28 return last;
29 }
30 }
@@ -26,10 +32,12 @@ static inline time_t prometheus_server_last_access(const char *server, time_t no
32 ps = callocz(1, sizeof(struct prometheus_server));
33 ps->server = strdupz(server);
34 ps->hash = hash;
35 + ps->host = host;
36 ps->last_access = now;
37 ps->next = prometheus_server_root;
38 prometheus_server_root = ps;
39
40 + netdata_mutex_unlock(&prometheus_server_root_mutex);
41 return 0;
42 }
43
@@ -111,6 +119,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
119 char labels[PROMETHEUS_LABELS_MAX + 1] = "";
120 if(allhosts) {
121 buffer_sprintf(wb, "netdata_info{instance=\"%s\",application=\"%s\",version=\"%s\"}\n", hostname, host->program_name, host->program_version);
122 +
123 if(host->tags && *(host->tags))
124 buffer_sprintf(wb, "netdata_host_tags{instance=\"%s\",%s} 1 %llu\n", hostname, host->tags, now_realtime_usec() / USEC_PER_MS);
125
@@ -371,7 +380,7 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
380 static inline time_t prometheus_preparation(RRDHOST *host, BUFFER *wb, uint32_t options, const char *server, time_t now, int help) {
381 if(!server || !*server) server = "default";
382
374 - time_t after = prometheus_server_last_access(server, now);
383 + time_t after = prometheus_server_last_access(server, host, now);
384
385 int first_seen = 0;
386 if(!after) {