Commit a57290b3 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: add new wrsCpuLoadGroup

New group with load averages similar to these returned by uptime,
but multiplied with 100 to avoid floats.

Add new wrsCpuLoadGroup with objects:
-- wrsCPULoadAvg1min
-- wrsCPULoadAvg5min
-- wrsCPULoadAvg15min

Additionally:
-- update of MIB
-- update Makefile
-- update init.c
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 5255a83c
......@@ -39,6 +39,7 @@ SOURCES = \
wrsBootStatusGroup.c \
wrsTemperatureGroup.c \
wrsMemoryGroup.c \
wrsCpuLoadGroup.c \
wrsStartCntGroup.c \
wrsSpllVersionGroup.c \
wrsSpllStatusGroup.c \
......
......@@ -757,6 +757,33 @@ wrsMemoryFree OBJECT-TYPE
"Free RAM in kB"
::= { wrsMemoryGroup 4 }
-- wrsCpuLoadGroup (.7.1.5)
wrsCpuLoadGroup OBJECT IDENTIFIER ::= { wrsOperationStatus 5 }
wrsCPULoadAvg1min OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Load average over 1min multiplied by 100"
::= { wrsCpuLoadGroup 1 }
wrsCPULoadAvg5min OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Load average over 5min multiplied by 100"
::= { wrsCpuLoadGroup 2 }
wrsCPULoadAvg15min OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Load average over 15min multiplied by 100"
::= { wrsCpuLoadGroup 3 }
wrsStartCntGroup OBJECT IDENTIFIER ::= { wrsExpertStatus 2 }
-- wrsStartCntGroup (.7.2)
......
......@@ -18,6 +18,7 @@
#include "wrsBootStatusGroup.h"
#include "wrsTemperatureGroup.h"
#include "wrsMemoryGroup.h"
#include "wrsCpuLoadGroup.h"
#include "wrsStartCntGroup.h"
#include "wrsSpllVersionGroup.h"
#include "wrsSpllStatusGroup.h"
......@@ -48,6 +49,7 @@ void init_wrsSnmp(void)
init_wrsBootStatusGroup();
init_wrsTemperatureGroup();
init_wrsMemoryGroup();
init_wrsCpuLoadGroup();
init_wrsStartCntGroup();
init_wrsSpllVersionGroup();
init_wrsSpllStatusGroup();
......
#include "wrsSnmp.h"
#include "wrsCpuLoadGroup.h"
#include <sys/sysinfo.h> /* sysinfo */
static struct pickinfo wrsCpuLoad_pickinfo[] = {
FIELD(wrsCpuLoad_s, ASN_INTEGER, wrsCPULoadAvg1min),
FIELD(wrsCpuLoad_s, ASN_INTEGER, wrsCPULoadAvg5min),
FIELD(wrsCpuLoad_s, ASN_INTEGER, wrsCPULoadAvg15min),
};
struct wrsCpuLoad_s wrsCpuLoad_s;
time_t wrsCpuLoad_data_fill(void)
{
static time_t time_update;
time_t time_cur;
struct sysinfo info;
time_cur = time(NULL);
if (time_update
&& time_cur - time_update < WRSCPULOAD_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
return time_update;
}
time_update = time_cur;
memset(&wrsCpuLoad_s, 0, sizeof(wrsCpuLoad_s));
if (sysinfo(&info) != 0) {
snmp_log(LOG_ERR, "SNMP: wrsMemoryGroup error while reading "
"system statistics with function sysinfo\n");
}
wrsCpuLoad_s.wrsCPULoadAvg1min =
(info.loads[0] * 100)/(1 << SI_LOAD_SHIFT);
wrsCpuLoad_s.wrsCPULoadAvg5min =
(info.loads[1] * 100)/(1 << SI_LOAD_SHIFT);
wrsCpuLoad_s.wrsCPULoadAvg15min =
(info.loads[2] * 100)/(1 << SI_LOAD_SHIFT);
/* there was an update, return current time */
return time_update;
}
#define GT_OID WRSCPULOAD_OID
#define GT_PICKINFO wrsCpuLoad_pickinfo
#define GT_DATA_FILL_FUNC wrsCpuLoad_data_fill
#define GT_DATA_STRUCT wrsCpuLoad_s
#define GT_GROUP_NAME "wrsCpuLoadGroup"
#define GT_INIT_FUNC init_wrsCpuLoadGroup
#include "wrsGroupTemplate.h"
#ifndef WRS_CPU_LOAD_GROUP_H
#define WRS_CPU_LOAD_GROUP_H
#define WRSCPULOAD_CACHE_TIMEOUT 5
#define WRSCPULOAD_OID WRS_OID, 7, 1, 5
struct wrsCpuLoad_s {
int wrsCPULoadAvg1min;
int wrsCPULoadAvg5min;
int wrsCPULoadAvg15min;
};
extern struct wrsCpuLoad_s wrsCpuLoad_s;
time_t wrsCpuLoad_data_fill(void);
void init_wrsCpuLoadGroup(void);
#endif /* WRS_CPU_LOAD_GROUP_H */
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