mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2026-01-04 14:01:47 +00:00
Redefine CpuAllPercentUtilization and CpuAllPercentIdle to be 100 times the percentage rounded to the nearest integer.
Use aim_time_monotonic. Add ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS.
This commit is contained in:
@@ -34,7 +34,7 @@ CpuAllPercentUtilization OBJECT-TYPE
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The average CPU utilization (in percent). Provided by mpstat."
|
||||
"The average CPU utilization in percent, multiplied by 100 and rounded to the nearest integer. Provided by mpstat."
|
||||
::= { Basic 1 }
|
||||
|
||||
CpuAllPercentIdle OBJECT-TYPE
|
||||
@@ -42,7 +42,7 @@ CpuAllPercentIdle OBJECT-TYPE
|
||||
MAX-ACCESS read-only
|
||||
STATUS current
|
||||
DESCRIPTION
|
||||
"The average CPU idle time (in percent). Provided by mpstat."
|
||||
"The average CPU idle time in percent, multiplied by 100 and rounded to the nearest integer. Provided by mpstat."
|
||||
::= { Basic 2 }
|
||||
|
||||
END
|
||||
|
||||
@@ -27,7 +27,7 @@ for line in out.split('\n'):
|
||||
|
||||
if "Average" in line:
|
||||
vals = line.split()[1:]
|
||||
stats[vals[0]] = { k:int(round(float(v))) \
|
||||
stats[vals[0]] = { k:int(round(100*float(v))) \
|
||||
for (k,v) in zip(keys[1:],vals[1:]) }
|
||||
|
||||
print json.dumps(stats)
|
||||
|
||||
@@ -3,7 +3,7 @@ include $(ONL)/make/any.mk
|
||||
MODULE := onlp-snmpd
|
||||
include $(BUILDER)/standardinit.mk
|
||||
|
||||
DEPENDMODULES := onlp_snmp AIM OS snmp_subagent IOF onlplib OS cjson cjson_util
|
||||
DEPENDMODULES := onlp_snmp AIM OS snmp_subagent IOF onlplib cjson cjson_util
|
||||
DEPENDMODULE_HEADERS := onlp
|
||||
|
||||
include $(BUILDER)/dependmodules.mk
|
||||
|
||||
@@ -56,6 +56,9 @@ cdefs: &cdefs
|
||||
- ONLP_SNMP_CONFIG_AS_SUBAGENT:
|
||||
doc: "Configure as an snmp_subagent client."
|
||||
default: 0
|
||||
- ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS:
|
||||
doc: "Resource object update period in seconds."
|
||||
default: 5
|
||||
|
||||
definitions:
|
||||
cdefs:
|
||||
|
||||
@@ -191,6 +191,16 @@
|
||||
#define ONLP_SNMP_CONFIG_AS_SUBAGENT 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS
|
||||
*
|
||||
* Resource object update period in seconds. */
|
||||
|
||||
|
||||
#ifndef ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS
|
||||
#define ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS 5
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,6 +94,11 @@ onlp_snmp_config_settings_t onlp_snmp_config_settings[] =
|
||||
{ __onlp_snmp_config_STRINGIFY_NAME(ONLP_SNMP_CONFIG_AS_SUBAGENT), __onlp_snmp_config_STRINGIFY_VALUE(ONLP_SNMP_CONFIG_AS_SUBAGENT) },
|
||||
#else
|
||||
{ ONLP_SNMP_CONFIG_AS_SUBAGENT(__onlp_snmp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
#ifdef ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS
|
||||
{ __onlp_snmp_config_STRINGIFY_NAME(ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS), __onlp_snmp_config_STRINGIFY_VALUE(ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS) },
|
||||
#else
|
||||
{ ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS(__onlp_snmp_config_STRINGIFY_NAME), "__undefined__" },
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <onlp_snmp/onlp_snmp_config.h>
|
||||
#include "onlp_snmp_log.h"
|
||||
|
||||
#include <OS/os_time.h>
|
||||
#include <AIM/aim_time.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <cjson_util/cjson_util.h>
|
||||
#include <net-snmp/net-snmp-config.h>
|
||||
@@ -89,9 +89,6 @@ resource_int_register(int index, const char* desc,
|
||||
}
|
||||
|
||||
|
||||
/* resource objects refreshed with this period; units in seconds */
|
||||
#define RESOURCE_UPDATE_PERIOD 5
|
||||
|
||||
/* resource objects */
|
||||
typedef struct {
|
||||
uint32_t utilization_percent;
|
||||
@@ -103,8 +100,9 @@ static uint64_t resource_update_time;
|
||||
|
||||
void resource_update(void)
|
||||
{
|
||||
uint64_t now = os_time_monotonic();
|
||||
if (now - resource_update_time > RESOURCE_UPDATE_PERIOD * 1000 * 1000) {
|
||||
uint64_t now = aim_time_monotonic();
|
||||
if (now - resource_update_time >
|
||||
(ONLP_SNMP_CONFIG_RESOURCE_UPDATE_SECONDS * 1000 * 1000)) {
|
||||
resource_update_time = now;
|
||||
AIM_LOG_INFO("update resource objects");
|
||||
|
||||
@@ -124,7 +122,7 @@ void resource_update(void)
|
||||
if (rv == 0) {
|
||||
/* save it */
|
||||
resources.idle_percent = result;
|
||||
resources.utilization_percent = 100 - result;
|
||||
resources.utilization_percent = 100*100 - result;
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user