disable prometheus TYPE line by default; added options help=yes|no, types=yes|no to enable and disable prometheus HELP and TYPE lines; fixes #2076; fixes #2079
Costa Tsaousis (ktsaou) committed
Apr 13, 2017 at 01:20 UTC
52d33c24ee3b5305cc65febb2c08e8221ad14c97
3 files changed
+29
-17
src/rrd2json.c
+12
-13
@@ -186,7 +186,7 @@ static inline size_t prometheus_name_copy(char *d, const char *s, size_t usable)
186
187
#define PROMETHEUS_ELEMENT_MAX 256
188
189
-void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb) {
189
+void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb, int help, int types) {
190
rrdhost_rdlock(host);
191
192
char hostname[PROMETHEUS_ELEMENT_MAX + 1];
@@ -209,18 +209,17 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb) {
209
char dimension[PROMETHEUS_ELEMENT_MAX + 1];
210
prometheus_name_copy(dimension, rd->id, PROMETHEUS_ELEMENT_MAX);
211
212
- // buffer_sprintf(wb, "# HELP %s.%s %s\n", st->id, rd->id, st->units);
212
+ const char *t = "gauge", *h = "gives";
213
+ if(rd->algorithm == RRD_ALGORITHM_INCREMENTAL || rd->algorithm == RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL) {
214
+ t = "counter";
215
+ h = "delta gives";
216
+ }
217
214
- switch(rd->algorithm) {
215
- case RRD_ALGORITHM_INCREMENTAL:
216
- case RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL:
217
- buffer_sprintf(wb, "# TYPE %s_%s counter\n", chart, dimension);
218
- break;
218
+ if(unlikely(help))
219
+ buffer_sprintf(wb, "# HELP netdata chart %s, dimension %s, value * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT " %s %s (%s)\n", st->id, rd->id, rd->multiplier, rd->divisor, h, st->units, t);
220
220
- default:
221
- buffer_sprintf(wb, "# TYPE %s_%s gauge\n", chart, dimension);
222
- break;
223
- }
221
+ if(unlikely(types))
222
+ buffer_sprintf(wb, "# TYPE %s_%s %s\n", chart, dimension, t);
223
224
// calculated_number n = (calculated_number)rd->last_collected_value * (calculated_number)(abs(rd->multiplier)) / (calculated_number)(abs(rd->divisor));
225
// buffer_sprintf(wb, "%s.%s " CALCULATED_NUMBER_FORMAT " %llu\n", st->id, rd->id, n, timeval_msec(&rd->last_collected_time));
@@ -239,11 +238,11 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb) {
238
rrdhost_unlock(host);
239
}
240
242
-void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(BUFFER *wb) {
241
+void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(BUFFER *wb, int help, int types) {
242
RRDHOST *host;
243
rrd_rdlock();
244
rrdhost_foreach_read(host) {
246
- rrd_stats_api_v1_charts_allmetrics_prometheus(host, wb);
245
+ rrd_stats_api_v1_charts_allmetrics_prometheus(host, wb, help, types);
246
}
247
rrd_unlock();
248
}
src/rrd2json.h
+2
-2
@@ -67,8 +67,8 @@ extern void rrd_stats_api_v1_charts(RRDHOST *host, BUFFER *wb);
67
68
extern void rrd_stats_api_v1_charts_allmetrics_json(RRDHOST *host, BUFFER *wb);
69
extern void rrd_stats_api_v1_charts_allmetrics_shell(RRDHOST *host, BUFFER *wb);
70
-extern void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb);
71
-extern void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(BUFFER *wb);
70
+extern void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb, int help, int types);
71
+extern void rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(BUFFER *wb, int help, int types);
72
73
extern int rrdset2anything_api_v1(RRDSET *st, BUFFER *out, BUFFER *dimensions, uint32_t format, long points
74
, long long after, long long before, int group_method, uint32_t options
src/web_api_v1.c
+15
-2
@@ -208,6 +208,7 @@ inline int web_client_api_request_v1_charts(RRDHOST *host, struct web_client *w,
208
209
inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client *w, char *url) {
210
int format = ALLMETRICS_SHELL;
211
+ int help = 0, types = 0; // prometheus options
212
213
while(url) {
214
char *value = mystrsep(&url, "?&");
@@ -229,6 +230,18 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
230
else
231
format = 0;
232
}
233
+ else if(!strcmp(name, "help")) {
234
+ if(!strcmp(value, "yes"))
235
+ help = 1;
236
+ else
237
+ help = 0;
238
+ }
239
+ else if(!strcmp(name, "types")) {
240
+ if(!strcmp(value, "yes"))
241
+ types = 1;
242
+ else
243
+ types = 0;
244
+ }
245
}
246
247
buffer_flush(w->response.data);
@@ -247,12 +260,12 @@ inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client
260
261
case ALLMETRICS_PROMETHEUS:
262
w->response.data->contenttype = CT_PROMETHEUS;
250
- rrd_stats_api_v1_charts_allmetrics_prometheus(host, w->response.data);
263
+ rrd_stats_api_v1_charts_allmetrics_prometheus(host, w->response.data, help, types);
264
return 200;
265
266
case ALLMETRICS_PROMETHEUS_ALL_HOSTS:
267
w->response.data->contenttype = CT_PROMETHEUS;
255
- rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(w->response.data);
268
+ rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(w->response.data, help, types);
269
return 200;
270
271
default: