diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-07-10 14:11:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-10 14:11:04 +0300 |
commit | eb6f1de7c6f7b626cb2ec333697b63034115914b (patch) | |
tree | a28fe8d5530573771df1d71cae66b32216d64289 | |
parent | ad85ae35b941b1c6cae17d6ad07a8f2f3116cdda (diff) |
multi-threaded version of freeipmi.plugin (#15327)
* multi-threaded version of freeipmi.plugin
* fix type check
* debug info
* debug info
* updated should be smaller, not bigger
* ignore sensors without name
* variable data collection frequencies for sensors and sel; also respect the min data collection frequency
* reorg and code cleanup
* collect states even for unknown units and empty names
* render all sensors
* reset unknown state sensors
* ignore sensors without name
* added component fan
* Update ipmi.conf
* added label type
* remove global state counters and chart
* updated copyright notice
* remove unused struct members
* remove unused variable
* added a log line everytime the plugin decides to exit to show what was wrong
* reworked freeipmi for optimal performance
* disabled debugging and fixed bug
* added debug
* added debug
* added debug
* removed debugging info
* cleanup and final touches
* let fan metrics be categorized by the component they are cooling
* added plugin and module to charts
* more component matches
* code cleanup, sel should now be a lot faster
* make sel min collection time 30 secs
* more component matches; refreshed functions copied from freeipmi codebase
* add keepalive to avoid parser read timeout during ipmi_detect_speed_secs
* ipmi.fan_speed => ipmi.sensor_fan_speed
* update metrics csv and readme
* ok newline
---------
Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
-rw-r--r-- | collectors/freeipmi.plugin/README.md | 141 | ||||
-rw-r--r-- | collectors/freeipmi.plugin/freeipmi_plugin.c | 2489 | ||||
-rw-r--r-- | collectors/freeipmi.plugin/metrics.csv | 18 | ||||
-rw-r--r-- | health/health.d/ipmi.conf | 10 | ||||
-rw-r--r-- | libnetdata/libnetdata.h | 26 |
5 files changed, 1395 insertions, 1289 deletions
diff --git a/collectors/freeipmi.plugin/README.md b/collectors/freeipmi.plugin/README.md index 47decd7ff7..65739f46a0 100644 --- a/collectors/freeipmi.plugin/README.md +++ b/collectors/freeipmi.plugin/README.md @@ -11,7 +11,10 @@ learn_rel_path: "Integrations/Monitor/Devices" Netdata has a [freeipmi](https://www.gnu.org/software/freeipmi/) plugin. -> FreeIPMI provides in-band and out-of-band IPMI software based on the IPMI v1.5/2.0 specification. The IPMI specification defines a set of interfaces for platform management and is implemented by a number vendors for system management. The features of IPMI that most users will be interested in are sensor monitoring, system event monitoring, power control, and serial-over-LAN (SOL). +> FreeIPMI provides in-band and out-of-band IPMI software based on the IPMI v1.5/2.0 specification. The IPMI +> specification defines a set of interfaces for platform management and is implemented by a number vendors for system +> management. The features of IPMI that most users will be interested in are sensor monitoring, system event monitoring, +> power control, and serial-over-LAN (SOL). ## Installing the FreeIPMI plugin @@ -22,7 +25,8 @@ installed automatically due to the large number of dependencies it requires. When using a static build of Netdata, the FreeIPMI plugin will be included and installed automatically, though you will still need to have FreeIPMI installed on your system to be able to use the plugin. -When using a local build of Netdata, you need to ensure that the FreeIPMI development packages (typically called `libipmimonitoring-dev`, `libipmimonitoring-devel`, or `freeipmi-devel`) are installed when building Netdata. +When using a local build of Netdata, you need to ensure that the FreeIPMI development packages (typically +called `libipmimonitoring-dev`, `libipmimonitoring-devel`, or `freeipmi-devel`) are installed when building Netdata. ### Special Considerations @@ -30,7 +34,9 @@ Accessing IPMI requires root access, so the FreeIPMI plugin is automatically ins FreeIPMI does not work correctly on IBM POWER systems, thus Netdata’s FreeIPMI plugin is not usable on such systems. -If you have not previously used IPMI on your system, you will probably need to run the `ipmimonitoring` command as root to initiailze IPMI settings so that the Netdata plugin works correctly. It should return information about available seensors on the system. +If you have not previously used IPMI on your system, you will probably need to run the `ipmimonitoring` command as root +to initiailze IPMI settings so that the Netdata plugin works correctly. It should return information about available +seensors on the system. In some distributions `libipmimonitoring.pc` is located in a non-standard directory, which can cause building the plugin to fail when building Netdata from source. In that case you @@ -38,37 +44,68 @@ should find the file and link it to the standard pkg-config directory. Usually, /usr/lib/$(uname -m)-linux-gnu/pkgconfig/libipmimonitoring.pc/libipmimonitoring.pc /usr/lib/pkgconfig/libipmimonitoring.pc` resolves this issue. -## Netdata use +## Metrics -The plugin creates (up to) 8 charts, based on the information collected from IPMI: +The plugin does a speed test when it starts, to find out the duration needed by the IPMI processor to respond. Depending +on the speed of your IPMI processor, charts may need several seconds to show up on the dashboard. -1. number of sensors by state -2. number of events in SEL -3. Temperatures CELSIUS -4. Temperatures FAHRENHEIT -5. Voltages -6. Currents -7. Power -8. Fans +Metrics grouped by *scope*. -It also adds 2 alarms: +The scope defines the instance that the metric belongs to. An instance is uniquely identified by a set of labels. -1. Sensors in non-nominal state (i.e. warning and critical) -2. SEL is non empty +### global -![image](https://cloud.githubusercontent.com/assets/2662304/23674138/88926a20-037d-11e7-89c0-20e74ee10cd1.png) +These metrics refer to the monitored host. -The plugin does a speed test when it starts, to find out the duration needed by the IPMI processor to respond. Depending on the speed of your IPMI processor, charts may need several seconds to show up on the dashboard. +This scope has no labels. -## `freeipmi.plugin` configuration +Metrics: + +| Metric | Dimensions | Unit | +|----------|:----------:|:------:| +| ipmi.sel | events | events | + +### sensor + +These metrics refer to the VPN user. + +Labels: + +| Label | Description | +|-----------|-----------------------------------------------------------------------------------------------------------------| +| sensor | Sensor name. Same value as the "Name" column in the `ipmi-sensors` output. | +| type | Sensor type. Same value as the "Type" column in the `ipmi-sensors` output. | +| component | General sensor component. Identified by Netdata based on sensor name and type (e.g. System, Processor, Memory). | + +Metrics: + +| Metric | Dimensions | Unit | +|-----------------------------|:-----------------------------------:|:----------:| +| ipmi.sensor_state | nominal, critical, warning, unknown | state | +| ipmi.sensor_temperature_c | temperature | Celsius | +| ipmi.sensor_temperature_f | temperature | Fahrenheit | +| ipmi.sensor_voltage | voltage | Volts | +| ipmi.sensor_ampere | ampere | Amps | +| ipmi.sensor_fan_speed | rotations | RPM | +| ipmi.sensor_power | power | Watts | +| ipmi.sensor_reading_percent | percentage | % | + +## Alarms + +There are 2 alarms: + +- The sensor is in a warning or critical state. +- System Event Log (SEL) is non-empty. + +## Configuration The plugin supports a few options. To see them, run: ```text -# /usr/libexec/netdata/plugins.d/freeipmi.plugin -h +# ./freeipmi.plugin --help - netdata freeipmi.plugin 1.8.0-546-g72ce5d6b_rolling - Copyright (C) 2016-2017 Costa Tsaousis <costa@tsaousis.gr> + netdata freeipmi.plugin v1.40.0-137-gf162c25bd + Copyright (C) 2023 Netdata Inc. Released under GNU General Public License v3 or later. All rights reserved. @@ -86,17 +123,49 @@ The plugin supports a few options. To see them, run: no-sel enable/disable SEL collection default: enabled + reread-sdr-cache re-read SDR cache on every iteration + default: disabled + + interpret-oem-data attempt to parse OEM data + default: disabled + + assume-system-event-record + tread illegal SEL events records as normal + default: disabled + + ignore-non-interpretable-sensors + do not read sensors that cannot be interpreted + default: disabled + + bridge-sensors bridge sensors not owned by the BMC + default: disabled + + shared-sensors enable shared sensors, if found + default: disabled + + no-discrete-reading do not read sensors that their event/reading type code is invalid + default: enabled + + ignore-scanning-disabled + Ignore the scanning bit and read sensors no matter what + default: disabled + + assume-bmc-owner assume the BMC is the sensor owner no matter what + (usually bridging is required too) + default: disabled + hostname HOST username USER password PASS connect to remote IPMI host default: local IPMI processor + no-auth-code-check noauthcodecheck don't check the authentication codes returned - driver-type IPMIDRIVER - Specify the driver type to use instead of doing an auto selection. - The currently available outofband drivers are LAN and LAN_2_0, - which perform IPMI 1.5 and IPMI 2.0 respectively. + driver-type IPMIDRIVER + Specify the driver type to use instead of doing an auto selection. + The currently available outofband drivers are LAN and LAN_2_0, + which perform IPMI 1.5 and IPMI 2.0 respectively. The currently available inband drivers are KCS, SSIF, OPENIPMI and SUNBMC. sdr-cache-dir PATH directory for SDR cache files @@ -105,9 +174,15 @@ The plugin supports a few options. To see them, run: sensor-config-file FILE filename to read sensor configuration default: system default + sel-config-file FILE filename to read sel configuration + default: system default + ignore N1,N2,N3,... sensor IDs to ignore default: none + ignore-status N1,N2,N3,... sensor IDs to ignore status (nominal/warning/critical) + default: none + -v -V version print version and exit @@ -131,13 +206,17 @@ You can set these options in `/etc/netdata/netdata.conf` at this section: command options = ``` -Append to `command options =` the settings you need. The minimum `update every` is 5 (enforced internally by the plugin). IPMI is slow and CPU hungry. So, once every 5 seconds is pretty acceptable. +Append to `command options =` the settings you need. The minimum `update every` is 5 (enforced internally by the +plugin). IPMI is slow and CPU hungry. So, once every 5 seconds is pretty acceptable. ## Ignoring specific sensors -Specific sensor IDs can be excluded from freeipmi tools by editing `/etc/freeipmi/freeipmi.conf` and setting the IDs to be ignored at `ipmi-sensors-exclude-record-ids`. **However this file is not used by `libipmimonitoring`** (the library used by Netdata's `freeipmi.plugin`). +Specific sensor IDs can be excluded from freeipmi tools by editing `/etc/freeipmi/freeipmi.conf` and setting the IDs to +be ignored at `ipmi-sensors-exclude-record-ids`. **However this file is not used by `libipmimonitoring`** (the library +used by Netdata's `freeipmi.plugin`). -So, `freeipmi.plugin` supports the option `ignore` that accepts a comma separated list of sensor IDs to ignore. To configure it, edit `/etc/netdata/netdata.conf` and set: +So, `freeipmi.plugin` supports the option `ignore` that accepts a comma separated list of sensor IDs to ignore. To +configure it, edit `/etc/netdata/netdata.conf` and set: ``` [plugin:freeipmi] @@ -196,7 +275,9 @@ You can also permanently set the above setting by creating the file `/etc/modpro options ipmi_si kipmid_max_busy_us=10 ``` -This instructs the kernel IPMI module to pause for a tick between checking IPMI. Querying IPMI will be a lot slower now (e.g. several seconds for IPMI to respond), but `kipmi` will not use any noticeable CPU. You can also use a higher number (this is the number of microseconds to poll IPMI for a response, before waiting for a tick). +This instructs the kernel IPMI module to pause for a tick between checking IPMI. Querying IPMI will be a lot slower +now (e.g. several seconds for IPMI to respond), but `kipmi` will not use any noticeable CPU. You can also use a higher +number (this is the number of microseconds to poll IPMI for a response, before waiting for a tick). If you need to disable IPMI for Netdata, edit `/etc/netdata/netdata.conf` and set: diff --git a/collectors/freeipmi.plugin/freeipmi_plugin.c b/collectors/freeipmi.plugin/freeipmi_plugin.c index a2251891ae..edc7d28ebf 100644 --- a/collectors/freeipmi.plugin/freeipmi_plugin.c +++ b/collectors/freeipmi.plugin/freeipmi_plugin.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later /* * netdata freeipmi.plugin - * Copyright (C) 2017 Costa Tsaousis + * Copyright (C) 2023 Netdata Inc. * GPL v3+ * * Based on: @@ -15,9 +15,59 @@ * UCRL-CODE-222073 */ +// ---------------------------------------------------------------------------- +// BEGIN NETDATA CODE + +// #define NETDATA_TIMING_REPORT 1 #include "libnetdata/libnetdata.h" #include "libnetdata/required_dummies.h" +// component names, based on our patterns +#define NETDATA_SENSOR_COMPONENT_MEMORY_MODULE "Memory Module" +#define NETDATA_SENSOR_COMPONENT_MEMORY "Memory" +#define NETDATA_SENSOR_COMPONENT_PROCESSOR "Processor" +#define NETDATA_SENSOR_COMPONENT_IPU "Image Processor" +#define NETDATA_SENSOR_COMPONENT_STORAGE "Storage" +#define NETDATA_SENSOR_COMPONENT_MOTHERBOARD "Motherboard" +#define NETDATA_SENSOR_COMPONENT_NETWORK "Network" +#define NETDATA_SENSOR_COMPONENT_POWER_SUPPLY "Power Supply" +#define NETDATA_SENSOR_COMPONENT_SYSTEM "System" +#define NETDATA_SENSOR_COMPONENT_PERIPHERAL "Peripheral" + +// netdata plugin defaults +#define SENSORS_DICT_KEY_SIZE 2048 // the max size of the key for the dictionary of sensors +#define SPEED_TEST_ITERATIONS 5 // how many times to repeat data collection to decide latency +#define IPMI_SENSORS_DASHBOARD_PRIORITY 90000 // the priority of the sensors charts on the dashboard +#define IPMI_SEL_DASHBOARD_PRIORITY 99000 // the priority of the SEL events chart on the dashboard +#define IPMI_SENSORS_MIN_UPDATE_EVERY 5 // the minimum data collection frequency for sensors +#define IPMI_SEL_MIN_UPDATE_EVERY 30 // the minimum data collection frequency for SEL events +#define IPMI_ENABLE_SEL_BY_DEFAULT true // true/false, to enable/disable SEL by default +#define IPMI_RESTART_EVERY_SECONDS 14400 // restart the plugin every this many seconds + // this is to prevent possible bugs/leaks in ipmi libraries +#define IPMI_RESTART_IF_SENSORS_DONT_ITERATE_EVERY_SECONDS (10 * 60) // stale data collection detection time + +// forward definition of functions and structures +struct netdata_ipmi_state; +static void netdata_update_ipmi_sensor_reading( + int record_id + , int sensor_number + , int sensor_type + , int sensor_state + , int sensor_units + , int sensor_reading_type + , char *sensor_name + , void *sensor_reading + , int event_reading_type_code + , int sensor_bitmask_type + , int sensor_bitmask + , char **sensor_bitmask_strings + , struct netdata_ipmi_state *state +); +static void netdata_update_ipmi_sel_events_count(struct netdata_ipmi_state *state, uint32_t events); + +// END NETDATA CODE +// ---------------------------------------------------------------------------- + #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -27,22 +77,9 @@ #include <unistd.h> #include <sys/time.h> -#define IPMI_PARSE_DEVICE_LAN_STR "lan" -#define IPMI_PARSE_DEVICE_LAN_2_0_STR "lan_2_0" -#define IPMI_PARSE_DEVICE_LAN_2_0_STR2 "lan20" -#define IPMI_PARSE_DEVICE_LAN_2_0_STR3 "lan_20" -#define IPMI_PARSE_DEVICE_LAN_2_0_STR4 "lan2_0" -#define IPMI_PARSE_DEVICE_LAN_2_0_STR5 "lanplus" -#define IPMI_PARSE_DEVICE_KCS_STR "kcs" -#define IPMI_PARSE_DEVICE_SSIF_STR "ssif" -#define IPMI_PARSE_DEVICE_OPENIPMI_STR "openipmi" -#define IPMI_PARSE_DEVICE_OPENIPMI_STR2 "open" -#define IPMI_PARSE_DEVICE_SUNBMC_STR "sunbmc" -#define IPMI_PARSE_DEVICE_SUNBMC_STR2 "bmc" -#define IPMI_PARSE_DEVICE_INTELDCMI_STR "inteldcmi" - #include <ipmi_monitoring.h> #include <ipmi_monitoring_bitmasks.h> +#include <ipmi_monitoring_offsets.h> /* Communication Configuration - Initialize accordingly */ @@ -50,53 +87,35 @@ char *hostname = NULL; /* In-band Communication Configuration */ -int driver_type = -1; // IPMI_MONITORING_DRIVER_TYPE_KCS; /* or -1 for default */ -int disable_auto_probe = 0; /* probe for in-band device */ -unsigned int driver_address = 0; /* not used if probing */ -unsigned int register_spacing = 0; /* not used if probing */ -char *driver_device = NULL; /* not used if probing */ +int driver_type = -1; // IPMI_MONITORING_DRIVER_TYPE_KCS, etc. or -1 for default +int disable_auto_probe = 0; /* probe for in-band device */ +unsigned int driver_address = 0; /* not used if probing */ +unsigned int register_spacing = 0; /* not used if probing */ +char *driver_device = NULL; /* not used if probing */ /* Out-of-band Communication Configuration */ -int protocol_version = -1; //IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */ -char *username = "foousername"; -char *password = "foopassword"; -unsigned char *ipmi_k_g = NULL; -unsigned int ipmi_k_g_len = 0; -int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */ -int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */ -int cipher_suite_id = 0; /* or -1 for default */ +int protocol_version = -1; // IPMI_MONITORING_PROTOCOL_VERSION_1_5, etc. or -1 for default +char *username = ""; +char *password = ""; +unsigned char *k_g = NULL; +unsigned int k_g_len = 0; +int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER, etc. or -1 for default +int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5, etc. or -1 for default +int cipher_suite_id = -1; /* 0 or -1 for default */ int session_timeout = 0; /* 0 for default */ int retransmission_timeout = 0; /* 0 for default */ /* Workarounds - specify workaround flags if necessary */ unsigned int workaround_flags = 0; -/* Initialize w/ record id numbers to only monitor specific record ids */ -unsigned int record_ids[] = {0}; -unsigned int record_ids_length = 0; - -/* Initialize w/ sensor types to only monitor specific sensor types - * see ipmi_monitoring.h sensor types list. - */ -unsigned int sensor_types[] = {0}; -unsigned int sensor_types_length = 0; - /* Set to an appropriate alternate if desired */ char *sdr_cache_directory = "/tmp"; char *sensor_config_file = NULL; +char *sel_config_file = NULL; -/* Set to 1 or 0 to enable these sensor reading flags - * - See ipmi_monitoring.h for descriptions of these flags. - */ -int reread_sdr_cache = 0; -int ignore_non_interpretable_sensors = 0; -int bridge_sensors = 0; -int interpret_oem_data = 0; -int shared_sensors = 0; -int discrete_reading = 1; -int ignore_scanning_disabled = 0; -int assume_bmc_owner = 0; -int entity_sensor_names = 0; +// controlled via command line options +unsigned int global_sel_flags = 0; +unsigned int global_sensor_reading_flags = IPMI_MONITORING_SENSOR_READING_FLAGS_DISCRETE_READING; /* Initialization flags * @@ -106,26 +125,10 @@ int entity_sensor_names = 0; */ unsigned int ipmimonitoring_init_flags = 0; -int errnum; - -// ---------------------------------------------------------------------------- -// SEL only variables - -/* Initialize w/ date range to only monitoring specific date range */ -char *date_begin = NULL; /* use MM/DD/YYYY format */ -char *date_end = NULL; /* use MM/DD/YYYY format */ - -int assume_system_event_record = 0; - -char *sel_config_file = NULL; - - // ---------------------------------------------------------------------------- // functions common to sensors and SEL -static void -_init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) -{ +static void initialize_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) { fatal_assert(ipmi_config); ipmi_config->driver_type = driver_type; @@ -137,8 +140,8 @@ _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) ipmi_config->protocol_version = protocol_version; ipmi_config->username = username; ipmi_config->password = password; - ipmi_config->k_g = ipmi_k_g; - ipmi_config->k_g_len = ipmi_k_g_len; + ipmi_config->k_g = k_g; + ipmi_config->k_g_len = k_g_len; ipmi_config->privilege_level = privilege_level; ipmi_config->authentication_type = authentication_type; ipmi_config->cipher_suite_id = cipher_suite_id; @@ -148,414 +151,549 @@ _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) ipmi_config->workaround_flags = workaround_flags; } -#ifdef NETDATA_COMMENTED -static const char * -_get_sensor_type_string (int sensor_type) -{ - switch (sensor_type) - { +static const char *netdata_ipmi_get_sensor_type_string (int sensor_type, const char **component) { + switch (sensor_type) { case IPMI_MONITORING_SENSOR_TYPE_RESERVED: return ("Reserved"); + case IPMI_MONITORING_SENSOR_TYPE_TEMPERATURE: return ("Temperature"); + case IPMI_MONITORING_SENSOR_TYPE_VOLTAGE: return ("Voltage"); + case IPMI_MONITORING_SENSOR_TYPE_CURRENT: return ("Current"); + case IPMI_MONITORING_SENSOR_TYPE_FAN: return ("Fan"); + case IPMI_MONITORING_SENSOR_TYPE_PHYSICAL_SECURITY: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Physical Security"); + case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_SECURITY_VIOLATION_ATTEMPT: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Platform Security Violation Attempt"); + case IPMI_MONITORING_SENSOR_TYPE_PROCESSOR: + *component = NETDATA_SENSOR_COMPONENT_PROCESSOR; return ("Processor"); + case IPMI_MONITORING_SENSOR_TYPE_POWER_SUPPLY: + *component = NETDATA_SENSOR_COMPONENT_POWER_SUPPLY; return ("Power Supply"); + case IPMI_MONITORING_SENSOR_TYPE_POWER_UNIT: + *component = NETDATA_SENSOR_COMPONENT_POWER_SUPPLY; return ("Power Unit"); + case IPMI_MONITORING_SENSOR_TYPE_COOLING_DEVICE: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Cooling Device"); + case IPMI_MONITORING_SENSOR_TYPE_OTHER_UNITS_BASED_SENSOR: return ("Other Units Based Sensor"); + case IPMI_MONITORING_SENSOR_TYPE_MEMORY: + *component = NETDATA_SENSOR_COMPONENT_MEMORY; return ("Memory"); + case IPMI_MONITORING_SENSOR_TYPE_DRIVE_SLOT: + *component = NETDATA_SENSOR_COMPONENT_STORAGE; return ("Drive Slot"); + case IPMI_MONITORING_SENSOR_TYPE_POST_MEMORY_RESIZE: + *component = NETDATA_SENSOR_COMPONENT_MEMORY; return ("POST Memory Resize"); + case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_FIRMWARE_PROGRESS: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("System Firmware Progress"); + case IPMI_MONITORING_SENSOR_TYPE_EVENT_LOGGING_DISABLED: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Event Logging Disabled"); + case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG1: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Watchdog 1"); + case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_EVENT: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("System Event"); + case IPMI_MONITORING_SENSOR_TYPE_CRITICAL_INTERRUPT: return ("Critical Interrupt"); + case IPMI_MONITORING_SENSOR_TYPE_BUTTON_SWITCH: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Button/Switch"); + case IPMI_MONITORING_SENSOR_TYPE_MODULE_BOARD: return ("Module/Board"); + case IPMI_MONITORING_SENSOR_TYPE_MICROCONTROLLER_COPROCESSOR: + *component = NETDATA_SENSOR_COMPONENT_PROCESSOR; return ("Microcontroller/Coprocessor"); + case IPMI_MONITORING_SENSOR_TYPE_ADD_IN_CARD: return ("Add In Card"); + case IPMI_MONITORING_SENSOR_TYPE_CHASSIS: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Chassis"); + case IPMI_MONITORING_SENSOR_TYPE_CHIP_SET: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Chip Set"); + case IPMI_MONITORING_SENSOR_TYPE_OTHER_FRU: return ("Other Fru"); + case IPMI_MONITORING_SENSOR_TYPE_CABLE_INTERCONNECT: return ("Cable/Interconnect"); + case IPMI_MONITORING_SENSOR_TYPE_TERMINATOR: return ("Terminator"); + case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_BOOT_INITIATED: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("System Boot Initiated"); + case IPMI_MONITORING_SENSOR_TYPE_BOOT_ERROR: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Boot Error"); + case IPMI_MONITORING_SENSOR_TYPE_OS_BOOT: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("OS Boot"); + case IPMI_MONITORING_SENSOR_TYPE_OS_CRITICAL_STOP: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("OS Critical Stop"); + case IPMI_MONITORING_SENSOR_TYPE_SLOT_CONNECTOR: return ("Slot/Connector"); + case IPMI_MONITORING_SENSOR_TYPE_SYSTEM_ACPI_POWER_STATE: return ("System ACPI Power State"); + case IPMI_MONITORING_SENSOR_TYPE_WATCHDOG2: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Watchdog 2"); + case IPMI_MONITORING_SENSOR_TYPE_PLATFORM_ALERT: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Platform Alert"); + case IPMI_MONITORING_SENSOR_TYPE_ENTITY_PRESENCE: return ("Entity Presence"); + case IPMI_MONITORING_SENSOR_TYPE_MONITOR_ASIC_IC: return ("Monitor ASIC/IC"); + case IPMI_MONITORING_SENSOR_TYPE_LAN: + *component = NETDATA_SENSOR_COMPONENT_NETWORK; return ("LAN"); + case IPMI_MONITORING_SENSOR_TYPE_MANAGEMENT_SUBSYSTEM_HEALTH: + *component = NETDATA_SENSOR_COMPONENT_SYSTEM; return ("Management Subsystem Health"); + case IPMI_MONITORING_SENSOR_TYPE_BATTERY: return ("Battery"); + case IPMI_MONITORING_SENSOR_TYPE_SESSION_AUDIT: return ("Session Audit"); + case IPMI_MONITORING_SENSOR_TYPE_VERSION_CHANGE: return ("Version Change"); + case IPMI_MONITORING_SENSOR_TYPE_FRU_STATE: return ("FRU State"); - } - - return ("Unrecognized"); -} -#endif // NETDATA_COMMENTED + case IPMI_MONITORING_SENSOR_TYPE_UNKNOWN: + return ("Unknown"); -// ---------------------------------------------------------------------------- -// BEGIN NETDATA CODE + default: + if(sensor_type >= IPMI_MONITORING_SENSOR_TYPE_OEM_MIN && sensor_type <= IPMI_MONITORING_SENSOR_TYPE_OEM_MAX) + return ("OEM"); -static int debug = 0; + return ("Unrecognized"); + } +} -static int netdata_update_every = 5; // this is the minimum update frequency -static int netdata_priority = 90000; -static int netdata_do_sel = 1; +#define netdata_ipmi_get_value_int(var, func, ctx) do { \ + (var) = func(ctx); \ + if( (var) < 0) { \ + collector_error("%s(): call to " #func " failed: %s", \ + __FUNCTION__, ipmi_monitoring_ctx_errormsg(ctx)); \ + goto cleanup; \ + } \ + timing_step(TIMING_STEP_FREEIPMI_READ_ ## var); \ +} while(0) + +#define netdata_ipmi_get_value_ptr(var, func, ctx) do { \ + (var) = func(ctx); \ + if(!(var)) { \ + collector_error("%s(): call to " #func " failed: %s", \ + __FUNCTION__, ipmi_monitoring_ctx_errormsg(ctx)); \ + goto cleanup; \ + } \ + timing_step(TIMING_STEP_FREEIPMI_READ_ ## var); \ +} while(0) + +#define netdata_ipmi_get_value_no_check(var, func, ctx) do { \ + (var) = func(ctx); \ + timing_step(TIMING_STEP_FREEIPMI_READ_ ## var); \ +} while(0) + +static int netdata_read_ipmi_sensors(struct ipmi_monitoring_ipmi_config *ipmi_config, struct netdata_ipmi_state *state) { + timing_init(); -static size_t netdata_sensors_updated = 0; -static size_t netdata_sensors_collected = 0; -static size_t netdata_sel_events = 0; -static size_t netdata_sensors_states_nominal = 0; -static size_t netdata_sensors_states_warning = 0; -static size_t netdata_sensors_states_critical = 0; + ipmi_monitoring_ctx_t ctx = NULL; + unsigned int sensor_reading_flags = global_sensor_reading_flags; + int i; + int sensor_count; + int rv = -1; -struct sensor { - int record_id; - int sensor_number; - int sensor_type; - int sensor_state; - int sensor_units; - char *sensor_name; + if (!(ctx = ipmi_monitoring_ctx_create ())) { + collector_error("ipmi_monitoring_ctx_create()"); + goto cleanup; + } - int sensor_reading_type; - union { - uint8_t bool_value; - uint32_t uint32_value; - double double_value; - } sensor_reading; + timing_step(TIMING_STEP_FREEIPMI_CTX_CREATE); - int sent; - int ignore; - int exposed; - int updated; - struct sensor *next; -} *sensors_root = NULL; + if (sdr_cache_directory) { + if (ipmi_monitoring_ctx_sdr_cache_directory (ctx, sdr_cache_directory) < 0) { + collector_error("ipmi_monitoring_ctx_sdr_cache_directory(): %s\n", ipmi_monitoring_ctx_errormsg (ctx)); + goto cleanup; + } + } -static void netdata_mark_as_not_updated() { - struct sensor *sn; - for(sn = sensors_root; sn ;sn = sn->next) - sn->updated = sn->sent = 0; + timing_step(TIMING_STEP_FREEIPMI_DSR_CACHE_DIR); - netdata_sensors_updated = 0; - netdata_sensors_collected = 0; - netdata_sel_events = 0; + // Must call otherwise only default interpretations ever used + // sensor_config_file can be NULL + if (ipmi_monitoring_ctx_sensor_config_file (ctx, sensor_config_file) < 0) { + collector_error( "ipmi_monitoring_ctx_sensor_config_file(): %s\n", ipmi_monitoring_ctx_errormsg (ctx)); + goto cleanup; + } - netdata_sensors_states_nominal = 0; - netdata_sensors_states_warning = 0; - netdata_sensors_states_critical = 0; -} + timing_step(TIMING_STEP_FREEIPMI_SENSOR_CONFIG_FILE); + + if ((sensor_count = ipmi_monitoring_sensor_readings_by_record_id (ctx, + hostname, + ipmi_config, + sensor_reading_flags, + NULL, + 0, + NULL, + NULL)) < 0) { + collector_error( "ipmi_monitoring_sensor_readings_by_record_id(): %s", + ipmi_monitoring_ctx_errormsg (ctx)); + goto cleanup; + } -static void send_chart_to_netdata_for_units(int units) { - struct sensor *sn, *sn_stored; - int dupfound, multiplier; + timing_step(TIMING_STEP_FREEIPMI_SENSOR_READINGS_BY_X); - switch(units) { - case IPMI_MONITORING_SENSOR_UNITS_CELSIUS: - printf("CHART ipmi.temperatures_c '' 'System Celsius Temperatures read by IPMI' 'Celsius' 'temperatures' 'ipmi.temperatures_c' 'line' %d %d\n" - , netdata_priority + 10 - , netdata_update_every - ); - break; + for (i = 0; i < sensor_count; i++, ipmi_monitoring_sensor_iterator_next (ctx)) { + int record_id, sensor_number, sensor_type, sensor_state, sensor_units, + sensor_bitmask_type, sensor_bitmask, event_reading_type_code, sensor_reading_type; - case IPMI_MONITORING_SENSOR_UNITS_FAHRENHEIT: - printf("CHART ipmi.temperatures_f '' 'System Fahrenheit Temperatures read by IPMI' 'Fahrenheit' 'temperatures' 'ipmi.temperatures_f' 'line' %d %d\n" - , netdata_priority + 11 - , netdata_update_every - ); - break; + char **sensor_bitmask_strings = NULL; + char *sensor_name = NULL; + void *sensor_reading; - case IPMI_MONITORING_SENSOR_UNITS_VOLTS: - printf("CHART ipmi.volts '' 'System Voltages read by IPMI' 'Volts' 'voltages' 'ipmi.voltages' 'line' %d %d\n" - , netdata_priority + 12 - , netdata_update_every - ); - break; + netdata_ipmi_get_value_int(record_id, ipmi_monitoring_sensor_read_record_id, ctx); + netdata_ipmi_get_value_int(sensor_number, ipmi_monitoring_sensor_read_sensor_number, ctx); + netdata_ipmi_get_value_int(sensor_type, ipmi_monitoring_sensor_read_sensor_type, ctx); + netdata_ipmi_get_value_ptr(sensor_name, ipmi_monitoring_sensor_read_sensor_name, ctx); + netdata_ipmi_get_value_int(sensor_state, ipmi_monitoring_sensor_read_sensor_state, ctx); + netdata_ipmi_get_value_int(sensor_units, ipmi_monitoring_sensor_read_sensor_units, ctx); + netdata_ipmi_get_value_int(sensor_bitmask_type, ipmi_monitoring_sensor_read_sensor_bitmask_type, ctx); + netdata_ipmi_get_value_int(sensor_bitmask, ipmi_monitoring_sensor_read_sensor_bitmask, ctx); + // it's ok for this to be NULL, i.e. sensor_bitmask == IPMI_MONITORING_SENSOR_BITMASK_TYPE_UNKNOWN + netdata_ipmi_get_value_no_check(sensor_bitmask_strings, ipmi_monitoring_sensor_read_sensor_bitmask_strings, ctx); + netdata_ipmi_get_value_int(sensor_reading_type, ipmi_monitoring_sensor_read_sensor_reading_type, ctx); + // whatever we read from the sensor, it is ok + netdata_ipmi_get_value_no_check(sensor_reading, ipmi_monitoring_sensor_read_sensor_reading, ctx); + netdata_ipmi_get_value_int(event_reading_type_code, ipmi_monitoring_sensor_read_event_reading_type_code, ctx); + + netdata_update_ipmi_sensor_reading( + record_id, sensor_number, sensor_type, sensor_state, sensor_units, sensor_reading_type, sensor_name, + sensor_reading, event_reading_type_code, sensor_bitmask_type, sensor_bitmask, sensor_bitmask_strings, + state + ); - case IPMI_MONITORING_SENSOR_UNITS_AMPS: - printf("CHART ipmi.amps '' 'System Current read by IPMI' 'Amps' 'current' 'ipmi.amps' 'line' %d %d\n" - , netdata_priority + 13 - , netdata_update_every - ); - break; +#ifdef NETDATA_COMMENTED + /* It is possible you may want to monitor specific event + * conditions that may occu |