Skip to content

Commit d0408cb

Browse files
committed
Merge branch 'collectd-5.5' into collectd-5.6
2 parents 8476eff + f8232cf commit d0408cb

File tree

5 files changed

+109
-48
lines changed

5 files changed

+109
-48
lines changed

contrib/examples/myplugin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int my_read (void)
104104

105105
/* it is strongly recommended to use a type defined in the types.db file
106106
* instead of a custom type */
107-
sstrncpy (vl.type, "myplugin", sizeof (vl.plugin));
107+
sstrncpy (vl.type, "myplugin", sizeof (vl.type));
108108
/* optionally set vl.plugin_instance and vl.type_instance to reasonable
109109
* values (default: "") */
110110

@@ -114,7 +114,7 @@ static int my_read (void)
114114

115115
/* A return value != 0 indicates an error and the plugin will be skipped
116116
* for an increasing amount of time. */
117-
return 0;
117+
return 0;
118118
} /* static int my_read (void) */
119119

120120
/*

src/daemon/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
11241124
}
11251125

11261126
if (value == endptr) {
1127-
ERROR ("parse_value: Failed to parse string as %s: %s.",
1127+
ERROR ("parse_value: Failed to parse string as %s: \"%s\".",
11281128
DS_TYPE_TO_STRING (ds_type), value);
11291129
sfree (value);
11301130
return -1;

src/postgresql_default.conf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@
159159
</Query>
160160

161161
<Query query_plans>
162-
Statement "SELECT sum(seq_scan) AS seq, \
163-
sum(seq_tup_read) AS seq_tup_read, \
164-
sum(idx_scan) AS idx, \
165-
sum(idx_tup_fetch) AS idx_tup_fetch \
162+
Statement "SELECT coalesce(sum(seq_scan), 0) AS seq, \
163+
coalesce(sum(seq_tup_read), 0) AS seq_tup_read, \
164+
coalesce(sum(idx_scan), 0) AS idx, \
165+
coalesce(sum(idx_tup_fetch), 0) AS idx_tup_fetch \
166166
FROM pg_stat_user_tables;"
167167

168168
<Result>
@@ -207,10 +207,10 @@
207207

208208
<Query query_plans_by_table>
209209
Statement "SELECT schemaname, relname, \
210-
seq_scan AS seq, \
211-
seq_tup_read AS seq_tup_read, \
212-
idx_scan AS idx, \
213-
idx_tup_fetch AS idx_tup_fetch \
210+
coalesce(seq_scan, 0) AS seq, \
211+
coalesce(seq_tup_read, 0) AS seq_tup_read, \
212+
coalesce(idx_scan, 0) AS idx, \
213+
coalesce(idx_tup_fetch, 0) AS idx_tup_fetch \
214214
FROM pg_stat_user_tables;"
215215

216216
<Result>

src/rrdcached.c

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,31 @@ static int rc_config (oconfig_item_t *ci)
287287
return (0);
288288
} /* int rc_config */
289289

290+
static int try_reconnect (void)
291+
{
292+
int status;
293+
294+
rrdc_disconnect ();
295+
296+
rrd_clear_error ();
297+
status = rrdc_connect (daemon_address);
298+
if (status != 0)
299+
{
300+
ERROR ("rrdcached plugin: Failed to reconnect to RRDCacheD "
301+
"at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
302+
return (-1);
303+
}
304+
305+
INFO ("rrdcached plugin: Successfully reconnected to RRDCacheD "
306+
"at %s", daemon_address);
307+
return (0);
308+
} /* int try_reconnect */
309+
290310
static int rc_read (void)
291311
{
292312
int status;
293313
rrdc_stats_t *head;
314+
_Bool retried = 0;
294315

295316
value_t values[1];
296317
value_list_t vl = VALUE_LIST_INIT;
@@ -311,19 +332,35 @@ static int rc_read (void)
311332
sstrncpy (vl.host, daemon_address, sizeof (vl.host));
312333
sstrncpy (vl.plugin, "rrdcached", sizeof (vl.plugin));
313334

335+
rrd_clear_error ();
314336
status = rrdc_connect (daemon_address);
315337
if (status != 0)
316338
{
317-
ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
318-
daemon_address, status);
339+
ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
340+
"at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
319341
return (-1);
320342
}
321343

322-
head = NULL;
323-
status = rrdc_stats_get (&head);
324-
if (status != 0)
344+
while (42)
325345
{
326-
ERROR ("rrdcached plugin: rrdc_stats_get failed with status %i.", status);
346+
/* The RRD client lib does not provide any means for checking a
347+
* connection, hence we'll have to retry upon failed operations. */
348+
head = NULL;
349+
rrd_clear_error ();
350+
status = rrdc_stats_get (&head);
351+
if (status == 0)
352+
break;
353+
354+
if (!retried)
355+
{
356+
retried = 1;
357+
if (try_reconnect () == 0)
358+
continue;
359+
/* else: report the error and fail */
360+
}
361+
362+
ERROR ("rrdcached plugin: rrdc_stats_get failed: %s (status=%i).",
363+
rrd_get_error (), status);
327364
return (-1);
328365
}
329366

@@ -411,6 +448,7 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl,
411448
char values[512];
412449
char *values_array[2];
413450
int status;
451+
_Bool retried = 0;
414452

415453
if (daemon_address == NULL)
416454
{
@@ -467,20 +505,34 @@ static int rc_write (const data_set_t *ds, const value_list_t *vl,
467505
}
468506
}
469507

508+
rrd_clear_error ();
470509
status = rrdc_connect (daemon_address);
471510
if (status != 0)
472511
{
473-
ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
474-
daemon_address, status);
512+
ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
513+
"at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
475514
return (-1);
476515
}
477516

