code cleanup - added check for homogeneous or heterogeneous charts
Costa Tsaousis (ktsaou) committed
Jul 11, 2017 at 23:24 UTC
0894e35ea39b3bee7d109c44f5df9db8a12a3a43
3 files changed
+74
-32
src/backend_prometheus.c
+55
-31
@@ -103,11 +103,11 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
103
rrdset_rdlock(st);
104
105
if(unlikely(help))
106
- buffer_sprintf(wb, "\n# COMMENT chart \"%s\", context \"%s\", family \"%s\", units \"%s\"\n",
107
- (names && st->name) ? st->name : st->id,
108
- st->context,
109
- st->family,
110
- st->units
106
+ buffer_sprintf(wb, "\n# COMMENT chart \"%s\", context \"%s\", family \"%s\", units \"%s\"\n"
107
+ , (names && st->name) ? st->name : st->id
108
+ , st->context
109
+ , st->family
110
+ , st->units
111
);
112
113
// for each dimension
@@ -122,29 +122,46 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
122
prometheus_name_copy(dimension, (names && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX);
123
124
const char *t = "gauge", *h = "gives";
125
- if (rd->algorithm == RRD_ALGORITHM_INCREMENTAL ||
126
- rd->algorithm == RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL) {
125
+ if(rd->algorithm == RRD_ALGORITHM_INCREMENTAL ||
126
+ rd->algorithm == RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL) {
127
t = "counter";
128
h = "delta gives";
129
}
130
131
- if (unlikely(help))
132
- buffer_sprintf(wb, "# COMMENT %s_%s_%s: chart \"%s\", context \"%s\", family \"%s\", dimension \"%s\", value * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT " %s %s (%s)\n",
133
- prefix, context, dimension,
134
- (names && st->name) ? st->name : st->id, st->context,
135
- st->family,
136
- (names && rd->name) ? rd->name : rd->id,
137
- rd->multiplier, rd->divisor,
138
- h, st->units, t
139
- );
131
+ if(unlikely(help))
132
+ buffer_sprintf(wb
133
+ , "# COMMENT %s_%s_%s: chart \"%s\", context \"%s\", family \"%s\", dimension \"%s\", value * " COLLECTED_NUMBER_FORMAT " / " COLLECTED_NUMBER_FORMAT " %s %s (%s)\n"
134
+ , prefix
135
+ , context
136
+ , dimension
137
+ , (names && st->name) ? st->name : st->id
138
+ , st->context
139
+ , st->family
140
+ , (names && rd->name) ? rd->name : rd->id
141
+ , rd->multiplier
142
+ , rd->divisor
143
+ , h
144
+ , st->units
145
+ , t
146
+ );
147
141
- if (unlikely(types))
142
- buffer_sprintf(wb, "# COMMENT TYPE %s_%s_%s %s\n", prefix, context, dimension, t);
148
+ if(unlikely(types))
149
+ buffer_sprintf(wb, "# COMMENT TYPE %s_%s_%s %s\n"
150
+ , prefix
151
+ , context
152
+ , dimension
153
+ , t
154
+ );
155
144
- buffer_sprintf(wb, "%s_%s_%s{chart=\"%s\",family=\"%s\"%s} " COLLECTED_NUMBER_FORMAT " %llu\n",
145
- prefix, context, dimension,
146
- chart, family, labels,
147
- rd->last_collected_value, timeval_msec(&rd->last_collected_time)
156
+ buffer_sprintf(wb, "%s_%s_%s{chart=\"%s\",family=\"%s\"%s} " COLLECTED_NUMBER_FORMAT " %llu\n"
157
+ , prefix
158
+ , context
159
+ , dimension
160
+ , chart
161
+ , family
162
+ , labels
163
+ , rd->last_collected_value
164
+ , timeval_msec(&rd->last_collected_time)
165
);
166
}
167
else {
@@ -157,20 +174,27 @@ static void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER
174
prometheus_label_copy(dimension, (names && rd->name) ? rd->name : rd->id, PROMETHEUS_ELEMENT_MAX);
175
176
if (unlikely(help))
160
- buffer_sprintf(wb, "# COMMENT %s_%s: dimension \"%s\", value is %s, gauge, dt %llu to %llu inclusive\n",
161
- prefix, context,
162
- (names && rd->name) ? rd->name : rd->id,
163
- st->units,
164
- (unsigned long long)first_t, (unsigned long long)last_t
177
+ buffer_sprintf(wb, "# COMMENT %s_%s: dimension \"%s\", value is %s, gauge, dt %llu to %llu inclusive\n"
178
+ , prefix
179
+ , context
180
+ , (names && rd->name) ? rd->name : rd->id
181
+ , st->units
182
+ , (unsigned long long)first_t
183
+ , (unsigned long long)last_t
184
);
185
186
if (unlikely(types))
187
buffer_sprintf(wb, "# COMMENT TYPE %s_%s gauge\n", prefix, context);
188
170
- buffer_sprintf(wb, "%s_%s{chart=\"%s\",family=\"%s\",dimension=\"%s\"%s} " CALCULATED_NUMBER_FORMAT " %llu\n",
171
- prefix, context,
172
- chart, family, dimension, labels,
173
- value, last_t * MSEC_PER_SEC
189
+ buffer_sprintf(wb, "%s_%s{chart=\"%s\",family=\"%s\",dimension=\"%s\"%s} " CALCULATED_NUMBER_FORMAT " %llu\n"
190
+ , prefix
191
+ , context
192
+ , chart
193
+ , family
194
+ , dimension
195
+ , labels
196
+ , value
197
+ , last_t * MSEC_PER_SEC
198
);
199
}
200
}
src/rrd.h
+2
-1
@@ -226,7 +226,8 @@ typedef enum rrdset_flags {
226
RRDSET_FLAG_BACKEND_SEND = 1 << 4, // if set, this chart should be sent to backends
227
RRDSET_FLAG_BACKEND_IGNORE = 1 << 5, // if set, this chart should not be sent to backends
228
RRDSET_FLAG_EXPOSED_UPSTREAM = 1 << 6, // if set, we have sent this chart to netdata master (streaming)
229
- RRDSET_FLAG_STORE_FIRST = 1 << 7 // if set, do not eliminate the first collection during interpolation
229
+ RRDSET_FLAG_STORE_FIRST = 1 << 7, // if set, do not eliminate the first collection during interpolation
230
+ RRDSET_FLAG_HETEROGENEOUS = 1 << 8 // if set, the chart is not homogeneus (dimensions in it have multiple algorithms, multipliers or dividers)
231
} RRDSET_FLAGS;
232
233
#ifdef HAVE_C___ATOMIC
src/rrddim.c
+17
@@ -237,6 +237,23 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
237
st->dimensions = rd;
238
else {
239
RRDDIM *td = st->dimensions;
240
+
241
+ if(td->algorithm != rd->algorithm || abs(td->multiplier) != abs(rd->multiplier) || abs(td->divisor) != abs(rd->divisor)) {
242
+ if(!rrdset_flag_check(st, RRDSET_FLAG_HETEROGENEOUS)) {
243
+ #ifdef NETDATA_INTERNAL_CHECKS
244
+ info("Dimension '%s' added on chart '%s' of host '%s' is not homogeneous to other dimensions already present (algorithm is '%s' vs '%s', multiplier is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ", divisor is " COLLECTED_NUMBER_FORMAT " vs " COLLECTED_NUMBER_FORMAT ").",
245
+ rd->name,
246
+ st->name,
247
+ st->rrdhost->hostname,
248
+ rrd_algorithm_name(rd->algorithm), rrd_algorithm_name(td->algorithm),
249
+ rd->multiplier, td->multiplier,
250
+ rd->divisor, td->divisor
251
+ );
252
+ #endif
253
+ rrdset_flag_set(st, RRDSET_FLAG_HETEROGENEOUS);
254
+ }
255
+ }
256
+
257
for(; td->next; td = td->next) ;
258
td->next = rd;
259
}