forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dell specific mibs (sonic-net#16)
- Loading branch information
1 parent
a3391a9
commit c38cc59
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import collections | ||
import time | ||
|
||
import psutil | ||
|
||
from ax_interface import MIBUpdater | ||
from sonic_ax_impl import logger | ||
|
||
|
||
class SystemUtilizationHandler(MIBUpdater): | ||
def __init__(self): | ||
super().__init__() | ||
# From the psutil documentation https://pythonhosted.org/psutil/#psutil.cpu_percent: | ||
# | ||
# Warning the first time this function is called | ||
# with interval = 0.0 or None it will return a | ||
# meaningless 0.0 value which you are supposed | ||
# to ignore. | ||
psutil.cpu_percent() | ||
# '...is recommended for accuracy that this function be called with at least 0.1 seconds between calls.' | ||
time.sleep(0.1) | ||
# a sliding window of 60 contiguous 5 sec utilization (up to five minutes) | ||
self.cpuutils = collections.deque([psutil.cpu_percent()], maxlen=60) | ||
self.system_virtual_memory = psutil.virtual_memory() | ||
|
||
logger.debug('System Utilization handler initialized.') | ||
|
||
def get_cpuutil_5sec(self): | ||
""" | ||
:return: Last polled CPU utilization. | ||
""" | ||
return int(self.cpuutils[-1]) | ||
|
||
def get_cpuutil_1min(self): | ||
""" | ||
:return: Up to one minute's worth of average CPU utilization. | ||
""" | ||
past_utilization = list(self.cpuutils)[-12:] | ||
return int(sum(past_utilization) / len(past_utilization)) | ||
|
||
def get_cpuutil_5min(self): | ||
""" | ||
:return: Up to five minute's worth of average CPU utilization. | ||
""" | ||
return int(sum(self.cpuutils) / len(self.cpuutils)) | ||
|
||
def get_memutil(self): | ||
""" | ||
:return: The current memory utilization (as a percent integer) | ||
""" | ||
return int(self.system_virtual_memory.percent) | ||
|
||
def update_data(self): | ||
""" | ||
Background task to add CPU Utilization sample / refresh memory utilization. | ||
""" | ||
cpu_util = psutil.cpu_percent() | ||
self.cpuutils.append(cpu_util) | ||
self.system_virtual_memory = psutil.virtual_memory() | ||
|
||
logger.debug('Updating CPU/Mem Utilization with: {}% / {}%'.format(cpu_util, self.get_memutil())) | ||
|
||
|
||
sys_util_h = SystemUtilizationHandler() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import force10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ax_interface import MIBMeta, ValueType | ||
from ax_interface.mib import MIBEntry | ||
from sonic_ax_impl.mibs.vendor import sys_util_h | ||
|
||
|
||
class SSeriesMIB(metaclass=MIBMeta, prefix='.1.3.6.1.4.1.6027.3.10.1.2.9'): | ||
""" | ||
-- .iso.org.dod.internet.private.enterprises | ||
.force10.f10Mgmt.f10ChassisMib.f10ChassisMibObject | ||
.chRpmObjects.chRpmUtilTable.chRpmUtilEntry.chRpmCpuUtil5Min | ||
""" | ||
updater = sys_util_h | ||
|
||
# S-Series CPU utilization in percentage for last 5 seconds | ||
chStackUnitCpuUtil5sec = MIBEntry('1.2.1', ValueType.GAUGE_32, sys_util_h.get_cpuutil_5sec) | ||
|
||
# S-Series CPU utilization in percentage for last 1 minute. | ||
chStackUnitCpuUtil1Min = MIBEntry('1.3.1', ValueType.GAUGE_32, sys_util_h.get_cpuutil_1min) | ||
|
||
# S-Series CPU utilization in percentage for last 5 minutes. | ||
chStackUnitCpuUtil5Min = MIBEntry('1.4.1', ValueType.GAUGE_32, sys_util_h.get_cpuutil_5min) | ||
|
||
# Stack member total memory usage in percentage | ||
chStackUnitMemUsageUtil = MIBEntry('1.5.1', ValueType.GAUGE_32, sys_util_h.get_memutil) |