@cryptotaxi247 / netdata-1 / commits / 7557b3f44

format the sdr cache filenames (#15361)

* format the sdr cache filenames * cleanup sdr cache file on startup * free the pattern * use flags to recreate the ipmi files * prevent newlines on tty * dont output newlines too frequently * Revert "dont output newlines too frequently" This reverts commit bbf26d79c9603de866d8575553a4c956c839c3fb. * detect tty

Costa Tsaousis committed Jul 11, 2023 at 23:45 UTC 7557b3f44753144dee3e3423cab4c2c700ba6c66
1 file changed +28 -5
collectors/freeipmi.plugin/freeipmi_plugin.c
+28 -5
@@ -110,12 +110,15 @@ unsigned int workaround_flags = 0;
110
111 /* Set to an appropriate alternate if desired */
112 char *sdr_cache_directory = "/tmp";
113 +char *sdr_sensors_cache_format = ".netdata-freeipmi-sensors-%H-on-%L.sdr";
114 +char *sdr_sel_cache_format = ".netdata-freeipmi-sel-%H-on-%L.sdr";
115 char *sensor_config_file = NULL;
116 char *sel_config_file = NULL;
117
118 // controlled via command line options
117 -unsigned int global_sel_flags = 0;
118 -unsigned int global_sensor_reading_flags = IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING;
119 +unsigned int global_sel_flags = IPMI_MONITORING_SEL_FLAGS_REREAD_SDR_CACHE;
120 +unsigned int global_sensor_reading_flags = IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING|IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE;
121 +bool remove_reread_sdr_after_first_use = true;
122
123 /* Initialization flags
124 *
@@ -371,6 +374,12 @@ static int netdata_read_ipmi_sensors(struct ipmi_monitoring_ipmi_config *ipmi_co
374 goto cleanup;
375 }
376 }
377 + if (sdr_sensors_cache_format) {
378 + if (ipmi_monitoring_ctx_sdr_cache_filenames(ctx, sdr_sensors_cache_format) < 0) {
379 + collector_error("ipmi_monitoring_ctx_sdr_cache_filenames(): %s\n", ipmi_monitoring_ctx_errormsg (ctx));
380 + goto cleanup;
381 + }
382 + }
383
384 timing_step(TIMING_STEP_FREEIPMI_DSR_CACHE_DIR);
385
@@ -472,6 +481,9 @@ cleanup:
481
482 timing_report();
483
484 + if(remove_reread_sdr_after_first_use)
485 + global_sensor_reading_flags &= ~(IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE);
486 +
487 return (rv);
488 }
489
@@ -491,8 +503,13 @@ static int netdata_get_ipmi_sel_events_count(struct ipmi_monitoring_ipmi_config
503
504 if (sdr_cache_directory) {
505 if (ipmi_monitoring_ctx_sdr_cache_directory (ctx, sdr_cache_directory) < 0) {
494 - collector_error( "ipmi_monitoring_ctx_sdr_cache_directory(): %s",
495 - ipmi_monitoring_ctx_errormsg (ctx));
506 + collector_error( "ipmi_monitoring_ctx_sdr_cache_directory(): %s", ipmi_monitoring_ctx_errormsg (ctx));
507 + goto cleanup;
508 + }
509 + }
510 + if (sdr_sel_cache_format) {
511 + if (ipmi_monitoring_ctx_sdr_cache_filenames(ctx, sdr_sel_cache_format) < 0) {
512 + collector_error("ipmi_monitoring_ctx_sdr_cache_filenames(): %s\n", ipmi_monitoring_ctx_errormsg (ctx));
513 goto cleanup;
514 }
515 }
@@ -528,6 +545,9 @@ cleanup:
545
546 timing_report();
547
548 + if(remove_reread_sdr_after_first_use)
549 + global_sel_flags &= ~(IPMI_MONITORING_SEL_FLAGS_REREAD_SDR_CACHE);
550 +
551 return (rv);
552 }
553
@@ -1461,6 +1481,7 @@ int main (int argc, char **argv) {
1481 else if(strcmp("reread-sdr-cache", argv[i]) == 0) {
1482 global_sel_flags |= IPMI_MONITORING_SEL_FLAGS_REREAD_SDR_CACHE;
1483 global_sensor_reading_flags |= IPMI_MONITORING_SENSOR_READING_FLAGS_REREAD_SDR_CACHE;
1484 + remove_reread_sdr_after_first_use = false;
1485 if (debug) fprintf(stderr, "%s: reread-sdr-cache enabled for both sensors and SEL\n", program_name);
1486 }
1487 else if(strcmp("interpret-oem-data", argv[i]) == 0) {
@@ -1771,13 +1792,15 @@ int main (int argc, char **argv) {
1792 size_t iteration = 0;
1793 usec_t step = 100 * USEC_PER_MS;
1794 bool global_chart_created = false;
1795 + bool tty = isatty(fileno(stderr)) == 1;
1796
1797 heartbeat_t hb;
1798 heartbeat_init(&hb);
1799 for(iteration = 0; 1 ; iteration++) {
1800 usec_t dt = heartbeat_next(&hb, step);
1801
1780 - fprintf(stdout, "\n"); // keepalive to avoid parser read timeout (2 minutes) during ipmi_detect_speed_secs()
1802 + if(!tty)
1803 + fprintf(stdout, "\n"); // keepalive to avoid parser read timeout (2 minutes) during ipmi_detect_speed_secs()
1804
1805 struct netdata_ipmi_state state = {0 };
1806