Skip to content

Commit 83fc110

Browse files
committed
fix handling performance data
the spool file way of handling performance data works like this: - check result comes in - perf data gets extracted - write perf data into spool file - close spool file - call spool file handler - open spool file again so during the runtime of the spool handler the spool file is closed for good reasons. But the check result handler simply skips adding performance data when the spool file is closed which basically means during about a second we loose all performance data. So instead of checking the spool file, we better check the buffer queue which is used to buffer the performance data already. Signed-off-by: Sven Nierlein <sven@consol.de>
1 parent c1d4580 commit 83fc110

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/naemon/perfdata.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,23 @@ int initialize_performance_data(const char *cfgfile)
8686
xpddefault_preprocess_file_templates(service_perfdata_file_template);
8787

8888
/* open the performance data caches */
89-
host_perfdata_bq = nm_bufferqueue_create();
9089
host_perfdata_fd = xpddefault_open_perfdata_file(
9190
host_perfdata_file,
9291
host_perfdata_file_pipe,
9392
host_perfdata_file_append);
94-
service_perfdata_bq = nm_bufferqueue_create();
93+
if(host_perfdata_fd > 0) {
94+
nm_log(NSLOG_RUNTIME_WARNING, "Warning: host perfdata file %s could not be opened - host performance data will not be processed!\n", host_perfdata_file);
95+
host_perfdata_bq = nm_bufferqueue_create();
96+
}
97+
9598
service_perfdata_fd = xpddefault_open_perfdata_file(
9699
service_perfdata_file,
97100
service_perfdata_file_pipe,
98101
service_perfdata_file_append);
102+
if (service_perfdata_fd > 0) {
103+
nm_log(NSLOG_RUNTIME_WARNING, "Warning: service perfdata file %s could not be opened - service performance data will not be processed!\n", service_perfdata_file);
104+
service_perfdata_bq = nm_bufferqueue_create();
105+
}
99106

100107
/* verify that performance data commands are valid */
101108
if (host_perfdata_command != NULL) {
@@ -426,6 +433,8 @@ static int xpddefault_open_perfdata_file(char *perfdata_file, int is_pipe, int a
426433
/* flush the perfdata stored in `bq` to the file referred to by `fd`, named by `filename`. Returns -1 on error, 0 on success. */
427434
static int flush_perfdata(nm_bufferqueue *bq, int fd, const char *filename)
428435
{
436+
if(bq == NULL)
437+
return -1;
429438
if (fd >= 0) {
430439
if (nm_bufferqueue_write(bq, fd) >= 0) {
431440
return 0;
@@ -485,7 +494,7 @@ static int xpddefault_update_service_performance_data_file(nagios_macros *mac, s
485494
if (svc == NULL)
486495
return ERROR;
487496

488-
if (service_perfdata_fd < 0)
497+
if (service_perfdata_bq == NULL)
489498
return OK;
490499

491500
if (service_perfdata_file_template == NULL)
@@ -502,8 +511,8 @@ static int xpddefault_update_service_performance_data_file(nagios_macros *mac, s
502511
log_debug_info(DEBUGL_PERFDATA, 2, "Processed service performance data file output: %s\n", processed_output);
503512

504513
nm_bufferqueue_push(service_perfdata_bq, processed_output, strlen(processed_output));
505-
/* temporary failures are fine - if it's serious, we log before we run the processing event */
506514

515+
/* temporary failures are fine - if it's serious, we log before we run the processing event */
507516
flush_perfdata(service_perfdata_bq, service_perfdata_fd, service_perfdata_file);
508517

509518
nm_free(raw_output);
@@ -523,7 +532,7 @@ static int xpddefault_update_host_performance_data_file(nagios_macros *mac, host
523532
if (hst == NULL)
524533
return ERROR;
525534

526-
if (host_perfdata_fd < 0)
535+
if (host_perfdata_bq == NULL)
527536
return OK;
528537

529538
if (host_perfdata_file_template == NULL)
@@ -540,6 +549,7 @@ static int xpddefault_update_host_performance_data_file(nagios_macros *mac, host
540549
log_debug_info(DEBUGL_PERFDATA, 2, "Processed host performance data file output: %s\n", processed_output);
541550

542551
nm_bufferqueue_push(host_perfdata_bq, processed_output, strlen(processed_output));
552+
543553
/* temporary failures are fine - if it's serious, we log before we run the processing event */
544554
flush_perfdata(host_perfdata_bq, host_perfdata_fd, host_perfdata_file);
545555

@@ -559,6 +569,8 @@ static void xpddefault_process_host_job_handler(struct wproc_result *wpres, void
559569
host_perfdata_file,
560570
host_perfdata_file_pipe,
561571
host_perfdata_file_append);
572+
if (host_perfdata_fd > 0)
573+
flush_perfdata(host_perfdata_bq, host_perfdata_fd, host_perfdata_file);
562574
}
563575

564576
/* periodically process the host perf data file */
@@ -626,6 +638,8 @@ static void xpddefault_process_service_job_handler(struct wproc_result *wpres, v
626638
service_perfdata_file,
627639
service_perfdata_file_pipe,
628640
service_perfdata_file_append);
641+
if (service_perfdata_fd > 0)
642+
flush_perfdata(service_perfdata_bq, service_perfdata_fd, service_perfdata_file);
629643
}
630644

631645
/* periodically process the service perf data file */

0 commit comments

Comments
 (0)