transfer VARIABLEs immediately, without upstream reconnection
Costa Tsaousis (ktsaou) committed
Oct 15, 2017 at 16:11 UTC
c592c5fffa5a9ba3282eba9b8e8c075b964d4821
8 files changed
+34
-17
src/health.h
+1
-1
@@ -364,7 +364,7 @@ void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf);
364
365
extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name);
366
extern void rrdvar_custom_host_variable_destroy(RRDHOST *host, const char *name);
367
-extern void rrdvar_custom_host_variable_set(RRDVAR *rv, calculated_number value);
367
+extern void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, calculated_number value);
368
369
extern const char *rrdcalc_status2string(RRDCALC_STATUS status);
370
src/ipc.c
+4
-4
@@ -188,8 +188,8 @@ int do_ipc(int update_every, usec_t dt) {
188
arrays_max = rrdvar_custom_host_variable_create(localhost, "ipc.semaphores.arrays.max");
189
semaphores_max = rrdvar_custom_host_variable_create(localhost, "ipc.semaphores.max");
190
191
- if(arrays_max) rrdvar_custom_host_variable_set(arrays_max, limits.semmni);
192
- if(semaphores_max) rrdvar_custom_host_variable_set(semaphores_max, limits.semmns);
191
+ if(arrays_max) rrdvar_custom_host_variable_set(localhost, arrays_max, limits.semmni);
192
+ if(semaphores_max) rrdvar_custom_host_variable_set(localhost, semaphores_max, limits.semmns);
193
194
// create the charts
195
if(unlikely(!st_semaphores)) {
@@ -234,8 +234,8 @@ int do_ipc(int update_every, usec_t dt) {
234
error("Unable to fetch semaphore limits.");
235
}
236
else {
237
- if(arrays_max) rrdvar_custom_host_variable_set(arrays_max, limits.semmni);
238
- if(semaphores_max) rrdvar_custom_host_variable_set(semaphores_max, limits.semmns);
237
+ if(arrays_max) rrdvar_custom_host_variable_set(localhost, arrays_max, limits.semmni);
238
+ if(semaphores_max) rrdvar_custom_host_variable_set(localhost, semaphores_max, limits.semmns);
239
240
st_arrays->red = limits.semmni;
241
st_semaphores->red = limits.semmns;
src/plugins_d.c
+1
-1
@@ -388,7 +388,7 @@ inline size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int
388
calculated_number v = (calculated_number)str2ld(value, NULL);
389
RRDVAR *rv = rrdvar_custom_host_variable_create(host, name);
390
if(rv)
391
- rrdvar_custom_host_variable_set(rv, v);
391
+ rrdvar_custom_host_variable_set(host, rv, v);
392
else
393
error("PLUGINSD: '%s': cannot find/create VARIABLE '%s' on host '%s'", cd->fullfilename, name, host->hostname);
394
}
src/proc_net_stat_conntrack.c
+1
-1
@@ -122,7 +122,7 @@ int do_proc_net_stat_conntrack(int update_every, usec_t dt) {
122
123
unsigned long long max;
124
if(likely(!read_single_number_file(nf_conntrack_max_filename, &max)))
125
- rrdvar_custom_host_variable_set(rrdvar_max, max);
125
+ rrdvar_custom_host_variable_set(localhost, rrdvar_max, max);
126
}
127
128
// --------------------------------------------------------------------
src/rrd.h
-1
@@ -697,7 +697,6 @@ extern collected_number rrddim_set(RRDSET *st, const char *id, collected_number
697
698
extern long align_entries_to_pagesize(RRD_MEMORY_MODE mode, long entries);
699
700
-
700
// ----------------------------------------------------------------------------
701
// RRD internal functions
702
src/rrdpush.c
+21
-8
@@ -188,20 +188,33 @@ void rrdset_done_push(RRDSET *st) {
188
// ----------------------------------------------------------------------------
189
// rrdpush sender thread
190
191
+static inline void rrdpush_sender_add_variable_to_buffer_nolock(RRDHOST *host, RRDVAR *rv) {
192
+ calculated_number *value = (calculated_number *)rv->value;
193
+
194
+ buffer_sprintf(
195
+ host->rrdpush_sender_buffer
196
+ , "VARIABLE %s = " CALCULATED_NUMBER_FORMAT "\n"
197
+ , rv->name
198
+ , *value
199
+ );
200
+}
201
+
202
+void rrdpush_sender_send_this_variable_now(RRDHOST *host, RRDVAR *rv) {
203
+ if(host->rrdpush_send_enabled && host->rrdpush_sender_spawn && host->rrdpush_sender_connected) {
204
+ rrdpush_buffer_lock(host);
205
+ rrdpush_sender_add_variable_to_buffer_nolock(host, rv);
206
+ rrdpush_buffer_unlock(host);
207
+ }
208
+}
209
+
210
static int rrdpush_sender_thread_custom_variables_callback(void *rrdvar_ptr, void *host_ptr) {
211
RRDVAR *rv = (RRDVAR *)rrdvar_ptr;
212
RRDHOST *host = (RRDHOST *)host_ptr;
213
214
if(unlikely(rv->type == RRDVAR_TYPE_CALCULATED_ALLOCATED)) {
196
- calculated_number *value = (calculated_number *)rv->value;
197
-
198
- buffer_sprintf(
199
- host->rrdpush_sender_buffer
200
- , "VARIABLE %s = " CALCULATED_NUMBER_FORMAT "\n"
201
- , rv->name
202
- , *value
203
- );
215
+ rrdpush_sender_add_variable_to_buffer_nolock(host, rv);
216
217
+ // return 1, so that the traversal will return the number of variables sent
218
return 1;
219
}
220
src/rrdpush.h
+2
@@ -14,4 +14,6 @@ extern void *rrdpush_sender_thread(void *ptr);
14
extern int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url);
15
extern void rrdpush_sender_thread_stop(RRDHOST *host);
16
17
+extern void rrdpush_sender_send_this_variable_now(RRDHOST *host, RRDVAR *rv);
18
+
19
#endif //NETDATA_RRDPUSH_H
src/rrdvar.c
+4
-1
@@ -157,12 +157,15 @@ void rrdvar_custom_host_variable_destroy(RRDHOST *host, const char *name) {
157
freez(rv);
158
}
159
160
-void rrdvar_custom_host_variable_set(RRDVAR *rv, calculated_number value) {
160
+void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, calculated_number value) {
161
if(rv->type != RRDVAR_TYPE_CALCULATED_ALLOCATED)
162
error("requested to set variable '%s' to value " CALCULATED_NUMBER_FORMAT " but the variable is not a custom one.", rv->name, value);
163
else {
164
calculated_number *v = rv->value;
165
*v = value;
166
+
167
+ // if the host is streaming, send this variable upstream immediately
168
+ rrdpush_sender_send_this_variable_now(host, rv);
169
}
170
}
171