当前位置: 首页>>代码示例>>Python>>正文


Python PeriodPoller.sample方法代码示例

本文整理汇总了Python中WMComponent.AlertGenerator.Pollers.Base.PeriodPoller.sample方法的典型用法代码示例。如果您正苦于以下问题:Python PeriodPoller.sample方法的具体用法?Python PeriodPoller.sample怎么用?Python PeriodPoller.sample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WMComponent.AlertGenerator.Pollers.Base.PeriodPoller的用法示例。


在下文中一共展示了PeriodPoller.sample方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testPeriodPollerOnRealProcess

# 需要导入模块: from WMComponent.AlertGenerator.Pollers.Base import PeriodPoller [as 别名]
# 或者: from WMComponent.AlertGenerator.Pollers.Base.PeriodPoller import sample [as 别名]
 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)
开发者ID:zhiwenuil,项目名称:WMCore,代码行数:60,代码来源:Base_t.py


注:本文中的WMComponent.AlertGenerator.Pollers.Base.PeriodPoller.sample方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。