Files
monasca-agent/monasca_setup/detection/plugins/system.py
Gary Hessler b1de7db1f5 Removing subprocess call from system metrics classes
Changed the IO, Disk and Network classes to not use a subprocess.
They now use psutil to get the metrics.  Also, changed the linux
system metrics classes to subclass the AgentCheck class instead
of the old-style Check class.  Added additional configuration
and changed monasca-setup to support that. Fixed some Python
2.6 incompatible string formatting issues.

Change-Id: I1f8b65bf48e48e2c598aa4950c194fbae2f9e337
2015-02-25 10:58:43 -07:00

43 lines
1.2 KiB
Python

import logging
import os
import yaml
from monasca_setup.detection import Plugin
from monasca_setup import agent_config
log = logging.getLogger(__name__)
class System(Plugin):
"""No configuration here, the system metrics are assumed so this is either on or off.
"""
system_metrics = ['network', 'disk', 'load', 'memory', 'cpu']
def _detect(self):
"""Run detection, set self.available True if the service is detected.
"""
self.available = True
def build_config(self):
"""Build the configs for the system metrics as Plugin objects and return.
"""
config = agent_config.Plugins()
for metric in System.system_metrics:
try:
with open(os.path.join(self.template_dir, 'conf.d/' + metric + '.yaml'), 'r') as metric_template:
default_config = yaml.load(metric_template.read())
config[metric] = default_config
log.info('\tConfigured {0}'.format(metric))
except (OSError, IOError):
log.info('\tUnable to configure {0}'.format(metric))
continue
return config
def dependencies_installed(self):
return True