@cryptotaxi247 / netdata-1 / commits / d2331f12a

enabled freeipmi.plugin automatically when possible; make freeipmi.plugin netdata friendly;

Costa Tsaousis (ktsaou) committed Mar 3, 2017 at 22:38 UTC d2331f12ac51cd08f981dc824e0db7a42c9dc0e5
4 files changed +173 -195
configure.ac
+10 -6
@@ -81,7 +81,7 @@ AC_ARG_ENABLE(
81 [plugin-freeipmi],
82 [AS_HELP_STRING([--enable-plugin-freeipmi], [freeipmi plugin, requires root])],
83 ,
84 - [enable_plugin_freeipmi="no"]
84 + [enable_plugin_freeipmi="detect"]
85 )
86 AC_ARG_ENABLE(
87 [pedantic],
@@ -197,15 +197,19 @@ AC_DEFINE([NETDATA_WITH_UUID], [1], [uuid settings])
197 OPTIONAL_UUID_CLFAGS="${UUID_CFLAGS}"
198 OPTIONAL_UUID_LIBS="${UUID_LIBS}"
199
200 -if test "${enable_plugin_freeipmi}" = "yes"; then
200 +if test ! "${enable_plugin_freeipmi}" = "no"; then
201 PKG_CHECK_MODULES(
202 [IPMIMONITORING],
203 [libipmimonitoring],
204 )
205 - test -z "${IPMIMONITORING_LIBS}" && AC_MSG_ERROR([ipmimonitoring required but not found. Try installing 'libipmimonitoring-dev' or 'libipmimonitoring-devel'])
206 - AC_DEFINE([HAVE_FREEIPMI], [1], [ipmimonitoring usability])
207 - OPTIONAL_IPMIMONITORING_CLFAGS="${IPMIMONITORING_CFLAGS}"
208 - OPTIONAL_IPMIMONITORING_LIBS="${IPMIMONITORING_LIBS}"
205 + if test ! -z "${IPMIMONITORING_LIBS}"; then
206 + enable_plugin_freeipmi="yes"
207 + AC_DEFINE([HAVE_FREEIPMI], [1], [ipmimonitoring usability])
208 + OPTIONAL_IPMIMONITORING_CLFAGS="${IPMIMONITORING_CFLAGS}"
209 + OPTIONAL_IPMIMONITORING_LIBS="${IPMIMONITORING_LIBS}"
210 + elif "${enable_plugin_freeipmi}" = "yes"; then
211 + AC_MSG_ERROR([ipmimonitoring required but not found. Try installing 'libipmimonitoring-dev' or 'libipmimonitoring-devel'])
212 + fi
213 fi
214 AM_CONDITIONAL([FREEIPMI], [test x$enable_plugin_freeipmi = xyes])
215
netdata-installer.sh
+7 -1
@@ -99,8 +99,10 @@ Valid <installer options> are:
99 Start immediately building it.
100
101 --enable-plugin-freeipmi
102 + --disable-plugin-freeipmi
103
103 - Enable the FreeIPMI plugin.
104 + Enable/disable the FreeIPMI plugin.
105 + Default: enable it when libipmimonitoring is available.
106
107 --zlib-is-really-here
108 --libs-are-really-here
@@ -193,6 +195,10 @@ do
195 then
196 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --enable-plugin-freeipmi"
197 shift 1
198 + elif [ "$1" = "--disable-plugin-freeipmi" ]
199 + then
200 + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --disable-plugin-freeipmi"
201 + shift 1
202 elif [ "$1" = "--help" -o "$1" = "-h" ]
203 then
204 usage
src/Makefile.am
+7 -2
@@ -155,8 +155,8 @@ apps_plugin_SOURCES = \
155
156 if FREEBSD
157 apps_plugin_SOURCES += \
158 - plugin_freebsd.h \
159 - $(NULL)
158 + plugin_freebsd.h \
159 + $(NULL)
160 endif
161
162 apps_plugin_LDADD = \
@@ -166,6 +166,11 @@ apps_plugin_LDADD = \
166
167 freeipmi_plugin_SOURCES = \
168 freeipmi_plugin.c \
169 + clocks.c clocks.h \
170 + common.c common.h \
171 + inlined.h \
172 + log.c log.h \
173 + procfile.c procfile.h \
174 $(NULL)
175
176 freeipmi_plugin_LDADD = \
src/freeipmi_plugin.c
+149 -186
@@ -1,31 +1,20 @@
1 -/*****************************************************************************\
2 - * $Id: ipmimonitoring-sensors.c,v 1.51 2016/11/02 23:46:24 chu11 Exp $
3 - * $Id: ipmimonitoring-sel.c,v 1.51 2016/11/02 23:46:24 chu11 Exp $
4 - *****************************************************************************
1 +/*
2 + * netdata freeipmi.plugin
3 + * Copyright (C) 2017 Costa Tsaousis
4 + * GPL v3+
5 + *
6 + * Based on:
7 + * ipmimonitoring-sensors.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
8 + * ipmimonitoring-sel.c,v 1.51 2016/11/02 23:46:24 chu11 Exp
9 + *
10 * Copyright (C) 2007-2015 Lawrence Livermore National Security, LLC.
11 * Copyright (C) 2006-2007 The Regents of the University of California.
12 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
13 * Written by Albert Chu <chu11@llnl.gov>
14 * UCRL-CODE-222073
10 - *
11 - * This file is part of Ipmimonitoring, an IPMI sensor monitoring
12 - * library. For details, see http://www.llnl.gov/linux/.
13 - *
14 - * Ipmimonitoring is free software; you can redistribute it and/or modify
15 - * it under the terms of the GNU General Public License as published by the
16 - * Free Software Foundation; either version 3 of the License, or (at your
17 - * option) any later version.
18 - *
19 - * Ipmimonitoring is distributed in the hope that it will be useful, but
20 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 - * for more details.
23 - *
24 - * You should have received a copy of the GNU General Public License along
25 - * with Ipmimonitoring. If not, see <http://www.gnu.org/licenses/>.
26 -\*****************************************************************************/
15 + */
16
28 -#include "config.h"
17 +#include "common.h"
18
19 #include <stdio.h>
20 #include <stdlib.h>
@@ -521,8 +510,7 @@ static void netdata_get_sensor(
510
511 sn = calloc(1, sizeof(struct sensor));
512 if(!sn) {
524 - fprintf(stderr, "freeipmi.plugin: cannot allocate %zu bytes of memory.", sizeof(struct sensor));
525 - exit(1);
513 + fatal("cannot allocate %zu bytes of memory.", sizeof(struct sensor));
514 }
515
516 sn->record_id = record_id;
@@ -533,8 +521,7 @@ static void netdata_get_sensor(
521 sn->sensor_reading_type = sensor_reading_type;
522 sn->sensor_name = strdup(sensor_name);
523 if(!sn->sensor_name) {
536 - fprintf(stderr, "freeipmi.plugin: cannot allocate %zu bytes of memory.", strlen(sensor_name));
537 - exit(1);
524 + fatal("cannot allocate %zu bytes of memory.", strlen(sensor_name));
525 }
526
527 sn->next = sensors_root;
@@ -588,33 +575,14 @@ static void netdata_get_sel(
575 }
576
577
591 -static unsigned long long now_realtime_usec() {
592 - struct timeval tv;
593 - gettimeofday(&tv, NULL);
594 - return tv.tv_sec * 1000000ULL + tv.tv_usec;
578 +void netdata_cleanup_and_exit(int ret) {
579 + exit(ret);
580 }
581
582 // END NETDATA CODE
583 // ----------------------------------------------------------------------------
584
585
601 -/* This is an example of how to use the libipmimonitoring library to
602 - * read and monitor sensors.
603 - *
604 - * At the top of this file, you'll find a number of variables for
605 - * configuration of IPMI communication and what sensors you are
606 - * interested in monitoring. Those variables are used in the
607 - * libipmimonitoring calls below.
608 - *
609 - * Hopefully this example will be sufficient to help anyone program
610 - * IPMI monitoring software for their environment.
611 - *
612 - * To compile, linking against the library should be sufficient for
613 - * most environments. e.g.
614 - *
615 - * gcc -o freeipmi.plugin freeipmi_plugin.c -lipmimonitoring
616 - */
617 -
586 static int
587 _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
588 {
@@ -624,9 +592,8 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
592 int sensor_count;
593 int rv = -1;
594
627 - if (!(ctx = ipmi_monitoring_ctx_create ()))
628 - {
629 - perror ("ipmi_monitoring_ctx_create:");
595 + if (!(ctx = ipmi_monitoring_ctx_create ())) {
596 + error("ipmi_monitoring_ctx_create()");
597 goto cleanup;
598 }
599
@@ -635,8 +602,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
602 if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
603 sdr_cache_directory) < 0)
604 {
638 - fprintf (stderr,
639 - "ipmi_monitoring_ctx_sdr_cache_directory: %s\n",
605 + error("ipmi_monitoring_ctx_sdr_cache_directory(): %s\n",
606 ipmi_monitoring_ctx_errormsg (ctx));
607 goto cleanup;
608 }
@@ -648,8 +614,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
614 if (ipmi_monitoring_ctx_sensor_config_file (ctx,
615 sensor_config_file) < 0)
616 {
651 - fprintf (stderr,
652 - "ipmi_monitoring_ctx_sensor_config_file: %s\n",
617 + error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
618 ipmi_monitoring_ctx_errormsg (ctx));
619 goto cleanup;
620 }
@@ -658,8 +623,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
623 {
624 if (ipmi_monitoring_ctx_sensor_config_file (ctx, NULL) < 0)
625 {
661 - fprintf (stderr,
662 - "ipmi_monitoring_ctx_sensor_config_file: %s\n",
626 + error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n",
627 ipmi_monitoring_ctx_errormsg (ctx));
628 goto cleanup;
629 }
@@ -705,8 +669,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
669 NULL,
670 NULL)) < 0)
671 {
708 - fprintf (stderr,
709 - "ipmi_monitoring_sensor_readings_by_record_id: %s\n",
672 + error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
673 ipmi_monitoring_ctx_errormsg (ctx));
674 goto cleanup;
675 }
@@ -722,8 +685,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
685 NULL,
686 NULL)) < 0)
687 {
725 - fprintf (stderr,
726 - "ipmi_monitoring_sensor_readings_by_record_id: %s\n",
688 + error( "ipmi_monitoring_sensor_readings_by_record_id(): %s",
689 ipmi_monitoring_ctx_errormsg (ctx));
690 goto cleanup;
691 }
@@ -739,8 +701,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
701 NULL,
702 NULL)) < 0)
703 {
742 - fprintf (stderr,
743 - "ipmi_monitoring_sensor_readings_by_sensor_type: %s\n",
704 + error( "ipmi_monitoring_sensor_readings_by_sensor_type(): %s",
705 ipmi_monitoring_ctx_errormsg (ctx));
706 goto cleanup;
707 }
@@ -777,48 +738,42 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
738
739 if ((record_id = ipmi_monitoring_sensor_read_record_id (ctx)) < 0)
740 {
780 - fprintf (stderr,
781 - "ipmi_monitoring_sensor_read_record_id: %s\n",
741 + error( "ipmi_monitoring_sensor_read_record_id(): %s",
742 ipmi_monitoring_ctx_errormsg (ctx));
743 goto cleanup;
744 }
745
746 if ((sensor_number = ipmi_monitoring_sensor_read_sensor_number (ctx)) < 0)
747 {
788 - fprintf (stderr,
789 - "ipmi_monitoring_sensor_read_sensor_number: %s\n",
748 + error( "ipmi_monitoring_sensor_read_sensor_number(): %s",
749 ipmi_monitoring_ctx_errormsg (ctx));
750 goto cleanup;
751 }
752
753 if ((sensor_type = ipmi_monitoring_sensor_read_sensor_type (ctx)) < 0)
754 {
796 - fprintf (stderr,
797 - "ipmi_monitoring_sensor_read_sensor_type: %s\n",
755 + error( "ipmi_monitoring_sensor_read_sensor_type(): %s",
756 ipmi_monitoring_ctx_errormsg (ctx));
757 goto cleanup;
758 }
759
760 if (!(sensor_name = ipmi_monitoring_sensor_read_sensor_name (ctx)))
761 {
804 - fprintf (stderr,
805 - "ipmi_monitoring_sensor_read_sensor_name: %s\n",
762 + error( "ipmi_monitoring_sensor_read_sensor_name(): %s",
763 ipmi_monitoring_ctx_errormsg (ctx));
764 goto cleanup;
765 }
766
767 if ((sensor_state = ipmi_monitoring_sensor_read_sensor_state (ctx)) < 0)
768 {
812 - fprintf (stderr,
813 - "ipmi_monitoring_sensor_read_sensor_state: %s\n",
769 + error( "ipmi_monitoring_sensor_read_sensor_state(): %s",
770 ipmi_monitoring_ctx_errormsg (ctx));
771 goto cleanup;
772 }
773
774 if ((sensor_units = ipmi_monitoring_sensor_read_sensor_units (ctx)) < 0)
775 {
820 - fprintf (stderr,
821 - "ipmi_monitoring_sensor_read_sensor_units: %s\n",
776 + error( "ipmi_monitoring_sensor_read_sensor_units(): %s",
777 ipmi_monitoring_ctx_errormsg (ctx));
778 goto cleanup;
779 }
@@ -826,23 +781,21 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
781 #ifdef NETDATA_COMMENTED
782 if ((sensor_bitmask_type = ipmi_monitoring_sensor_read_sensor_bitmask_type (ctx)) < 0)
783 {
829 - fprintf (stderr,
830 - "ipmi_monitoring_sensor_read_sensor_bitmask_type: %s\n",
784 + error( "ipmi_monitoring_sensor_read_sensor_bitmask_type(): %s",
785 ipmi_monitoring_ctx_errormsg (ctx));
786 goto cleanup;
787 }
788 if ((sensor_bitmask = ipmi_monitoring_sensor_read_sensor_bitmask (ctx)) < 0)
789 {
836 - fprintf (stderr,
837 - "ipmi_monitoring_sensor_read_sensor_bitmask: %s\n",
790 + error(
791 + "ipmi_monitoring_sensor_read_sensor_bitmask(): %s",
792 ipmi_monitoring_ctx_errormsg (ctx));
793 goto cleanup;
794 }
795
796 if (!(sensor_bitmask_strings = ipmi_monitoring_sensor_read_sensor_bitmask_strings (ctx)))
797 {
844 - fprintf (stderr,
845 - "ipmi_monitoring_sensor_read_sensor_bitmask_strings: %s\n",
798 + error( "ipmi_monitoring_sensor_read_sensor_bitmask_strings(): %s",
799 ipmi_monitoring_ctx_errormsg (ctx));
800 goto cleanup;
801 }
@@ -850,8 +803,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
803
804 if ((sensor_reading_type = ipmi_monitoring_sensor_read_sensor_reading_type (ctx)) < 0)
805 {
853 - fprintf (stderr,
854 - "ipmi_monitoring_sensor_read_sensor_reading_type: %s\n",
806 + error( "ipmi_monitoring_sensor_read_sensor_reading_type(): %s",
807 ipmi_monitoring_ctx_errormsg (ctx));
808 goto cleanup;
809 }
@@ -861,8 +813,7 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
813 #ifdef NETDATA_COMMENTED
814 if ((event_reading_type_code = ipmi_monitoring_sensor_read_event_reading_type_code (ctx)) < 0)
815 {
864 - fprintf (stderr,
865 - "ipmi_monitoring_sensor_read_event_reading_type_code: %s\n",
816 + error( "ipmi_monitoring_sensor_read_event_reading_type_code(): %s",
817 ipmi_monitoring_ctx_errormsg (ctx));
818 goto cleanup;
819 }
@@ -985,25 +936,6 @@ _ipmimonitoring_sensors (struct ipmi_monitoring_ipmi_config *ipmi_config)
936 }
937
938
988 -/* This is an example of how to use the libipmimonitoring library to
989 - * read and monitor the SEL.
990 - *
991 - * At the top of this file, you'll find a number of variables for
992 - * configuration of IPMI communication and what SEL records you are
993 - * interested in monitoring. Those variables are used in the
994 - * libipmimonitoring calls below.
995 - *
996 - * Hopefully this example will be sufficient to help anyone program
997 - * IPMI monitoring software for their environment.
998 - *
999 - * To compile, linking against the library should be sufficient for
1000 - * most environments. e.g.
1001 - *
1002 - * gcc -o ipmimonitoring-sel ipmimonitoring-sel.c -lipmimonitoring
1003 - */
1004 -
1005 -/* Communication Configuration - Initialize accordingly */
1006 -
939 static int
940 _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
941 {
@@ -1015,7 +947,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
947
948 if (!(ctx = ipmi_monitoring_ctx_create ()))
949 {
1018 - perror ("ipmi_monitoring_ctx_create:");
950 + error("ipmi_monitoring_ctx_create()");
951 goto cleanup;
952 }
953
@@ -1024,8 +956,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
956 if (ipmi_monitoring_ctx_sdr_cache_directory (ctx,
957 sdr_cache_directory) < 0)
958 {
1027 - fprintf (stderr,
1028 - "ipmi_monitoring_ctx_sdr_cache_directory: %s\n",
959 + error( "ipmi_monitoring_ctx_sdr_cache_directory(): %s",
960 ipmi_monitoring_ctx_errormsg (ctx));
961 goto cleanup;
962 }
@@ -1037,8 +968,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
968 if (ipmi_monitoring_ctx_sel_config_file (ctx,
969 sel_config_file) < 0)
970 {
1040 - fprintf (stderr,
1041 - "ipmi_monitoring_ctx_sel_config_file: %s\n",
971 + error( "ipmi_monitoring_ctx_sel_config_file(): %s",
972 ipmi_monitoring_ctx_errormsg (ctx));
973 goto cleanup;
974 }
@@ -1047,8 +977,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
977 {
978 if (ipmi_monitoring_ctx_sel_config_file (ctx, NULL) < 0)
979 {
1050 - fprintf (stderr,
1051 - "ipmi_monitoring_ctx_sel_config_file: %s\n",
980 + error( "ipmi_monitoring_ctx_sel_config_file(): %s",
981 ipmi_monitoring_ctx_errormsg (ctx));
982 goto cleanup;
983 }
@@ -1079,8 +1008,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1008 NULL,
1009 NULL)) < 0)
1010 {
1082 - fprintf (stderr,
1083 - "ipmi_monitoring_sel_by_record_id: %s\n",
1011 + error( "ipmi_monitoring_sel_by_record_id(): %s",
1012 ipmi_monitoring_ctx_errormsg (ctx));
1013 goto cleanup;
1014 }
@@ -1096,8 +1024,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1024 NULL,
1025 NULL)) < 0)
1026 {
1099 - fprintf (stderr,
1100 - "ipmi_monitoring_sel_by_sensor_type: %s\n",
1027 + error( "ipmi_monitoring_sel_by_sensor_type(): %s",
1028 ipmi_monitoring_ctx_errormsg (ctx));
1029 goto cleanup;
1030 }
@@ -1114,8 +1041,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1041 NULL,
1042 NULL)) < 0)
1043 {
1117 - fprintf (stderr,
1118 - "ipmi_monitoring_sel_by_sensor_type: %s\n",
1044 + error( "ipmi_monitoring_sel_by_sensor_type(): %s",
1045 ipmi_monitoring_ctx_errormsg (ctx));
1046 goto cleanup;
1047 }
@@ -1131,8 +1057,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1057 NULL,
1058 NULL)) < 0)
1059 {
1134 - fprintf (stderr,
1135 - "ipmi_monitoring_sel_by_record_id: %s\n",
1060 + error( "ipmi_monitoring_sel_by_record_id(): %s",
1061 ipmi_monitoring_ctx_errormsg (ctx));
1062 goto cleanup;
1063 }
@@ -1172,32 +1097,28 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1097
1098 if ((record_id = ipmi_monitoring_sel_read_record_id (ctx)) < 0)
1099 {
1175 - fprintf (stderr,
1176 - "ipmi_monitoring_sel_read_record_id: %s\n",
1100 + error( "ipmi_monitoring_sel_read_record_id(): %s",
1101 ipmi_monitoring_ctx_errormsg (ctx));
1102 goto cleanup;
1103 }
1104
1105 if ((record_type = ipmi_monitoring_sel_read_record_type (ctx)) < 0)
1106 {
1183 - fprintf (stderr,
1184 - "ipmi_monitoring_sel_read_record_type: %s\n",
1107 + error( "ipmi_monitoring_sel_read_record_type(): %s",
1108 ipmi_monitoring_ctx_errormsg (ctx));
1109 goto cleanup;
1110 }
1111
1112 if ((record_type_class = ipmi_monitoring_sel_read_record_type_class (ctx)) < 0)
1113 {
1191 - fprintf (stderr,
1192 - "ipmi_monitoring_sel_read_record_type_class: %s\n",
1114 + error( "ipmi_monitoring_sel_read_record_type_class(): %s",
1115 ipmi_monitoring_ctx_errormsg (ctx));
1116 goto cleanup;
1117 }
1118
1119 if ((sel_state = ipmi_monitoring_sel_read_sel_state (ctx)) < 0)
1120 {
1199 - fprintf (stderr,
1200 - "ipmi_monitoring_sel_read_sel_state: %s\n",
1121 + error( "ipmi_monitoring_sel_read_sel_state(): %s",
1122 ipmi_monitoring_ctx_errormsg (ctx));
1123 goto cleanup;
1124 }
@@ -1229,8 +1150,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1150
1151 if (ipmi_monitoring_sel_read_timestamp (ctx, &timestamp) < 0)
1152 {
1232 - fprintf (stderr,
1233 - "ipmi_monitoring_sel_read_timestamp: %s\n",
1153 + error( "ipmi_monitoring_sel_read_timestamp(): %s",
1154 ipmi_monitoring_ctx_errormsg (ctx));
1155 goto cleanup;
1156 }
@@ -1259,40 +1179,35 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1179
1180 if (!(sensor_name = ipmi_monitoring_sel_read_sensor_name (ctx)))
1181 {
1262 - fprintf (stderr,
1263 - "ipmi_monitoring_sel_read_sensor_name: %s\n",
1182 + error( "ipmi_monitoring_sel_read_sensor_name(): %s",
1183 ipmi_monitoring_ctx_errormsg (ctx));
1184 goto cleanup;
1185 }
1186
1187 if ((sensor_type = ipmi_monitoring_sel_read_sensor_type (ctx)) < 0)
1188 {
1270 - fprintf (stderr,
1271 - "ipmi_monitoring_sel_read_sensor_type: %s\n",
1189 + error( "ipmi_monitoring_sel_read_sensor_type(): %s",
1190 ipmi_monitoring_ctx_errormsg (ctx));
1191 goto cleanup;
1192 }
1193
1194 if ((sensor_number = ipmi_monitoring_sel_read_sensor_number (ctx)) < 0)
1195 {
1278 - fprintf (stderr,
1279 - "ipmi_monitoring_sel_read_sensor_number: %s\n",
1196 + error( "ipmi_monitoring_sel_read_sensor_number(): %s",
1197 ipmi_monitoring_ctx_errormsg (ctx));
1198 goto cleanup;
1199 }
1200
1201 if ((event_direction = ipmi_monitoring_sel_read_event_direction (ctx)) < 0)
1202 {
1286 - fprintf (stderr,
1287 - "ipmi_monitoring_sel_read_event_direction: %s\n",
1203 + error( "ipmi_monitoring_sel_read_event_direction(): %s",
1204 ipmi_monitoring_ctx_errormsg (ctx));
1205 goto cleanup;
1206 }
1207
1208 if ((event_type_code = ipmi_monitoring_sel_read_event_type_code (ctx)) < 0)
1209 {
1294 - fprintf (stderr,
1295 - "ipmi_monitoring_sel_read_event_type_code: %s\n",
1210 + error( "ipmi_monitoring_sel_read_event_type_code(): %s",
1211 ipmi_monitoring_ctx_errormsg (ctx));
1212 goto cleanup;
1213 }
@@ -1302,32 +1217,28 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1217 &event_data2,
1218 &event_data3) < 0)
1219 {
1305 - fprintf (stderr,
1306 - "ipmi_monitoring_sel_read_event_data: %s\n",
1220 + error( "ipmi_monitoring_sel_read_event_data(): %s",
1221 ipmi_monitoring_ctx_errormsg (ctx));
1222 goto cleanup;
1223 }
1224
1225 if ((event_offset_type = ipmi_monitoring_sel_read_event_offset_type (ctx)) < 0)
1226 {
1313 - fprintf (stderr,
1314 - "ipmi_monitoring_sel_read_event_offset_type: %s\n",
1227 + error( "ipmi_monitoring_sel_read_event_offset_type(): %s",
1228 ipmi_monitoring_ctx_errormsg (ctx));
1229 goto cleanup;
1230 }
1231
1232 if ((event_offset = ipmi_monitoring_sel_read_event_offset (ctx)) < 0)
1233 {
1321 - fprintf (stderr,
1322 - "ipmi_monitoring_sel_read_event_offset: %s\n",
1234 + error( "ipmi_monitoring_sel_read_event_offset(): %s",
1235 ipmi_monitoring_ctx_errormsg (ctx));
1236 goto cleanup;
1237 }
1238
1239 if (!(event_offset_string = ipmi_monitoring_sel_read_event_offset_string (ctx)))
1240 {
1329 - fprintf (stderr,
1330 - "ipmi_monitoring_sel_read_event_offset_string: %s\n",
1241 + error( "ipmi_monitoring_sel_read_event_offset_string(): %s",
1242 ipmi_monitoring_ctx_errormsg (ctx));
1243 goto cleanup;
1244 }
@@ -1369,8 +1280,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1280 {
1281 if ((manufacturer_id = ipmi_monitoring_sel_read_manufacturer_id (ctx)) < 0)
1282 {
1372 - fprintf (stderr,
1373 - "ipmi_monitoring_sel_read_manufacturer_id: %s\n",
1283 + error( "ipmi_monitoring_sel_read_manufacturer_id(): %s",
1284 ipmi_monitoring_ctx_errormsg (ctx));
1285 goto cleanup;
1286 }
@@ -1380,8 +1290,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1290
1291 if ((oem_data_len = ipmi_monitoring_sel_read_oem_data (ctx, oem_data, 1024)) < 0)
1292 {
1383 - fprintf (stderr,
1384 - "ipmi_monitoring_sel_read_oem_data: %s\n",
1293 + error( "ipmi_monitoring_sel_read_oem_data(): %s",
1294 ipmi_monitoring_ctx_errormsg (ctx));
1295 goto cleanup;
1296 }
@@ -1409,6 +1318,7 @@ _ipmimonitoring_sel (struct ipmi_monitoring_ipmi_config *ipmi_config)
1318 // MAIN PROGRAM FOR NETDATA PLUGIN
1319
1320 int ipmi_collect_data(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1321 + errno = 0;
1322
1323 if (_ipmimonitoring_sensors(ipmi_config) < 0) return -1;
1324 if (_ipmimonitoring_sel (ipmi_config) < 0) return -2;
@@ -1425,10 +1335,9 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1335
1336 // measure the time a data collection needs
1337 unsigned long long start = now_realtime_usec();
1428 - if(ipmi_collect_data(ipmi_config) < 0) {
1429 - fprintf(stderr, "freeipmi.plugin: data collection failed.\n");
1430 - exit(1);
1431 - }
1338 + if(ipmi_collect_data(ipmi_config) < 0)
1339 + fatal("freeipmi.plugin: data collection failed.");
1340 +
1341 unsigned long long end = now_realtime_usec();
1342
1343 if(debug) fprintf(stderr, "freeipmi.plugin: data collection speed was %llu usec\n", end - start);
@@ -1438,7 +1347,7 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1347
1348 // wait the same time
1349 // to avoid flooding the IPMI processor with requests
1441 - usleep(end - start);
1350 + sleep_usec(end - start);
1351 }
1352
1353 // so, we assume it needed 3x the time
@@ -1449,8 +1358,21 @@ int ipmi_detect_speed_secs(struct ipmi_monitoring_ipmi_config *ipmi_config) {
1358 }
1359
1360 int main (int argc, char **argv) {
1452 - struct ipmi_monitoring_ipmi_config ipmi_config;
1361
1362 + // ------------------------------------------------------------------------
1363 + // initialization of netdata plugin
1364 +
1365 + program_name = "freeipmi.plugin";
1366 +
1367 + // disable syslog
1368 + error_log_syslog = 0;
1369 +
1370 + // set errors flood protection to 100 logs per hour
1371 + error_log_errors_per_period = 100;
1372 + error_log_throttle_period = 3600;
1373 +
1374 +
1375 + // ------------------------------------------------------------------------
1376 // parse command line parameters
1377
1378 int i, freq = 0;
@@ -1467,86 +1389,127 @@ int main (int argc, char **argv) {
1389 debug = 1;
1390 continue;
1391 }
1392 + else if(strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
1393 + fprintf(stderr,
1394 + "\n"
1395 + "netdata freeipmi.plugin " VERSION "\n"
1396 + "Usage:\n"
1397 + "\n"
1398 + " freeipmi.plugin [OPTIONS]\n"
1399 + "\n"
1400 + "Available options:\n"
1401 + " NUMBER, sets the data collection frequency\n"
1402 + " debug, enables verbose output\n"
1403 + " hostname X, sets the remote host to connect to\n"
1404 + " username X, sets the username to authenticate at the remote host\n"
1405 + " password X, sets the password to authenticate at the remote host\n"
1406 + " sdr-cache-dir X, sets the directory to save SDR cache files\n"
1407 + " sensor-config-file X, set the filename to read sensor configuration\n"
1408 + );
1409 + exit(1);
1410 + }
1411 + else if(i < argc && strcmp("hostname", argv[i]) == 0) {
1412 + hostname = argv[++i];
1413 + if(debug) fprintf(stderr, "freeipmi.plugin: hostname set to '%s'\n", hostname);
1414 + continue;
1415 + }
1416 + else if(i < argc && strcmp("username", argv[i]) == 0) {
1417 + username = argv[++i];
1418 + if(debug) fprintf(stderr, "freeipmi.plugin: username set to '%s'\n", username);
1419 + continue;
1420 + }
1421 + else if(i < argc && strcmp("password", argv[i]) == 0) {
1422 + password = argv[++i];
1423 + if(debug) fprintf(stderr, "freeipmi.plugin: password set to '%s'\n", password);
1424 + continue;
1425 + }
1426 + else if(i < argc && strcmp("sdr-cache-dir", argv[i]) == 0) {
1427 + sdr_cache_directory = argv[++i];
1428 + if(debug) fprintf(stderr, "freeipmi.plugin: SDR cache directory set to '%s'\n", sdr_cache_directory);
1429 + continue;
1430 + }
1431 + else if(i < argc && strcmp("sensor-config-file", argv[i]) == 0) {
1432 + sensor_config_file = argv[++i];
1433 + if(debug) fprintf(stderr, "freeipmi.plugin: sensor config file set to '%s'\n", sensor_config_file);
1434 + continue;
1435 + }
1436
1471 - fprintf(stderr, "freeipmi.plugin: ignoring parameter '%s'\n", argv[i]);
1437 + error("freeipmi.plugin: ignoring parameter '%s'", argv[i]);
1438 }
1439
1440 if(freq > 0 && freq < netdata_update_every)
1441 netdata_update_every = freq;
1442
1443 else if(freq)
1478 - fprintf(stderr, "freeipmi.plugin: update frequency %d seconds is too small for IPMI. Using %d", freq, netdata_update_every);
1444 + error("update frequency %d seconds is too small for IPMI. Using %d.", freq, netdata_update_every);
1445
1446
1447 + // ------------------------------------------------------------------------
1448 // initialize IPMI
1449
1450 + struct ipmi_monitoring_ipmi_config ipmi_config;
1451 +
1452 if(debug) fprintf(stderr, "freeipmi.plugin: calling _init_ipmi_config()\n");
1453
1454 _init_ipmi_config(&ipmi_config);
1455
1456 if(debug) fprintf(stderr, "freeipmi.plugin: calling ipmi_monitoring_init()\n");
1457
1489 - if(ipmi_monitoring_init(ipmimonitoring_init_flags, &errnum) < 0) {
1490 - fprintf(stderr, "ipmi_monitoring_init: %s\n", ipmi_monitoring_ctx_strerror(errnum));
1491 - exit(1);
1492 - }
1458 + if(ipmi_monitoring_init(ipmimonitoring_init_flags, &errnum) < 0)
1459 + fatal("ipmi_monitoring_init: %s", ipmi_monitoring_ctx_strerror(errnum));
1460
1461 if(debug) fprintf(stderr, "freeipmi.plugin: detecting IPMI minimum update frequency...\n");
1462 freq = ipmi_detect_speed_secs(&ipmi_config);
1463 if(debug) fprintf(stderr, "freeipmi.plugin: IPMI minimum update frequency was calculated to %d seconds.\n", freq);
1464
1465 if(netdata_update_every < freq) {
1499 - fprintf(stderr, "freeipmi.plugin: enforcing minimum data collection frequency, calculated to %d seconds.\n", freq);
1466 + info("enforcing minimum data collection frequency, calculated to %d seconds.", freq);
1467 netdata_update_every = freq;
1468 }
1469
1470 +
1471 + // ------------------------------------------------------------------------
1472 // the main loop
1473 +
1474 if(debug) fprintf(stderr, "freeipmi.plugin: starting data collection\n");
1475
1476 + time_t started_t = now_monotonic_sec();
1477 +
1478 size_t iteration = 0;
1507 - unsigned long long step = netdata_update_every * 1000000ULL;
1508 - unsigned long long now = now_realtime_usec();
1509 - unsigned long long next = now - (now % step) + step;
1510 - while(1) {
1511 - unsigned long long last = now;
1512 - now = now_realtime_usec();
1479 + usec_t step = netdata_update_every * USEC_PER_SEC;
1480 +
1481 + heartbeat_t hb;
1482 + heartbeat_init(&hb);
1483 + for(iteration = 0; 1 ; iteration++) {
1484 + usec_t dt = heartbeat_next(&hb, step);
1485 +
1486 if(debug && iteration)
1487 fprintf(stderr, "freeipmi.plugin: iteration %zu, dt %llu usec, sensors collected %zu, sensors sent to netdata %zu \n"
1488 , iteration
1516 - , now - last
1489 + , dt
1490 , netdata_sensors_collected
1491 , netdata_sensors_updated
1492 );
1493
1521 - while(now < next) {
1522 - if(debug) fprintf(stderr, "freeipmi.plugin: sleeping for %llu usec\n", next - now);
1523 - usleep(next - now);
1524 - now = now_realtime_usec();
1525 - }
1526 - next = now - (now % step) + step;
1527 -
1494 netdata_mark_as_not_updated();
1495
1496 if(debug) fprintf(stderr, "freeipmi.plugin: calling ipmi_collect_data()\n");
1531 - if(ipmi_collect_data(&ipmi_config) < 0) {
1532 - fprintf(stderr, "freeipmi.plugin: data collection failed.\n");
1533 - exit(1);
1534 - }
1497 + if(ipmi_collect_data(&ipmi_config) < 0)
1498 + fatal("data collection failed.");
1499
1500 if(debug) fprintf(stderr, "freeipmi.plugin: calling send_metrics_to_netdata()\n");
1501 send_metrics_to_netdata();
1502 fflush(stdout);
1503
1540 - iteration++;
1504 + // restart check (14400 seconds)
1505 + if(now_monotonic_sec() - started_t > 14400) exit(0);
1506 }
1542 - exit(0);
1507 }
1508
1509 #else // !HAVE_FREEIPMI
1510
1511 int main(int argc, char **argv) {
1548 - fprintf(stderr, "freeipmi.plugin: not compiled.");
1549 - exit(1);
1512 + fatal("freeipmi.plugin is not compiled.");
1513 }
1514
1552 -#endif
1515 +#endif // !HAVE_FREEIPMI