本文整理汇总了Python中WMComponent.AlertGenerator.Pollers.Base.PeriodPoller类的典型用法代码示例。如果您正苦于以下问题:Python PeriodPoller类的具体用法?Python PeriodPoller怎么用?Python PeriodPoller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PeriodPoller类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
# ProcessDetail class instance (main process plus subprocesses)
self._dbProcessDetail = None
# instance of Measurements
self._measurements = None
self._setUp()
示例2: check
def check(self):
self._updateComponentsInfo()
for processDetail, measurements in zip(self._components, self._compMeasurements):
try:
PeriodPoller.check(self, processDetail, measurements)
except psutil.error.NoSuchProcess as ex:
logging.warn("Observed process or its child process(es) disappeared, "
"update at the next polling attempt, reason: %s." % ex)
示例3: testPeriodPollerOnRealProcess
def testPeriodPollerOnRealProcess(self):
config = getConfig("/tmp")
config.component_("AlertProcessor")
config.AlertProcessor.section_("critical")
config.AlertProcessor.section_("soft")
config.AlertProcessor.critical.level = 5
config.AlertProcessor.soft.level = 0
config.component_("AlertGenerator")
config.AlertGenerator.section_("bogusPoller")
config.AlertGenerator.bogusPoller.soft = 5 # [percent]
# the way the worker is implemented should take 100% CPU, but it sometimes
# take a while, test safer threshold here, testing thresholds
# more rigorously happens in Pollers_t
config.AlertGenerator.bogusPoller.critical = 50 # [percent]
config.AlertGenerator.bogusPoller.pollInterval = 0.2 # [second]
# period during which measurements are collected before evaluating for possible alert triggering
config.AlertGenerator.bogusPoller.period = 1
generator = utils.AlertGeneratorMock(config)
poller = PeriodPoller(config.AlertGenerator.bogusPoller, generator)
poller.sender = utils.SenderMock()
# get CPU usage percentage, it's like measuring CPU usage of a real
# component, so use the appropriate poller's method for that
# (PeriodPoller itself is higher-level class so it doesn't define
# a method to provide sampling data)
poller.sample = lambda processDetail: ComponentsCPUPoller.sample(processDetail)
p = utils.getProcess()
self.testProcesses.append(p)
while not p.is_alive():
time.sleep(0.2)
name = "mytestprocess-testPeriodPollerBasic"
pd = ProcessDetail(p.pid, name)
# need to repeat sampling required number of measurements
numOfMeasurements = int(config.AlertGenerator.bogusPoller.period /
config.AlertGenerator.bogusPoller.pollInterval)
mes = Measurements(numOfMeasurements)
self.assertEqual(len(mes), 0)
for i in range(mes._numOfMeasurements):
poller.check(pd, mes)
# 1 alert should have arrived, test it
# though there may be a second alert as well if the test managed to
# run second round - don't test number of received alerts
# also the Level and threshold is not deterministic: given it's
# measured on a live process it can't be determined up-front how
# much CPU this simple process will be given: don't test Level
# and threshold
a = poller.sender.queue[0]
self.assertEqual(a["Component"], generator.__class__.__name__)
self.assertEqual(a["Source"], poller.__class__.__name__)
d = a["Details"]
self.assertEqual(d["numMeasurements"], mes._numOfMeasurements)
self.assertEqual(d["component"], name)
self.assertEqual(d["period"], config.AlertGenerator.bogusPoller.period)
# since the whole measurement cycle was done, values should have been nulled
self.assertEqual(len(mes), 0)
示例4: __init__
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
# access to the entire agent's configuration
self.agentCompleteConfig = generator.config
# list of instances of ProcessDetail class (processes (plus subprocesses)
# that represent all (as read from the configuration) components of the agent
self._components = []
# list of instance of the Measurements class - measurements for 1 particular component
self._compMeasurements = []
self._setUp()
示例5: check
def check(self):
"""
Above, the database server psutil.Process instance creation may have
failed. Proceed with checking only if the instance exists.
"""
if self._dbProcessDetail:
try:
PeriodPoller.check(self, self._dbProcessDetail, self._measurements)
except psutil.error.NoSuchProcess as ex:
logging.warn(ex)
logging.warn("Updating info about the polled process ...")
self._setUp()
示例6: __init__
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
# access to the entire agent's configuration
self.agentCompleteConfig = generator.config
# number of measurements (polling) before the values are evaluated
# for possible alert sending (is set up in the _setUp method)
self.numOfMeasurements = -1
# list of instances of ProcessDetail class (processes (plus subprocesses)
# that represent all (as read from the configuration) components of the agent
self._components = []
# list of instance of the Measurements class - measurements for 1 particular component
self._compMeasurements = []
self._setUp()
示例7: check
def check(self):
PeriodPoller.check(self, None, self._measurements)
示例8: __init__
def __init__(self, config, generator):
PeriodPoller.__init__(self, config, generator)
numOfMeasurements = round(self.config.period / self.config.pollInterval, 0)
self._measurements = Measurements(numOfMeasurements)
示例9: check
def check(self):
for processDetail, measurements in zip(self._components, self._compMeasurements):
PeriodPoller.check(self, processDetail, measurements)