Merge pull request #334 from fomars/lunapark-2661

Lunapark 2661
This commit is contained in:
Alexey Lavrenuke 2017-03-23 17:51:06 +03:00 committed by GitHub
commit 9a953ec4db
2 changed files with 16 additions and 11 deletions

View File

@ -3,6 +3,8 @@ import logging
import sys
import time
import copy
from ...common.interfaces import MonitoringDataListener
from ..Telegraf.client import SSHClient, LocalhostClient
@ -33,7 +35,7 @@ class MonitoringCollector(object):
self.agent_sessions = []
self.listeners = []
self.first_data_received = False
self.send_data = []
self.__collected_data = []
self.artifact_files = []
self.load_start_time = None
self.config_manager = ConfigManager()
@ -98,15 +100,15 @@ class MonitoringCollector(object):
}
}
}
self.send_data.append(ready_to_send)
self.__collected_data.append(ready_to_send)
logger.debug(
'Polling/decoding agents data took: %.2fms',
(time.time() - start_time) * 1000)
collected_data_length = len(self.send_data)
collected_data_length = len(self.__collected_data)
if not self.first_data_received and self.send_data:
if not self.first_data_received and self.__collected_data:
self.first_data_received = True
logger.info("Monitoring received first data.")
else:
@ -130,11 +132,10 @@ class MonitoringCollector(object):
def send_collected_data(self):
"""sends pending data set to listeners"""
[
listener.monitoring_data(self.send_data)
for listener in self.listeners
]
self.send_data = []
data = copy.deepcopy(self.__collected_data)
self.__collected_data = []
for listener in self.listeners:
listener.monitoring_data(copy.deepcopy(data))
class StdOutPrintMon(MonitoringDataListener):

View File

@ -9,6 +9,9 @@ import json
import logging
import os
import time
from copy import deepcopy
from ...common.resource import manager as resource
from ...common.interfaces import MonitoringDataListener, \
AbstractPlugin, AbstractInfoWidget
@ -222,7 +225,7 @@ class Plugin(AbstractPlugin):
for log in self.monitoring.artifact_files:
self.core.add_artifact_file(log)
while self.monitoring.send_data:
while self.monitoring.__collected_data:
logger.info("Sending monitoring data rests...")
self.monitoring.send_collected_data()
if self.mon_saver:
@ -365,10 +368,11 @@ class AbstractMetricCriterion(AbstractCriterion, MonitoringDataListener):
self.last_second = None
self.seconds_count = 0
def monitoring_data(self, block):
def monitoring_data(self, _block):
if self.triggered:
return
block = deepcopy(_block)
for chunk in block:
host = chunk['data'].keys()[0]
data = chunk['data'][host]['metrics']