478-
status = rrdc_update (filename, /* values_num = */ 1, (void *) values_array);
479-
if (status != 0)
517+
while (42)
480518
{
481-
ERROR ("rrdcached plugin: rrdc_update (%s, [%s], 1) failed with "
482-
"status %i.",
483-
filename, values_array[0], status);
519+
/* The RRD client lib does not provide any means for checking a
520+
* connection, hence we'll have to retry upon failed operations. */
521+
rrd_clear_error ();
522+
status = rrdc_update (filename, /* values_num = */ 1, (void *) values_array);
523+
if (status == 0)
524+
break;
525+
526+
if (!retried)
527+
{
528+
retried = 1;
529+
if (try_reconnect () == 0)
530+
continue;
531+
/* else: report the error and fail */
532+
}
533+
534+
ERROR ("rrdcached plugin: rrdc_update (%s, [%s], 1) failed: %s (status=%i)",
535+
filename, values_array[0], rrd_get_error (), status);
484536
return (-1);
485537
}
486538

@@ -493,6 +545,7 @@ static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
493545
{
494546
char filename[PATH_MAX + 1];
495547
int status;
548+
_Bool retried = 0;
496549

497550
if (identifier == NULL)
498551
return (EINVAL);
@@ -502,19 +555,34 @@ static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
502555
else
503556
ssnprintf (filename, sizeof (filename), "%s.rrd", identifier);
504557

558+
rrd_clear_error ();
505559
status = rrdc_connect (daemon_address);
506560
if (status != 0)
507561
{
508-
ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
509-
daemon_address, status);
562+
ERROR ("rrdcached plugin: Failed to connect to RRDCacheD "
563+
"at %s: %s (status=%d)", daemon_address, rrd_get_error (), status);
510564
return (-1);
511565
}
512566

513-
status = rrdc_flush (filename);
514-
if (status != 0)
567+
while (42)
515568
{
516-
ERROR ("rrdcached plugin: rrdc_flush (%s) failed with status %i.",
517-
filename, status);
569+
/* The RRD client lib does not provide any means for checking a
570+
* connection, hence we'll have to retry upon failed operations. */
571+
rrd_clear_error ();
572+
status = rrdc_flush (filename);
573+
if (status == 0)
574+
break;
575+
576+
if (!retried)
577+
{
578+
retried = 1;
579+
if (try_reconnect () == 0)
580+
continue;
581+
/* else: report the error and fail */
582+
}
583+
584+
ERROR ("rrdcached plugin: rrdc_flush (%s) failed: %s (status=%i).",
585+
filename, rrd_get_error (), status);
518586
return (-1);
519587
}
520588
DEBUG ("rrdcached plugin: rrdc_flush (%s): Success.", filename);

src/vserver.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,7 @@ static derive_t vserver_get_sock_bytes(const char *s)
132132

133133
static int vserver_read (void)
134134
{
135-
#if NAME_MAX < 1024
136-
# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + 1024 + 1)
137-
#else
138-
# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + NAME_MAX + 1)
139-
#endif
140-
141-
DIR *proc;
142-
struct dirent *dent; /* 42 */
143-
char dirent_buffer[DIRENT_BUFFER_SIZE];
135+
DIR *proc;
144136

145137
errno = 0;
146138
proc = opendir (PROCDIR);
@@ -154,6 +146,7 @@ static int vserver_read (void)
154146

155147
while (42)
156148
{
149+
struct dirent *dent;
157150
int len;
158151
char file[BUFSIZE];
159152

@@ -165,20 +158,20 @@ static int vserver_read (void)
165158

166159
int status;
167160

168-
status = readdir_r (proc, (struct dirent *) dirent_buffer, &dent);
169-
if (status != 0)
161+
errno = 0;
162+
dent = readdir (proc);
163+
if (dent == NULL)
170164
{
171165
char errbuf[4096];
172-
ERROR ("vserver plugin: readdir_r failed: %s",
173-
sstrerror (errno, errbuf, sizeof (errbuf)));
166+
167+
if (errno == 0) /* end of directory */
168+
break;
169+
170+
ERROR ("vserver plugin: failed to read directory %s: %s",
171+
PROCDIR, sstrerror (errno, errbuf, sizeof (errbuf)));
174172
closedir (proc);
175173
return (-1);
176174
}
177-
else if (dent == NULL)
178-
{
179-
/* end of directory */
180-
break;
181-
}
182175

183176
if (dent->d_name[0] == '.')
184177
continue;

0 commit comments

Comments
 (0)