@cryptotaxi247 / netdata-1 / commits / 7cb252795

ipmi plugin now monitors sensors state

Costa Tsaousis (ktsaou) committed Mar 7, 2017 at 00:01 UTC 7cb2527958e61d7f15383c78ddc20d3a54f082a7
1 file changed +82 -24
src/freeipmi_plugin.c
+82 -24
@@ -36,20 +36,20 @@
36 char *hostname = NULL;
37
38 /* In-band Communication Configuration */
39 -int driver_type = IPMI_MONITORING_DRIVER_TYPE_KCS; /* or -1 for default */
39 +int driver_type = -1; // IPMI_MONITORING_DRIVER_TYPE_KCS; /* or -1 for default */
40 int disable_auto_probe = 0; /* probe for in-band device */
41 unsigned int driver_address = 0; /* not used if probing */
42 unsigned int register_spacing = 0; /* not used if probing */
43 char *driver_device = NULL; /* not used if probing */
44
45 /* Out-of-band Communication Configuration */
46 -int protocol_version = IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */
46 +int protocol_version = -1; //IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */
47 char *username = "foousername";
48 char *password = "foopassword";
49 unsigned char *k_g = NULL;
50 unsigned int k_g_len = 0;
51 -int privilege_level = IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */
52 -int authentication_type = IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */
51 +int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */
52 +int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */
53 int cipher_suite_id = 0; /* or -1 for default */
54 int session_timeout = 0; /* 0 for default */
55 int retransmission_timeout = 0; /* 0 for default */
@@ -244,10 +244,14 @@ static int debug = 0;
244
245 static int netdata_update_every = 5;
246 static int netdata_priority = 90000;
247 +static int netdata_do_sel = 1;
248
249 static size_t netdata_sensors_updated = 0;
250 static size_t netdata_sensors_collected = 0;
251 static size_t netdata_sel_events = 0;
252 +static size_t netdata_sensors_state_nominal = 0;
253 +static size_t netdata_sensors_state_warning = 0;
254 +static size_t netdata_sensors_state_critical = 0;
255
256 struct sensor {
257 int record_id;
@@ -279,6 +283,10 @@ static void netdata_mark_as_not_updated() {
283 netdata_sensors_updated = 0;
284 netdata_sensors_collected = 0;
285 netdata_sel_events = 0;
286 +
287 + netdata_sensors_state_nominal = 0;
288 + netdata_sensors_state_warning = 0;
289 + netdata_sensors_state_critical = 0;
290 }
291
292 static void send_chart_to_netdata_for_units(int units) {
@@ -287,49 +295,49 @@ static void send_chart_to_netdata_for_units(int units) {
295 switch(units) {
296 case IPMI_MONITORING_SENSOR_UNITS_CELSIUS:
297 printf("CHART ipmi.temperatures_c '' 'System Celcius Temperatures read by IPMI' 'Celcius' 'temperatures' 'ipmi.temperatures_c' 'line' %d %d\n"
290 - , netdata_priority
298 + , netdata_priority + 10
299 , netdata_update_every
300 );
301 break;
302
303 case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT:
304 printf("CHART ipmi.temperatures_f '' 'System Fahrenheit Temperatures read by IPMI' 'Fahrenheit' 'temperatures' 'ipmi.temperatures_f' 'line' %d %d\n"
297 - , netdata_priority
305 + , netdata_priority + 11
306 , netdata_update_every
307 );
308 break;
309
310 case IPMI_MONITORING_SENSOR_UNITS_VOLTS:
311 printf("CHART ipmi.volts '' 'System Voltages read by IPMI' 'Volts' 'voltages' 'ipmi.voltages' 'line' %d %d\n"
304 - , netdata_priority
312 + , netdata_priority + 12
313 , netdata_update_every
314 );
315 break;
316
317 case IPMI_MONITORING_SENSOR_UNITS_AMPS:
318 printf("CHART ipmi.amps '' 'System Current read by IPMI' 'Amps' 'current' 'ipmi.amps' 'line' %d %d\n"
311 - , netdata_priority
319 + , netdata_priority + 13
320 , netdata_update_every
321 );
322 break;
323
324 case IPMI_MONITORING_SENSOR_UNITS_RPM:
325 printf("CHART ipmi.rpm '' 'System Fans read by IPMI' 'RPM' 'fans' 'ipmi.rpm' 'line' %d %d\n"
318 - , netdata_priority
326 + , netdata_priority + 14
327 , netdata_update_every
328 );
329 break;
330
331 case IPMI_MONITORING_SENSOR_UNITS_WATTS:
332 printf("CHART ipmi.watts '' 'System Power read by IPMI' 'Watts' 'power' 'ipmi.watts' 'line' %d %d\n"
325 - , netdata_priority
333 + , netdata_priority + 5
334 , netdata_update_every
335 );
336 break;
337
338 case IPMI_MONITORING_SENSOR_UNITS_PERCENT:
339 printf("CHART ipmi.percent '' 'System Metrics read by IPMI' '%%' 'other' 'ipmi.percent' 'line' %d %d\n"
332 - , netdata_priority
340 + , netdata_priority + 15
341 , netdata_update_every
342 );
343 break;
@@ -459,23 +467,53 @@ static void send_metrics_to_netdata_for_units(int units) {
467 }
468
469 static void send_metrics_to_netdata() {
462 - static int sel_chart_generated = 0;
470 + static int sel_chart_generated = 0, sensors_state_chart_generated = 0;
471 struct sensor *sn;
472
465 - if(!sel_chart_generated) {
466 - printf("CHART ipmi.events '' 'IPMI Events' 'events' 'events' 'ipmi.sel' 'area' %d %d\n"
467 - , netdata_priority
473 + if(netdata_do_sel && !sel_chart_generated) {
474 + sel_chart_generated = 1;
475 + printf("CHART ipmi.events '' 'IPMI Events' 'events' 'events' ipmi.sel area %d %d\n"
476 + , netdata_priority + 2
477 , netdata_update_every
478 );
479 printf("DIMENSION events '' absolute 1 1\n");
480 }
481
482 + if(!sensors_state_chart_generated) {
483 + sensors_state_chart_generated = 1;
484 + printf("CHART ipmi.sensors_state '' 'IPMI Sensors State' 'sensors' 'sensors' ipmi.sensors_state stacked %d %d\n"
485 + , netdata_priority + 1
486 + , netdata_update_every
487 + );
488 + printf("DIMENSION nominal '' absolute 1 1\n");
489 + printf("DIMENSION critical '' absolute 1 1\n");
490 + printf("DIMENSION warning '' absolute 1 1\n");
491 + }
492 +
493 // generate the CHART/DIMENSION lines, if we have to
494 for(sn = sensors_root; sn; sn = sn->next)
495 if(sn->updated && !sn->exposed && !sn->ignore)
496 send_chart_to_netdata_for_units(sn->sensor_units);
497
478 - printf("BEGIN ipmi.events\nSET events = %zu\nEND\n", netdata_sel_events);
498 + if(netdata_do_sel) {
499 + printf(
500 + "BEGIN ipmi.events\n"
501 + "SET events = %zu\n"
502 + "END\n"
503 + , netdata_sel_events
504 + );
505 + }
506 +
507 + printf(
508 + "BEGIN ipmi.sensors_state\n"
509 + "SET nominal = %zu\n"
510 + "SET warning = %zu\n"
511 + "SET critical = %zu\n"
512 + "END\n"
513 + , netdata_sensors_state_nominal
514 + , netdata_sensors_state_warning
515 + , netdata_sensors_state_critical
516 + );
517
518 // send metrics to netdata
519 for(sn = sensors_root; sn; sn = sn->next)
@@ -552,14 +590,22 @@ static void netdata_get_sensor(
590 break;
591 }
592
555 -/* switch(sensor_state) {
593 + switch(sensor_state) {
594 case IPMI_MONITORING_STATE_NOMINAL:
595 + netdata_sensors_state_nominal++;
596 + break;
597 +
598 case IPMI_MONITORING_STATE_WARNING:
599 + netdata_sensors_state_warning++;
600 + break;
601 +
602 case IPMI_MONITORING_STATE_CRITICAL:
603 + netdata_sensors_state_critical++;
604 + break;
605 +
606 default:
607 break;
608 }
562 -*/
609 }
610
611 static void netdata_get_sel(
@@ -1321,7 +1367,10 @@ int ipmi_collect_data(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1367 errno = 0;
1368
1369 if (_ipmimonitoring_sensors(ipmi_config) < 0) return -1;
1324 - if (_ipmimonitoring_sel (ipmi_config) < 0) return -2;
1370 +
1371 + if(netdata_do_sel) {
1372 + if(_ipmimonitoring_sel(ipmi_config) < 0) return -2;
1373 + }
1374
1375 return 0;
1376 }
@@ -1350,11 +1399,11 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1399 sleep_usec(end - start);
1400 }
1401
1353 - // so, we assume it needed 3x the time
1402 + // so, we assume it needed 2x the time
1403 // we find the average in microseconds
1404 // and we round-up to the closest second
1405
1357 - return (( total * 3 / checks / 1000000 ) + 1);
1406 + return (( total * 2 / checks / 1000000 ) + 1);
1407 }
1408
1409 int main (int argc, char **argv) {
@@ -1409,17 +1458,26 @@ int main (int argc, char **argv) {
1458 exit(1);
1459 }
1460 else if(i < argc && strcmp("hostname", argv[i]) == 0) {
1412 - hostname = argv[++i];
1461 + hostname = strdupz(argv[++i]);
1462 + char *s = argv[i];
1463 + // mask it be hidden from the process tree
1464 + while(*s) *s++ = 'x';
1465 if(debug) fprintf(stderr, "freeipmi.plugin: hostname set to '%s'\n", hostname);
1466 continue;
1467 }
1468 else if(i < argc && strcmp("username", argv[i]) == 0) {
1417 - username = argv[++i];
1469 + username = strdupz(argv[++i]);
1470 + char *s = argv[i];
1471 + // mask it be hidden from the process tree
1472 + while(*s) *s++ = 'x';
1473 if(debug) fprintf(stderr, "freeipmi.plugin: username set to '%s'\n", username);
1474 continue;
1475 }
1476 else if(i < argc && strcmp("password", argv[i]) == 0) {
1422 - password = argv[++i];
1477 + password = strdupz(argv[++i]);
1478 + char *s = argv[i];
1479 + // mask it be hidden from the process tree
1480 + while(*s) *s++ = 'x';
1481 if(debug) fprintf(stderr, "freeipmi.plugin: password set to '%s'\n", password);
1482 continue;
1483 }