ROFL-pipeline  v0.6.0dev
monitoring.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
13 #ifndef __MONITORING_H__
14 #define __MONITORING_H__
15 
16 #include <rofl.h>
17 #include <stdbool.h>
18 #include <inttypes.h>
19 #include <time.h>
20 #include "platform/lock.h"
21 
22 //fwd decl
23 struct monitored_entity;
24 
30  SENSOR_DATA_T_OHTER=1, //a measure other than those listed below
31  SENSOR_DATA_T_UNKNOWN=2, //unknown measurement, or arbitrary, relative numbers
32  SENSOR_DATA_T_VOLTS_AC=3, //electric potential
33  SENSOR_DATA_T_VOLTS_DC=4, //electric potential
34  SENSOR_DATA_T_AMPERES=5, //electric current
35  SENSOR_DATA_T_WATTS=6, //power
36  SENSOR_DATA_T_HERTZ=7, //frequency
37  SENSOR_DATA_T_CELSIUS=8, //temperature
38  SENSOR_DATA_T_PERCENTRH=9, //percent relative humidity
39  SENSOR_DATA_T_RPM=10, //shaft revolutions per minute
40  SENSOR_DATA_T_CMM=11, //cubic meters per minute (airflow)
41  SENSOR_DATA_T_TRUTH_VALUE=12 //value takes { true(1), false(2) }
42 };
43 
49  SENSOR_DATA_S_YOCTO=1, //10^-24
50  SENSOR_DATA_S_ZEPTO=2, //10^-21
51  SENSOR_DATA_S_ATTO=3, //10^-18
52  SENSOR_DATA_S_FEMTO=4, //10^-15
53  SENSOR_DATA_S_PICO=5, //10^-12
54  SENSOR_DATA_S_NANO=6, //10^-9
55  SENSOR_DATA_S_MICRO=7, //10^-6
56  SENSOR_DATA_S_MILLI=8, //10^-3
57  SENSOR_DATA_S_UNITS=9, //10^0
58  SENSOR_DATA_S_KILO=10, //10^3
59  SENSOR_DATA_S_MEGA=11, //10^6
60  SENSOR_DATA_S_GIGA=12, //10^9
61  SENSOR_DATA_S_TERA=13, //10^12
62  SENSOR_DATA_S_EXA=14, //10^15
63  SENSOR_DATA_S_PETA=15, //10^18
64  SENSOR_DATA_S_ZETTA=16, //10^21
65  SENSOR_DATA_S_YOTTA=17 //10^24
66 };
67 
73  SENSOR_DATA_OS_OK=1,
74  SENSOR_DATA_OS_UNAVAILABLE=2,
75  SENSOR_DATA_OS_NONOPERATIONAL=3,
76 };
77 
82 typedef struct sensor_data{
83  enum sensor_data_type type;
84  enum sensor_data_scale scale;
85  unsigned int precision;
86  double value;
87  enum sensor_data_oper_status operational_status;
88  unsigned int unitsdisplay;
89  time_t value_timestamp;
90  unsigned int value_update_rate;
92 
93 
99  ME_TYPE_OTHER=1,
100  ME_TYPE_UNKNOWN=2,
101  ME_TYPE_CHASSIS=3,
102  ME_TYPE_BACKPLANE=4,
103  ME_TYPE_CONTAINER=5,
104  ME_TYPE_POWER_SUPPLY=6,
105  ME_TYPE_FAN=7,
106  ME_TYPE_SENSOR=8,
107  ME_TYPE_MODULE=9,
108  ME_TYPE_PORT=10,
109  ME_TYPE_STACK=11
110 };
111 
116 #define MONITORED_ENTITY_MAX_SENSOR_DATA 8
117 
124 typedef struct monitored_entity{
125 
126  //Type
127  enum monitored_entity_type type;
128 
129  //Data
130  unsigned int physical_index;
131  char* description;
132  char* vendor_type;
133  char* class_type;
134  char* name;
135  char* hardware_rev;
136  char* firmware_rev;
137  char* software_rev;
138  char* serial_num;
139  char* manufacturer_model_name;
140  char* model_name;
141  char* alias;
142  char* asset_id;
143  bool is_field_replaceable_unit;
144 
145  //Sensor
147 
148  /*
149  * Navigational elements
150  */
151 
152  //Parent
153  struct monitored_entity* parent;
154 
155  //Inner elements
156  struct monitored_entity* inner;
157 
158  //double-linked list
159  struct monitored_entity* prev;
160  struct monitored_entity* next;
162 
163 
168 typedef struct monitoring_state{
169 
170  //Reusing the same struct for the snapshot
171  bool is_snapshot;
172 
173  //Simple counter which mantains
174  //the version of the monitored data
175  //Useful to avoid snapshots
176  uint64_t last_rev; //1->2...
177 
178  //Main chassis monitored entity(root)
179  monitored_entity_t chassis;
180 
181  /*
182  * Protects state while creating snapshots
183  * Should be acquired in WRITE mode when updating
184  * information. READ mode should only be used while
185  * creating snapshots
186  */
187  platform_rwlock_t* rwlock;
188 
189  //Not used at all (except for platform_atomic_inc64())
190  platform_mutex_t* mutex;
192 
193 //Alias
195 
196 //C++ extern C
197 ROFL_BEGIN_DECLS
198 
199 //Monitoring API
200 
204 rofl_result_t __monitoring_init(monitoring_state_t* monitoring);
205 
210 void monitoring_dump(monitoring_state_t* monitoring);
211 
217  return monitoring_dump(snapshot);
218 }
219 
220 //Destroys the monitoring state
221 void __monitoring_destroy(monitoring_state_t* monitoring);
222 
227 static inline bool monitoring_has_changed(monitoring_state_t* state, uint64_t* last_seen_rev){
228  return *last_seen_rev != state->last_rev;
229 }
230 
243 
249  return monitoring_get_snapshot(orig);
250 }
251 
257  __monitoring_destroy((monitoring_state_t*)snapshot);
258 }
259 
266 
267 
268 //fwd declaration
269 rofl_result_t __monitoring_remove_monitored_entity(monitoring_state_t* monitoring, monitored_entity_t* entity, bool lock_acquired);
275 static inline rofl_result_t monitoring_remove_monitored_entity(monitoring_state_t* monitoring, monitored_entity_t* entity){
276  return __monitoring_remove_monitored_entity(monitoring, entity, false);
277 }
278 
279 //C++ extern C
280 ROFL_END_DECLS
281 
282 #endif //MONITORING
static monitoring_snapshot_state_t * monitoring_clone_snapshot(monitoring_snapshot_state_t *orig)
Clone a monitoring snapshot.
Definition: monitoring.h:248
Defines the locking interface used by the library. The user of the library MUST provide an implementa...
monitoring_snapshot_state_t * monitoring_get_snapshot(monitoring_state_t *monitoring)
Get a snapshot of the current monitoring state.
Definition: monitoring.c:343
struct monitoring_state monitoring_state_t
Container of the monitoring state.
static bool monitoring_has_changed(monitoring_state_t *state, uint64_t *last_seen_rev)
Returns true if the monitoring state has changed.
Definition: monitoring.h:227
static void monitoring_destroy_snapshot(monitoring_snapshot_state_t *snapshot)
Destroy a snapshot previously generated via monitoring_get_snapshot() routine.
Definition: monitoring.h:256
sensor_data_scale
Sensor data scale.
Definition: monitoring.h:48
Container of the monitoring state.
Definition: monitoring.h:168
sensor_data_type
Sensor data type.
Definition: monitoring.h:29
sensor_data_oper_status
Sensor data operational status.
Definition: monitoring.h:72
static void monitoring_dump_snapshot(monitoring_snapshot_state_t *snapshot)
Dumps the monitoring state of a snapshot.
Definition: monitoring.h:216
struct sensor_data sensor_data_t
Sensor data information.
void monitoring_dump(monitoring_state_t *monitoring)
Dumps the monitoring state, only meaningful for debugging purposes.
Definition: monitoring.c:316
Abstraction of a monitored entity data.
Definition: monitoring.h:124
monitored_entity_t * monitoring_add_monitored_entity(monitoring_state_t *monitoring, enum monitored_entity_type type, monitored_entity_t *prev, monitored_entity_t *parent)
Creates a monitored entity object and links it to the linked-list, in the position of prev OR parent...
Definition: monitoring.c:85
#define MONITORED_ENTITY_MAX_SENSOR_DATA
Maximum number of sensors per monitored entity.
Definition: monitoring.h:116
static rofl_result_t monitoring_remove_monitored_entity(monitoring_state_t *monitoring, monitored_entity_t *entity)
Destroys an detaches monitored entity object.
Definition: monitoring.h:275
monitored_entity_type
Monitoring entity type enum, defined according to RFC2737.
Definition: monitoring.h:98
Sensor data information.
Definition: monitoring.h:82
ROFL_BEGIN_DECLS rofl_result_t __monitoring_init(monitoring_state_t *monitoring)
Initializes the monitoring state.
Definition: monitoring.c:207
struct monitored_entity monitored_entity_t
Abstraction of a monitored entity data.