Commit 60c82cbf authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: add wrsMemoryFreeLow to wrsOSStatusGroup

Notify with error or warning when mamory usage is too high.

Additionally:
--update MIB
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 7472a026
......@@ -172,6 +172,21 @@ wrsTemperatureWarning OBJECT-TYPE
"Warning if temperature exceed threshold levels"
::= { wrsOSStatusGroup 2 }
wrsMemoryFreeLow OBJECT-TYPE
SYNTAX INTEGER {
na(0),
ok(1),
error(2),
warning(3),
warningNA(4)
}
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Status of free memory. Based on wrsMemoryGroup.
Error - more than 80% memory used
Warning - more than 50% memory used"
::= { wrsOSStatusGroup 3 }
-- wrsTimingStatusGroup (.6.2.2)
wrsTimingStatusGroup OBJECT IDENTIFIER ::= { wrsDetailedStatusesGroup 2 }
......
#include "wrsSnmp.h"
#include "wrsBootStatusGroup.h"
#include "wrsTemperatureGroup.h"
#include "wrsMemoryGroup.h"
#include "wrsOSStatusGroup.h"
#define WRSMEMORYFREELOW_TRESHOLD_ERROR 80
#define WRSMEMORYFREELOW_TRESHOLD_WARNING 50
static struct pickinfo wrsOSStatus_pickinfo[] = {
FIELD(wrsOSStatus_s, ASN_INTEGER, wrsBootSuccessful),
FIELD(wrsOSStatus_s, ASN_INTEGER, wrsTemperatureWarning),
FIELD(wrsOSStatus_s, ASN_INTEGER, wrsMemoryFreeLow),
};
struct wrsOSStatus_s wrsOSStatus_s;
......@@ -15,13 +20,17 @@ time_t wrsOSStatus_data_fill(void)
static time_t time_update; /* time of last update */
time_t time_temp; /* time when temperature data was updated */
time_t time_boot; /* time when boot data was updated */
time_t time_free_mem; /* time when free memory data was updated */
struct wrsBootStatus_s *b;
struct wrsMemory_s *f;
time_boot = wrsBootStatus_data_fill();
time_temp = wrsTemperature_data_fill();
time_free_mem = wrsMemory_data_fill();
if (time_boot <= time_update
&& time_temp <= time_update) {
&& time_temp <= time_update
&& time_free_mem <= time_update) {
/* cache not updated, return last update time */
return time_update;
}
......@@ -127,6 +136,26 @@ time_t wrsOSStatus_data_fill(void)
|| (wrsTemperature_s.temp_psr > wrsTemperature_s.temp_psr_thold));
}
/*********************************************************************\
|************************* wrsMemoryFreeLow *************************|
\*********************************************************************/
/* Check memory usage */
f = &wrsMemory_s;
if (f->wrsMemoryUsedPerc > WRSMEMORYFREELOW_TRESHOLD_ERROR) {
/* Memory usage above error threshold level */
wrsOSStatus_s.wrsMemoryFreeLow = WRS_MEMORY_FREE_LOW_ERROR;
} else if (f->wrsMemoryUsedPerc > WRSMEMORYFREELOW_TRESHOLD_WARNING) {
/* Memory usage above warning threshold level */
wrsOSStatus_s.wrsMemoryFreeLow = WRS_MEMORY_FREE_LOW_WARNING;
} else if (f->wrsMemoryTotal == 0) {
/* Problem with read memory size */
wrsOSStatus_s.wrsMemoryFreeLow =
WRS_MEMORY_FREE_LOW_WARNING_NA;
} else {
/* Memory usage below threshold levels */
wrsOSStatus_s.wrsMemoryFreeLow = WRS_MEMORY_FREE_LOW_OK;
}
/* there was an update, return current time */
return time_update;
}
......
......@@ -15,9 +15,17 @@
#define WRS_TEMPERATURE_WARNING_OK 2 /* ok */
#define WRS_TEMPERATURE_WARNING_TOO_HIGH 3 /* warning */
#define WRS_MEMORY_FREE_LOW_OK 1 /* ok */
#define WRS_MEMORY_FREE_LOW_ERROR 2 /* error */
#define WRS_MEMORY_FREE_LOW_WARNING 3 /* warning */
#define WRS_MEMORY_FREE_LOW_WARNING_NA 4 /* warning, at least one field is
* equal to 0 (NA),shouldn't happen in
* normal operation */
struct wrsOSStatus_s {
int wrsBootSuccessful;
int wrsTemperatureWarning;
int wrsMemoryFreeLow;
};
extern struct wrsOSStatus_s wrsOSStatus_s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment