本文整理汇总了Python中WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter.updateAgentInfo方法的典型用法代码示例。如果您正苦于以下问题:Python WMStatsWriter.updateAgentInfo方法的具体用法?Python WMStatsWriter.updateAgentInfo怎么用?Python WMStatsWriter.updateAgentInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter
的用法示例。
在下文中一共展示了WMStatsWriter.updateAgentInfo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HeartbeatMonitorBase
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
class HeartbeatMonitorBase(CherryPyPeriodicTask):
def __init__(self, rest, config):
super(HeartbeatMonitorBase, self).__init__(config)
self.centralWMStats = WMStatsWriter(config.wmstats_url)
self.threadList = config.thread_list
def setConcurrentTasks(self, config):
"""
sets the list of function reference for concurrent tasks
"""
self.concurrentTasks = [{'func': self.reportToWMStats, 'duration': config.heartbeatCheckDuration}]
def reportToWMStats(self, config):
"""
report thread status and heartbeat.
Also can report additional mointoring information by rewriting addAdditionalMonitorReport method
"""
self.logger.info("Checking Thread status...")
downThreadInfo = self.logDB.wmstats_down_components_report(self.threadList)
monitorInfo = self.addAdditionalMonitorReport(config)
downThreadInfo.update(monitorInfo)
wqSummaryDoc = convertToServiceCouchDoc(downThreadInfo, config.log_reporter)
self.centralWMStats.updateAgentInfo(wqSummaryDoc)
self.logger.info("Uploaded to WMStats...")
return
def addAdditionalMonitorReport(self, config):
"""
add Additonal report with heartbeat report
overwite the method with each applications monitoring info. (Need to follow the format displayed in wmstats)
"""
return {}
示例2: AgentStatusPoller
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
#.........这里部分代码省略.........
else:
agentInfo['drain_mode'] = False
couchInfo = self.collectCouchDBInfo()
if couchInfo['status'] != 'ok':
agentInfo['down_components'].append(couchInfo['name'])
agentInfo['status'] = couchInfo['status']
agentInfo['down_component_detail'].append(couchInfo)
# Couch process warning
couchProc = numberCouchProcess()
logging.info("CouchDB is running with %d processes", couchProc)
couchProcessThreshold = self.config.AnalyticsDataCollector.couchProcessThreshold
if couchProc >= couchProcessThreshold:
agentInfo['couch_process_warning'] = couchProc
else:
agentInfo['couch_process_warning'] = 0
# This adds the last time and message when data was updated to agentInfo
lastDataUpload = DataUploadTime.getInfo()
if lastDataUpload['data_last_update']:
agentInfo['data_last_update'] = lastDataUpload['data_last_update']
if lastDataUpload['data_error']:
agentInfo['data_error'] = lastDataUpload['data_error']
# Change status if there is data_error, couch process maxed out or disk full problems.
if agentInfo['status'] == 'ok' and (agentInfo['drain_mode'] or agentInfo['disk_warning']):
agentInfo['status'] = "warning"
if agentInfo['status'] == 'ok' or agentInfo['status'] == 'warning':
if agentInfo.get('data_error', 'ok') != 'ok' or agentInfo.get('couch_process_warning', 0):
agentInfo['status'] = "error"
logging.info("List of agent components down: %s", agentInfo['down_components'])
return agentInfo
def uploadAgentInfoToCentralWMStats(self, agentInfo, uploadTime):
# direct data upload to the remote to prevent data conflict when agent is cleaned up and redeployed
agentDocs = convertToAgentCouchDoc(agentInfo, self.config.ACDC, uploadTime)
self.centralWMStatsCouchDB.updateAgentInfo(agentDocs)
@timeFunction
def collectWMBSInfo(self):
"""
Fetches WMBS job information.
In addition to WMBS, also collects RunJob info from BossAir
:return: dict with the number of jobs in each status
"""
logging.info("Getting wmbs job info ...")
results = {}
# first retrieve the site thresholds
results['thresholds'] = self.wmagentDB.getJobSlotInfo()
logging.debug("Running and pending site thresholds: %s", results['thresholds'])
# now fetch the amount of jobs in each state and the amount of created
# jobs grouped by task
results.update(self.wmagentDB.getAgentMonitoring())
logging.debug("Total number of jobs in WMBS sorted by status: %s", results['wmbsCountByState'])
logging.debug("Total number of 'created' jobs in WMBS sorted by type: %s", results['wmbsCreatedTypeCount'])
logging.debug("Total number of 'executing' jobs in WMBS sorted by type: %s", results['wmbsExecutingTypeCount'])
logging.debug("Total number of active jobs in BossAir sorted by status: %s", results['activeRunJobByStatus'])
logging.debug("Total number of complete jobs in BossAir sorted by status: %s",
results['completeRunJobByStatus'])
logging.debug("Available slots thresholds to pull work from GQ to LQ: %s", results['thresholdsGQ2LQ'])
logging.debug("List of jobs pending for each site, sorted by priority: %s", results['sitePendCountByPrio'])
return results
def checkProxyLifetime(self, agInfo):
"""
Check the proxy lifetime (usually X509_USER_CERT) and raise either
a warning or an error if the proxy validity is about to expire.
:param agInfo: dictionary with plenty of agent monitoring information in place.
:return: same dictionary object plus additional keys/values if needed.
"""
secsLeft = self.proxy.getTimeLeft(proxy=self.proxyFile)
logging.debug("Proxy '%s' lifetime is %d secs", self.proxyFile, secsLeft)
if secsLeft <= 86400 * 3: # 3 days
proxyWarning = True
agInfo['status'] = "error"
elif secsLeft <= 86400 * 5: # 5 days
proxyWarning = True
if agInfo['status'] == "ok":
agInfo['status'] = "warning"
else:
proxyWarning = False
if proxyWarning:
warnMsg = "Agent proxy '%s' must be renewed ASAP. " % self.proxyFile
warnMsg += "Its time left is: %.2f hours." % (secsLeft / 3600.)
agInfo['proxy_warning'] = warnMsg
return
示例3: HeartbeatMonitorBase
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
class HeartbeatMonitorBase(CherryPyPeriodicTask):
def __init__(self, rest, config):
super(HeartbeatMonitorBase, self).__init__(config)
self.centralWMStats = WMStatsWriter(config.wmstats_url)
self.threadList = config.thread_list
self.userAMQ = getattr(config, "user_amq", None)
self.passAMQ = getattr(config, "pass_amq", None)
self.postToAMQ = getattr(config, "post_to_amq", False)
self.topicAMQ = getattr(config, "topic_amq", None)
self.hostPortAMQ = getattr(config, "host_port_amq", None)
def setConcurrentTasks(self, config):
"""
sets the list of function reference for concurrent tasks
"""
self.concurrentTasks = [{'func': self.reportToWMStats, 'duration': config.heartbeatCheckDuration}]
def reportToWMStats(self, config):
"""
report thread status and heartbeat.
Also can report additional monitoring information by rewriting addAdditionalMonitorReport method
"""
self.logger.info("Checking Thread status...")
downThreadInfo = self.logDB.wmstats_down_components_report(self.threadList)
monitorInfo = self.addAdditionalMonitorReport(config)
downThreadInfo.update(monitorInfo)
wqSummaryDoc = convertToServiceCouchDoc(downThreadInfo, config.log_reporter)
self.centralWMStats.updateAgentInfo(wqSummaryDoc)
self.logger.info("Uploaded to WMStats...")
return
def addAdditionalMonitorReport(self, config):
"""
add Additonal report with heartbeat report
overwite the method with each applications monitoring info. (Need to follow the format displayed in wmstats)
"""
return {}
def uploadToAMQ(self, docs, producer=None):
"""
_uploadToAMQ_
Sends data to AMQ, which ends up in elastic search.
:param docs: list of documents/dicts to be posted
:param producer: service name that's providing this info
"""
if not docs:
self.logger.info("There are no documents to send to AMQ")
return
producer = producer or self.producer
self.logger.debug("Sending the following data to AMQ %s", pformat(docs))
ts = int(time.time())
try:
stompSvc = StompAMQ(username=self.userAMQ,
password=self.passAMQ,
producer=producer,
topic=self.topicAMQ,
host_and_ports=self.hostPortAMQ,
logger=self.logger)
notifications = [stompSvc.make_notification(payload=doc, docType=self.docTypeAMQ, ts=ts,
dataSubfield="payload") for doc in docs]
failures = stompSvc.send(notifications)
self.logger.info("%i docs successfully sent to Stomp AMQ", len(notifications) - len(failures))
except Exception as ex:
self.logger.exception("Failed to send data to StompAMQ. Error %s", str(ex))
return
示例4: AgentStatusPoller
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
#.........这里部分代码省略.........
if isDrainMode(self.config):
logging.info("Agent is in DrainMode")
agentInfo['drain_mode'] = True
else:
agentInfo['drain_mode'] = False
couchInfo = self.collectCouchDBInfo()
if couchInfo['status'] != 'ok':
agentInfo['down_components'].append(couchInfo['name'])
agentInfo['status'] = couchInfo['status']
agentInfo['down_component_detail'].append(couchInfo)
# Disk space warning
diskUseList = diskUse()
diskUseThreshold = float(
self.config.AnalyticsDataCollector.diskUseThreshold)
agentInfo['disk_warning'] = []
for disk in diskUseList:
if float(disk['percent'].strip('%')) >= diskUseThreshold and \
disk['mounted'] not in self.config.AnalyticsDataCollector.ignoreDisk:
agentInfo['disk_warning'].append(disk)
# Couch process warning
couchProc = numberCouchProcess()
logging.info("CouchDB is running with %d processes", couchProc)
couchProcessThreshold = self.config.AnalyticsDataCollector.couchProcessThreshold
if couchProc >= couchProcessThreshold:
agentInfo['couch_process_warning'] = couchProc
else:
agentInfo['couch_process_warning'] = 0
# This adds the last time and message when data was updated to agentInfo
lastDataUpload = DataUploadTime.getInfo()
if lastDataUpload['data_last_update']:
agentInfo['data_last_update'] = lastDataUpload['data_last_update']
if lastDataUpload['data_error']:
agentInfo['data_error'] = lastDataUpload['data_error']
# Change status if there is data_error, couch process maxed out or disk full problems.
if agentInfo['status'] == 'ok' and (agentInfo['drain_mode']
or agentInfo['disk_warning']):
agentInfo['status'] = "warning"
if agentInfo['status'] == 'ok' or agentInfo['status'] == 'warning':
if agentInfo.get('data_error', 'ok') != 'ok' or agentInfo.get(
'couch_process_warning', 0):
agentInfo['status'] = "error"
if agentInfo['down_components']:
logging.info("List of agent components down: %s" %
agentInfo['down_components'])
return agentInfo
def uploadAgentInfoToCentralWMStats(self, agentInfo, uploadTime):
#direct data upload to the remote to prevent data conflict when agent is cleaned up and redeployed
agentDocs = convertToAgentCouchDoc(agentInfo, self.config.ACDC,
uploadTime)
self.centralWMStatsCouchDB.updateAgentInfo(agentDocs)
def collectWMBSInfo(self):
"""
Fetches WMBS job information.
In addition to WMBS, also collects RunJob info from BossAir
:return: dict with the number of jobs in each status
"""
results = {}
logging.info("Getting wmbs job info ...")
# first retrieve the site thresholds
results['thresholds'] = self.wmagentDB.getJobSlotInfo()
logging.info("Running and pending site thresholds: %s",
results['thresholds'])
# now fetch the amount of jobs in each state and the amount of created
# jobs grouped by task
results.update(self.wmagentDB.getAgentMonitoring())
logging.info("Total number of jobs in WMBS sorted by status: %s",
results['wmbsCountByState'])
logging.info(
"Total number of 'created' jobs in WMBS sorted by type: %s",
results['wmbsCreatedTypeCount'])
logging.info(
"Total number of 'executing' jobs in WMBS sorted by type: %s",
results['wmbsExecutingTypeCount'])
logging.info(
"Total number of active jobs in BossAir sorted by status: %s",
results['activeRunJobByStatus'])
logging.info(
"Total number of complete jobs in BossAir sorted by status: %s",
results['completeRunJobByStatus'])
logging.info(
"Available slots thresholds to pull work from GQ to LQ: %s",
results['thresholdsGQ2LQ'])
logging.info(
"List of jobs pending for each site, sorted by priority: %s",
results['sitePendCountByPrio'])
return results
示例5: AgentStatusPoller
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
#.........这里部分代码省略.........
"""
try:
logging.info("Getting Agent info ...")
agentInfo = self.collectAgentInfo()
#set the uploadTime - should be the same for all docs
uploadTime = int(time.time())
self.uploadAgentInfoToCentralWMStats(agentInfo, uploadTime)
logging.info("Agent components down:\n %s" % agentInfo['down_components'])
logging.info("Agent in drain mode:\n %s \nsleep for next WMStats alarm updating cycle"
% agentInfo['drain_mode'])
except Exception as ex:
logging.error("Error occurred, will retry later:")
logging.error(str(ex))
logging.error("Trace back: \n%s" % traceback.format_exc())
def collectCouchDBInfo(self):
couchInfo = {'status': 'ok', 'error_message': ""}
if self.skipReplicationCheck:
# skipping the check this round set if False so it can be checked next round.
self.skipReplicationCheck = False
return couchInfo
msg = ""
for rp in self.replicatorDocs:
cInfo = self.localCouchMonitor.checkCouchServerStatus(rp['source'],
rp['target'], checkUpdateSeq = False)
if cInfo['status'] != 'ok':
couchInfo['status'] = 'error'
couchInfo['error_message'] = msg
return couchInfo
def collectAgentInfo(self):
agentInfo = self.wmagentDB.getComponentStatus(self.config)
agentInfo.update(self.agentInfo)
if isDrainMode(self.config):
logging.info("Agent is in DrainMode")
agentInfo['drain_mode'] = True
agentInfo['status'] = "warning"
else:
agentInfo['drain_mode'] = False
couchInfo = self.collectCouchDBInfo()
if (couchInfo['status'] != 'ok'):
agentInfo['down_components'].append("CouchServer")
agentInfo['status'] = couchInfo['status']
couchInfo['name'] = "CouchServer"
agentInfo['down_component_detail'].append(couchInfo)
# Disk space warning
diskUseList = diskUse()
diskUseThreshold = float(self.config.AnalyticsDataCollector.diskUseThreshold)
agentInfo['disk_warning'] = []
for disk in diskUseList:
if float(disk['percent'].strip('%')) >= diskUseThreshold and disk['mounted'] not in self.config.AnalyticsDataCollector.ignoreDisk:
agentInfo['disk_warning'].append(disk)
# Couch process warning
couchProc = numberCouchProcess()
couchProcessThreshold = float(self.config.AnalyticsDataCollector.couchProcessThreshold)
if couchProc >= couchProcessThreshold:
agentInfo['couch_process_warning'] = couchProc
else:
agentInfo['couch_process_warning'] = 0
# This adds the last time and message when data was updated to agentInfo
lastDataUpload = DataUploadTime.getInfo(self)
if lastDataUpload['data_last_update']!=0:
agentInfo['data_last_update'] = lastDataUpload['data_last_update']
if lastDataUpload['data_error']!="":
agentInfo['data_error'] = lastDataUpload['data_error']
# Change status if there is data_error, couch process maxed out or disk full problems.
if agentInfo['status'] == 'ok':
if agentInfo['disk_warning'] != []:
agentInfo['status'] = "warning"
if agentInfo['status'] == 'ok' or agentInfo['status'] == 'warning':
if ('data_error' in agentInfo and agentInfo['data_error'] != 'ok') or \
('couch_process_warning' in agentInfo and agentInfo['couch_process_warning'] != 0):
agentInfo['status'] = "error"
return agentInfo
def uploadAgentInfoToCentralWMStats(self, agentInfo, uploadTime):
#direct data upload to the remote to prevent data conflict when agent is cleaned up and redeployed
agentDocs = convertToAgentCouchDoc(agentInfo, self.config.ACDC, uploadTime)
self.centralWMStatsCouchDB.updateAgentInfo(agentDocs)
示例6: AgentStatusPoller
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
#.........这里部分代码省略.........
# Couch process warning
couchProc = numberCouchProcess()
logging.info("CouchDB is running with %d processes", couchProc)
couchProcessThreshold = self.config.AnalyticsDataCollector.couchProcessThreshold
if couchProc >= couchProcessThreshold:
agentInfo['couch_process_warning'] = couchProc
else:
agentInfo['couch_process_warning'] = 0
# Change status if there is data_error, couch process maxed out or disk full problems.
if agentInfo['status'] == 'ok' and (agentInfo['drain_mode'] or agentInfo['disk_warning']):
agentInfo['status'] = "warning"
if agentInfo['status'] == 'ok' or agentInfo['status'] == 'warning':
if agentInfo.get('data_error', 'ok') != 'ok' or agentInfo.get('couch_process_warning', 0):
agentInfo['status'] = "error"
logging.info("List of agent components down: %s", agentInfo['down_components'])
return agentInfo
def uploadAgentInfoToCentralWMStats(self, agentInfo):
"""
Add some required fields to the document before it can get uploaded
to WMStats.
:param agentInfo: dict with agent stats to be posted to couchdb
"""
agentInfo['_id'] = agentInfo["agent_url"]
agentInfo['timestamp'] = int(time.time())
agentInfo['type'] = "agent_info"
# directly upload to the remote to prevent data conflict when agent is cleaned up and redeployed
try:
self.centralWMStatsCouchDB.updateAgentInfo(agentInfo,
propertiesToKeep=["data_last_update", "data_error"])
except Exception as e:
logging.error("Failed to upload agent statistics to WMStats. Error: %s", str(e))
@timeFunction
def collectWMBSInfo(self):
"""
Fetches WMBS job information.
In addition to WMBS, also collects RunJob info from BossAir
:return: dict with the number of jobs in each status
"""
logging.info("Getting wmbs job info ...")
results = {}
# first retrieve the site thresholds
results['thresholds'] = self.wmagentDB.getJobSlotInfo()
logging.debug("Running and pending site thresholds: %s", results['thresholds'])
# now fetch the amount of jobs in each state and the amount of created
# jobs grouped by task
results.update(self.wmagentDB.getAgentMonitoring())
logging.debug("Total number of jobs in WMBS sorted by status: %s", results['wmbsCountByState'])
logging.debug("Total number of 'created' jobs in WMBS sorted by type: %s", results['wmbsCreatedTypeCount'])
logging.debug("Total number of 'executing' jobs in WMBS sorted by type: %s", results['wmbsExecutingTypeCount'])
logging.debug("Total number of active jobs in BossAir sorted by status: %s", results['activeRunJobByStatus'])
logging.debug("Total number of complete jobs in BossAir sorted by status: %s",
results['completeRunJobByStatus'])
logging.debug("Available slots thresholds to pull work from GQ to LQ: %s", results['thresholdsGQ2LQ'])
logging.debug("List of jobs pending for each site, sorted by priority: %s", results['sitePendCountByPrio'])
示例7: AnalyticsPoller
# 需要导入模块: from WMCore.Services.WMStats.WMStatsWriter import WMStatsWriter [as 别名]
# 或者: from WMCore.Services.WMStats.WMStatsWriter.WMStatsWriter import updateAgentInfo [as 别名]
class AnalyticsPoller(BaseWorkerThread):
"""
Gether the summary data for request (workflow) from local queue,
local job couchdb, wmbs/boss air and populate summary db for monitoring
"""
def __init__(self, config):
"""
initialize properties specified from config
"""
BaseWorkerThread.__init__(self)
# set the workqueue service for REST call
self.config = config
self.agentInfo = {}
self.agentInfo['agent_team'] = config.Agent.teamName
self.agentInfo['agent'] = config.Agent.agentName
# temporarly add port for the split test
self.agentInfo['agent_url'] = ("%s:%s" % (config.Agent.hostName, config.WMBSService.Webtools.port))
# need to get campaign, user, owner info
self.agentDocID = "agent+hostname"
self.summaryLevel = (config.AnalyticsDataCollector.summaryLevel).lower()
def setup(self, parameters):
"""
set db connection(couchdb, wmbs) to prepare to gether information
"""
#
self.localQueue = WorkQueueService(self.config.AnalyticsDataCollector.localQueueURL)
# set the connection for local couchDB call
self.localCouchDB = LocalCouchDBData(self.config.AnalyticsDataCollector.localCouchURL, self.summaryLevel)
# interface to WMBS/BossAir db
myThread = threading.currentThread()
# set wmagent db data
self.wmagentDB = WMAgentDBData(self.summaryLevel, myThread.dbi, myThread.logger)
# set the connection for local couchDB call
self.localSummaryCouchDB = WMStatsWriter(self.config.AnalyticsDataCollector.localWMStatsURL)
logging.info("Setting the replication to central monitor ...")
self.localSummaryCouchDB.replicate(self.config.AnalyticsDataCollector.centralWMStatsURL)
def algorithm(self, parameters):
"""
get information from wmbs, workqueue and local couch
"""
try:
#jobs per request info
logging.info("Getting Job Couch Data ...")
jobInfoFromCouch = self.localCouchDB.getJobSummaryByWorkflowAndSite()
#fwjr per request info
logging.info("Getting FWJRJob Couch Data ...")
fwjrInfoFromCouch = self.localCouchDB.getEventSummaryByWorkflow()
logging.info("Getting Batch Job Data ...")
batchJobInfo = self.wmagentDB.getBatchJobInfo()
# get the data from local workqueue:
# request name, input dataset, inWMBS, inQueue
logging.info("Getting Local Queue Data ...")
localQInfo = self.localQueue.getAnalyticsData()
# combine all the data from 3 sources
logging.info("""Combining data from
Job Couch(%s),
FWJR(%s),
Batch Job(%s),
Local Queue(%s) ..."""
% (len(jobInfoFromCouch), len(fwjrInfoFromCouch), len(batchJobInfo), len(localQInfo)))
tempCombinedData = combineAnalyticsData(jobInfoFromCouch, batchJobInfo)
combinedRequests = combineAnalyticsData(tempCombinedData, localQInfo)
#set the uploadTime - should be the same for all docs
uploadTime = int(time.time())
logging.info("%s requests Data combined,\n uploading request data..." % len(combinedRequests))
requestDocs = convertToRequestCouchDoc(combinedRequests, fwjrInfoFromCouch,
self.agentInfo, uploadTime, self.summaryLevel)
self.localSummaryCouchDB.uploadData(requestDocs)
logging.info("Request data upload success\n %s request \n uploading agent data" % len(requestDocs))
#TODO: agent info (need to include job Slots for the sites)
agentInfo = self.wmagentDB.getHeartBeatWarning()
agentInfo.update(self.agentInfo)
agentDocs = convertToAgentCouchDoc(agentInfo, self.config.ACDC, uploadTime)
self.localSummaryCouchDB.updateAgentInfo(agentDocs)
logging.info("Agent data upload success\n %s request" % len(agentDocs))
except Exception, ex:
logging.error(str(ex))
raise