Skip to content

Commit

Permalink
Add dell specific mibs (sonic-net#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiluo-msft authored Mar 7, 2017
1 parent a3391a9 commit c38cc59
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sonic_ax_impl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sonic_ax_impl.mibs import ieee802_1ab
from . import logger
from .mibs.ietf import rfc1213, rfc2863, rfc4292, rfc4363
from .mibs.vendor import dell

# Background task update frequency ( in seconds )
DEFAULT_UPDATE_FREQUENCY = 5
Expand All @@ -27,6 +28,7 @@ class SonicMIB(
rfc4292.IpCidrRouteTable,
ieee802_1ab.LLDPLocPortTable,
ieee802_1ab.LLDPRemTable,
dell.force10.SSeriesMIB,
):
"""
If SONiC was to create custom MIBEntries, they may be specified here.
Expand Down
64 changes: 64 additions & 0 deletions src/sonic_ax_impl/mibs/vendor/__init__.py
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()
1 change: 1 addition & 0 deletions src/sonic_ax_impl/mibs/vendor/dell/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import force10
24 changes: 24 additions & 0 deletions src/sonic_ax_impl/mibs/vendor/dell/force10.py
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)

0 comments on commit c38cc59

Please sign in to comment.