Renaming agent packages to reflect monasca

Renamed monagent package to monasca_agent and monsetup package to monasca_setup.
Also, renamed the monstatsd agent package to statsd to more closely match the internal
collector and forwarder packages.

Change-Id: I0649ae4341fe325007e2a8d37161d330e4c95d72
This commit is contained in:
gary-hessler 2014-12-17 12:01:44 -07:00
parent 110781ca0c
commit 34d82d455e
147 changed files with 462 additions and 478 deletions

View File

@ -400,10 +400,10 @@ Plugins are the way to extend the Monasca Agent. Plugins add additional functio
Developers can extend the functionality of the Agent by writing custom plugins. Plugins are written in Python according to the conventions described below. The plugin script is placed in /etc/monasca/agent/checks.d, and a YAML file containing the configuration for the plugin is placed in /etc/monasca/agent/conf.d. The YAML file must have the same stem name as the plugin script. Developers can extend the functionality of the Agent by writing custom plugins. Plugins are written in Python according to the conventions described below. The plugin script is placed in /etc/monasca/agent/checks.d, and a YAML file containing the configuration for the plugin is placed in /etc/monasca/agent/conf.d. The YAML file must have the same stem name as the plugin script.
### AgentCheck Interface ### AgentCheck Interface
Most monasca-agent plugin code uses the AgentCheck interface. All custom checks inherit from the AgentCheck class found in monagent/collector/checks/__init__.py and require a check() method that takes one argument, instance, which is a dict specifying the configuration of the instance on behalf of the plugin being executed. The check() method is run once per instance defined in the check's configuration (discussed later). Most monasca-agent plugin code uses the AgentCheck interface. All custom checks inherit from the AgentCheck class found in monasca_agent/collector/checks/__init__.py and require a check() method that takes one argument, instance, which is a dict specifying the configuration of the instance on behalf of the plugin being executed. The check() method is run once per instance defined in the check's configuration (discussed later).
### ServicesCheck interface ### ServicesCheck interface
Some monasca-agent plugins use the ServicesCheck class found in monagent/collector/services_checks.py. These require a _check() method that is similar to AgentCheck's check(), but instead of being called once per iteration in a linear fashion, it is run against a threadpool to allow concurrent instances to be checked. Also, _check() must return a tuple consisting of either Status.UP or 'Status.DOWN(frommonagent.collector.checks.services_checks`), plus a text description. Some monasca-agent plugins use the ServicesCheck class found in monasca_agent/collector/services_checks.py. These require a _check() method that is similar to AgentCheck's check(), but instead of being called once per iteration in a linear fashion, it is run against a threadpool to allow concurrent instances to be checked. Also, _check() must return a tuple consisting of either Status.UP or 'Status.DOWN(from monasca_agent.collector.checks.services_checks`), plus a text description.
The size of the threadpool is either 6 or the total number of instances, whichever is lower. This may be adjusted with the threads_count parameter in the plugin's init_config (see Plugin Configuration below). The size of the threadpool is either 6 or the total number of instances, whichever is lower. This may be adjusted with the threads_count parameter in the plugin's init_config (see Plugin Configuration below).
@ -965,7 +965,7 @@ The following ceilometer processes are monitored, if they exist when the monasca
The Libvirt plugin provides metrics for virtual machines when run on the hypervisor server. It provides two sets of metrics per measurement: one designed for the owner of the VM, and one intended for the owner of the hypervisor server. The Libvirt plugin provides metrics for virtual machines when run on the hypervisor server. It provides two sets of metrics per measurement: one designed for the owner of the VM, and one intended for the owner of the hypervisor server.
### Configuration ### Configuration
The `monasca-setup` program will configure the Libvirt plugin if `nova-api` is running, `/etc/nova/nova.conf` exists, and `python-novaclient` is installed. It uses a cache directory to persist data, which is `/dev/shm` by default. On non-Linux systems (BSD, Mac OSX), `/dev/shm` may not exist, so `cache_dir` would need to be changed accordingly, either in `monsetup/detection/plugins/libvirt.py` prior to running `monasca-setup`, or `/etc/monasca/agent/conf.d/libvirt.yaml` afterwards. The `monasca-setup` program will configure the Libvirt plugin if `nova-api` is running, `/etc/nova/nova.conf` exists, and `python-novaclient` is installed. It uses a cache directory to persist data, which is `/dev/shm` by default. On non-Linux systems (BSD, Mac OSX), `/dev/shm` may not exist, so `cache_dir` would need to be changed accordingly, either in `monasca_setup/detection/plugins/libvirt.py` prior to running `monasca-setup`, or `/etc/monasca/agent/conf.d/libvirt.yaml` afterwards.
`nova_refresh` specifies the number of seconds between calls to the Nova API to refresh the instance cache. This is helpful for updating VM hostname and pruning deleted instances from the cache. By default, it is set to 14,400 seconds (four hours). Set to 0 to refresh every time the Collector runs, or to None to disable regular refreshes entirely (though the instance cache will still be refreshed if a new instance is detected). `nova_refresh` specifies the number of seconds between calls to the Nova API to refresh the instance cache. This is helpful for updating VM hostname and pruning deleted instances from the cache. By default, it is set to 14,400 seconds (four hours). Set to 0 to refresh every time the Collector runs, or to None to disable regular refreshes entirely (though the instance cache will still be refreshed if a new instance is detected).

View File

@ -79,24 +79,24 @@ use_mount: no
# non_local_traffic: no # non_local_traffic: no
# ========================================================================== # # ========================================================================== #
# MonStatsd configuration # # Monasca Statsd configuration #
# ========================================================================== # # ========================================================================== #
# MonStatsd is a small server that aggregates your custom app metrics. # Monasca Statsd is a small server that aggregates your custom app metrics.
# Make sure your client is sending to the same port. # Make sure your client is sending to the same port.
monstatsd_port : 8125 monasca_statsd_port : 8125
## The monstatsd flush period. ## The monasca_statsd flush period.
# monstatsd_interval : 10 # monasca_statsd_interval : 10
## If 'yes', counters and rates will be normalized to 1 second (that is divided ## If 'yes', counters and rates will be normalized to 1 second (that is divided
## by the monstatsd_interval) before being sent to the server. Defaults to 'yes' ## by the monasca_statsd_interval) before being sent to the server. Defaults to 'yes'
# monstatsd_normalize : yes # monasca_statsd_normalize : yes
# If you want to forward every packet received by the monstatsd server # If you want to forward every packet received by the monasca_statsd server
# to another statsd server, uncomment these lines. # to another statsd server, uncomment these lines.
# WARNING: Make sure that forwarded packets are regular statsd packets and not "monstatsd" packets, # WARNING: Make sure that forwarded packets are regular statsd packets and not "monasca_statsd" packets,
# as your other statsd server might not be able to handle them. # as your other statsd server might not be able to handle them.
# statsd_forward_host: address_of_own_statsd_server # statsd_forward_host: address_of_own_statsd_server
# statsd_forward_port: 8125 # statsd_forward_port: 8125
@ -155,7 +155,7 @@ log_level: INFO
collector_log_file: /var/log/monasca/agent/collector.log collector_log_file: /var/log/monasca/agent/collector.log
forwarder_log_file: /var/log/monasca/agent/forwarder.log forwarder_log_file: /var/log/monasca/agent/forwarder.log
monstatsd_log_file: /var/log/monasca/agent/monstatsd.log statsd_log_file: /var/log/monasca/agent/statsd.log
# if syslog is enabled but a host and port are not set, a local domain socket # if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted # connection will be attempted

View File

@ -15,10 +15,11 @@ import traceback
import yaml import yaml
from monagent.common.aggregator import MetricsAggregator from monasca_agent.common.keystone import Keystone
import monagent.common.config from monasca_agent.common.aggregator import MetricsAggregator
import monagent.common.exceptions import monasca_agent.common.config
import monagent.common.util import monasca_agent.common.exceptions
import monasca_agent.common.util
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -52,7 +53,7 @@ class Check(object):
self._counters = {} # metric_name: bool self._counters = {} # metric_name: bool
self.logger = logger self.logger = logger
try: try:
self.logger.addFilter(monagent.common.util.LaconicFilter()) self.logger.addFilter(monasca_agent.common.util.LaconicFilter())
except Exception: except Exception:
self.logger.exception("Trying to install laconic log filter and failed") self.logger.exception("Trying to install laconic log filter and failed")
@ -127,11 +128,11 @@ class Check(object):
if timestamp is None: if timestamp is None:
timestamp = time.time() timestamp = time.time()
if metric not in self._sample_store: if metric not in self._sample_store:
raise monagent.common.exceptions.CheckException("Saving a sample for an undefined metric: %s" % metric) raise monasca_agent.common.exceptions.CheckException("Saving a sample for an undefined metric: %s" % metric)
try: try:
value = monagent.common.util.cast_metric_val(value) value = monasca_agent.common.util.cast_metric_val(value)
except ValueError as ve: except ValueError as ve:
raise monagent.common.exceptions.NaN(ve) raise monasca_agent.common.exceptions.NaN(ve)
# Sort and validate dimensions # Sort and validate dimensions
self._set_dimensions(dimensions) self._set_dimensions(dimensions)
@ -147,8 +148,8 @@ class Check(object):
self._sample_store[metric][key] = self._sample_store[metric][key][-1:] + \ self._sample_store[metric][key] = self._sample_store[metric][key][-1:] + \
[(timestamp, value, hostname, device_name)] [(timestamp, value, hostname, device_name)]
else: else:
raise monagent.common.exceptions.CheckException("%s must be either gauge or counter, skipping sample at %s" % raise monasca_agent.common.exceptions.CheckException("%s must be either gauge or counter, skipping sample at %s" %
(metric, time.ctime(timestamp))) (metric, time.ctime(timestamp)))
if self.is_gauge(metric): if self.is_gauge(metric):
# store[metric][dimensions] = (ts, val) - only 1 value allowed # store[metric][dimensions] = (ts, val) - only 1 value allowed
@ -169,19 +170,19 @@ class Check(object):
try: try:
interval = sample2[0] - sample1[0] interval = sample2[0] - sample1[0]
if interval == 0: if interval == 0:
raise monagent.common.exceptions.Infinity() raise monasca_agent.common.exceptions.Infinity()
delta = sample2[1] - sample1[1] delta = sample2[1] - sample1[1]
if delta < 0: if delta < 0:
raise monagent.common.exceptions.UnknownValue() raise monasca_agent.common.exceptions.UnknownValue()
return (sample2[0], delta / interval, sample2[2], sample2[3]) return (sample2[0], delta / interval, sample2[2], sample2[3])
except monagent.common.exceptions.Infinity: except monasca_agent.common.exceptions.Infinity:
raise raise
except monagent.common.exceptions.UnknownValue: except monasca_agent.common.exceptions.UnknownValue:
raise raise
except Exception as e: except Exception as e:
raise monagent.common.exceptions.NaN(e) raise monasca_agent.common.exceptions.NaN(e)
def get_sample_with_timestamp(self, metric, dimensions=None, device_name=None, expire=True): def get_sample_with_timestamp(self, metric, dimensions=None, device_name=None, expire=True):
"""Get (timestamp-epoch-style, value). """Get (timestamp-epoch-style, value).
@ -192,11 +193,11 @@ class Check(object):
# Never seen this metric # Never seen this metric
if metric not in self._sample_store: if metric not in self._sample_store:
raise monagent.common.exceptions.UnknownValue() raise monasca_agent.common.exceptions.UnknownValue()
# Not enough value to compute rate # Not enough value to compute rate
elif self.is_counter(metric) and len(self._sample_store[metric][key]) < 2: elif self.is_counter(metric) and len(self._sample_store[metric][key]) < 2:
raise monagent.common.exceptions.UnknownValue() raise monasca_agent.common.exceptions.UnknownValue()
elif self.is_counter(metric) and len(self._sample_store[metric][key]) >= 2: elif self.is_counter(metric) and len(self._sample_store[metric][key]) >= 2:
res = self._rate( res = self._rate(
@ -209,7 +210,7 @@ class Check(object):
return self._sample_store[metric][key][-1] return self._sample_store[metric][key][-1]
else: else:
raise monagent.common.exceptions.UnknownValue() raise monasca_agent.common.exceptions.UnknownValue()
def get_sample(self, metric, dimensions=None, device_name=None, expire=True): def get_sample(self, metric, dimensions=None, device_name=None, expire=True):
"""Return the last value for that metric. """Return the last value for that metric.
@ -259,7 +260,7 @@ class Check(object):
try: try:
ts, val, hostname, device_name = self.get_sample_with_timestamp( ts, val, hostname, device_name = self.get_sample_with_timestamp(
m, dimensions, device_name, expire) m, dimensions, device_name, expire)
except monagent.common.exceptions.UnknownValue: except monasca_agent.common.exceptions.UnknownValue:
continue continue
attributes = {} attributes = {}
if dimensions_list: if dimensions_list:
@ -289,7 +290,7 @@ class AgentCheck(object):
self.name = name self.name = name
self.init_config = init_config self.init_config = init_config
self.agent_config = agent_config self.agent_config = agent_config
self.hostname = monagent.common.util.get_hostname(agent_config) self.hostname = monasca_agent.common.util.get_hostname(agent_config)
self.log = logging.getLogger('%s.%s' % (__name__, name)) self.log = logging.getLogger('%s.%s' % (__name__, name))
self.aggregator = MetricsAggregator(self.hostname, self.aggregator = MetricsAggregator(self.hostname,
@ -455,7 +456,7 @@ class AgentCheck(object):
"""Get all metrics, including the ones that are tagged. """Get all metrics, including the ones that are tagged.
@return the list of samples @return the list of samples
@rtype list of Measurement objects from monagent.common.metrics @rtype list of Measurement objects from monasca_agent.common.metrics
""" """
if prettyprint: if prettyprint:
metrics = self.aggregator.flush() metrics = self.aggregator.flush()
@ -528,18 +529,18 @@ class AgentCheck(object):
try: try:
self.check(instance) self.check(instance)
if self.has_warnings(): if self.has_warnings():
instance_status = monagent.common.check_status.InstanceStatus(i, instance_status = monasca_agent.common.check_status.InstanceStatus(i,
monagent.common.check_status.STATUS_WARNING, monasca_agent.common.check_status.STATUS_WARNING,
warnings=self.get_warnings()) warnings=self.get_warnings())
else: else:
instance_status = monagent.common.check_status.InstanceStatus(i, instance_status = monasca_agent.common.check_status.InstanceStatus(i,
monagent.common.check_status.STATUS_OK) monasca_agent.common.check_status.STATUS_OK)
except Exception as e: except Exception as e:
self.log.exception("Check '%s' instance #%s failed" % (self.name, i)) self.log.exception("Check '%s' instance #%s failed" % (self.name, i))
instance_status = monagent.common.check_status.InstanceStatus(i, instance_status = monasca_agent.common.check_status.InstanceStatus(i,
monagent.common.check_status.STATUS_ERROR, monasca_agent.common.check_status.STATUS_ERROR,
error=e, error=e,
tb=traceback.format_exc()) tb=traceback.format_exc())
instance_statuses.append(instance_status) instance_statuses.append(instance_status)
return instance_statuses return instance_statuses
@ -622,7 +623,7 @@ def run_check(name, path=None):
import tests.common import tests.common
# Read the config file # Read the config file
confd_path = path or os.path.join(monagent.common.config.get_confd_path(monagent.common.util.get_os()), confd_path = path or os.path.join(monasca_agent.common.config.get_confd_path(monasca_agent.common.util.get_os()),
'%s.yaml' % name) '%s.yaml' % name)
try: try:

View File

@ -6,9 +6,9 @@ import system.win32 as w32
import threading import threading
import time import time
import monagent.common.check_status import monasca_agent.common.check_status
import monagent.common.metrics import monasca_agent.common.metrics
import monagent.common.util import monasca_agent.common.util
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -32,7 +32,7 @@ class Collector(object):
def __init__(self, agent_config, emitter, checksd=None): def __init__(self, agent_config, emitter, checksd=None):
self.emit_duration = None self.emit_duration = None
self.agent_config = agent_config self.agent_config = agent_config
self.os = monagent.common.util.get_os() self.os = monasca_agent.common.util.get_os()
self.plugins = None self.plugins = None
self.emitter = emitter self.emitter = emitter
socket.setdefaulttimeout(15) socket.setdefaulttimeout(15)
@ -79,18 +79,18 @@ class Collector(object):
# Don't try to send to an emitter if we're stopping/ # Don't try to send to an emitter if we're stopping/
if self.continue_running: if self.continue_running:
name = self.emitter.__name__ name = self.emitter.__name__
emitter_status = monagent.common.check_status.EmitterStatus(name) emitter_status = monasca_agent.common.check_status.EmitterStatus(name)
try: try:
self.emitter(payload, log, self.agent_config['forwarder_url']) self.emitter(payload, log, self.agent_config['forwarder_url'])
except Exception as e: except Exception as e:
log.exception("Error running emitter: %s" % self.emitter.__name__) log.exception("Error running emitter: %s" % self.emitter.__name__)
emitter_status = monagent.common.check_status.EmitterStatus(name, e) emitter_status = monasca_agent.common.check_status.EmitterStatus(name, e)
statuses.append(emitter_status) statuses.append(emitter_status)
return statuses return statuses
def _set_status(self, check_statuses, emitter_statuses, collect_duration): def _set_status(self, check_statuses, emitter_statuses, collect_duration):
try: try:
monagent.common.check_status.CollectorStatus(check_statuses, emitter_statuses).persist() monasca_agent.common.check_status.CollectorStatus(check_statuses, emitter_statuses).persist()
except Exception: except Exception:
log.exception("Error persisting collector status") log.exception("Error persisting collector status")
@ -129,7 +129,7 @@ class Collector(object):
There are currently two types of checks the system checks and the configured ones from checks_d There are currently two types of checks the system checks and the configured ones from checks_d
""" """
timer = monagent.common.util.Timer() timer = monasca_agent.common.util.Timer()
self.run_count += 1 self.run_count += 1
log.debug("Starting collection run #%s" % self.run_count) log.debug("Starting collection run #%s" % self.run_count)
@ -142,12 +142,12 @@ class Collector(object):
for check_type in self._legacy_checks: for check_type in self._legacy_checks:
try: try:
for name, value in check_type.check().iteritems(): for name, value in check_type.check().iteritems():
metrics_list.append(monagent.common.metrics.Measurement(name, metrics_list.append(monasca_agent.common.metrics.Measurement(name,
timestamp, timestamp,
value, value,
{'component': 'monasca-agent', {'component': 'monasca-agent',
'service': 'monitoring'}, 'service': 'monitoring'},
None)) None))
except Exception: except Exception:
log.exception('Error running check.') log.exception('Error running check.')
@ -166,12 +166,12 @@ class Collector(object):
# Add in metrics on the collector run, emit_duration is from the previous run # Add in metrics on the collector run, emit_duration is from the previous run
for name, value in self.collector_stats(len(metrics_list), len(events), for name, value in self.collector_stats(len(metrics_list), len(events),
collect_duration, self.emit_duration).iteritems(): collect_duration, self.emit_duration).iteritems():
metrics_list.append(monagent.common.metrics.Measurement(name, metrics_list.append(monasca_agent.common.metrics.Measurement(name,
timestamp, timestamp,
value, value,
{'component': 'monasca-agent', {'component': 'monasca-agent',
'service': 'monitoring'}, 'service': 'monitoring'},
None)) None))
emitter_statuses = self._emit(metrics_list) emitter_statuses = self._emit(metrics_list)
self.emit_duration = timer.step() self.emit_duration = timer.step()
@ -215,16 +215,16 @@ class Collector(object):
except Exception: except Exception:
log.exception("Error running check %s" % check.name) log.exception("Error running check %s" % check.name)
check_status = monagent.common.check_status.CheckStatus(check.name, instance_statuses, metric_count, event_count, check_status = monasca_agent.common.check_status.CheckStatus(check.name, instance_statuses, metric_count, event_count,
library_versions=check.get_library_info()) library_versions=check.get_library_info())
check_statuses.append(check_status) check_statuses.append(check_status)
for check_name, info in self.init_failed_checks_d.iteritems(): for check_name, info in self.init_failed_checks_d.iteritems():
if not self.continue_running: if not self.continue_running:
return return
check_status = monagent.common.check_status.CheckStatus(check_name, None, None, None, check_status = monasca_agent.common.check_status.CheckStatus(check_name, None, None, None,
init_failed_error=info['error'], init_failed_error=info['error'],
init_failed_traceback=info['traceback']) init_failed_traceback=info['traceback'])
check_statuses.append(check_status) check_statuses.append(check_status)
return measurements, events, check_statuses return measurements, events, check_statuses

View File

@ -5,8 +5,8 @@ import re
import time import time
import traceback import traceback
import monagent.collector import monasca_agent.collector
import monagent.common.util import monasca_agent.common.util
import utils import utils
@ -111,7 +111,7 @@ class Dogstream(object):
if parser_spec: if parser_spec:
try: try:
parse_func = monagent.collector.modules.load(parser_spec, 'parser') parse_func = monasca_agent.collector.modules.load(parser_spec, 'parser')
if isinstance(parse_func, type): if isinstance(parse_func, type):
logger.info('Instantiating class-based dogstream') logger.info('Instantiating class-based dogstream')
parse_func = parse_func( parse_func = parse_func(
@ -142,7 +142,7 @@ class Dogstream(object):
self.class_based = class_based self.class_based = class_based
# Apply LaconicFilter to avoid log flooding # Apply LaconicFilter to avoid log flooding
self.logger.addFilter(monagent.common.util.LaconicFilter("dogstream")) self.logger.addFilter(monasca_agent.common.util.LaconicFilter("dogstream"))
self.log_path = log_path self.log_path = log_path
self.parse_func = parse_func or self._default_line_parser self.parse_func = parse_func or self._default_line_parser

View File

@ -3,8 +3,8 @@ import Queue
import threading import threading
import time import time
import monagent.collector.checks import monasca_agent.collector.checks
import monagent.collector.checks.libs.thread_pool import monasca_agent.collector.checks.libs.thread_pool
TIMEOUT = 180 TIMEOUT = 180
@ -17,7 +17,7 @@ Status = up_down('UP', 'DOWN')
EventType = up_down("servicecheck.state_change.up", "servicecheck.state_change.down") EventType = up_down("servicecheck.state_change.up", "servicecheck.state_change.down")
class ServicesCheck(monagent.collector.checks.AgentCheck): class ServicesCheck(monasca_agent.collector.checks.AgentCheck):
SOURCE_TYPE_NAME = 'servicecheck' SOURCE_TYPE_NAME = 'servicecheck'
"""Services checks inherits from this class. """Services checks inherits from this class.
@ -39,7 +39,7 @@ class ServicesCheck(monagent.collector.checks.AgentCheck):
""" """
def __init__(self, name, init_config, agentConfig, instances): def __init__(self, name, init_config, agentConfig, instances):
monagent.collector.checks.AgentCheck.__init__(self, name, init_config, agentConfig, instances) monasca_agent.collector.checks.AgentCheck.__init__(self, name, init_config, agentConfig, instances)
# A dictionary to keep track of service statuses # A dictionary to keep track of service statuses
self.statuses = {} self.statuses = {}
@ -59,7 +59,7 @@ class ServicesCheck(monagent.collector.checks.AgentCheck):
default_size = min(self.instance_count(), DEFAULT_SIZE_POOL) default_size = min(self.instance_count(), DEFAULT_SIZE_POOL)
self.pool_size = int(self.init_config.get('threads_count', default_size)) self.pool_size = int(self.init_config.get('threads_count', default_size))
self.pool = monagent.collector.checks.libs.thread_pool.Pool(self.pool_size) self.pool = monasca_agent.collector.checks.libs.thread_pool.Pool(self.pool_size)
self.resultsq = Queue.Queue() self.resultsq = Queue.Queue()
self.jobs_status = {} self.jobs_status = {}

View File

@ -13,16 +13,16 @@ import time
# project # project
import monagent.collector.checks.check import monasca_agent.collector.checks.check
import monagent.common.metrics import monasca_agent.common.metrics
import monagent.common.util import monasca_agent.common.util
# locale-resilient float converter # locale-resilient float converter
to_float = lambda s: float(s.replace(",", ".")) to_float = lambda s: float(s.replace(",", "."))
class Disk(monagent.collector.checks.check.Check): class Disk(monasca_agent.collector.checks.check.Check):
"""Collects metrics about the machine's disks. """Collects metrics about the machine's disks.
""" """
@ -60,13 +60,13 @@ class Disk(monagent.collector.checks.check.Check):
# parse into a list of Measurements # parse into a list of Measurements
stats.update(inodes) stats.update(inodes)
timestamp = time.time() timestamp = time.time()
measurements = [monagent.common.metrics.Measurement(key.split('.', 1)[1], measurements = [monasca_agent.common.metrics.Measurement(key.split('.', 1)[1],
timestamp, timestamp,
value, value,
{'device': key.split('.', 1)[0], {'device': key.split('.', 1)[0],
'service': 'monitoring', 'service': 'monitoring',
'component': 'monasca-agent'}, 'component': 'monasca-agent'},
None) None)
for key, value in stats.iteritems()] for key, value in stats.iteritems()]
return measurements return measurements
@ -93,14 +93,14 @@ class Disk(monagent.collector.checks.check.Check):
if use_mount: if use_mount:
parts[0] = parts[-1] parts[0] = parts[-1]
if inodes: if inodes:
if monagent.common.util.Platform.is_darwin(platform_name): if monasca_agent.common.util.Platform.is_darwin(platform_name):
# Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted # Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted
# Inodes are in position 5, 6 and we need to compute the total # Inodes are in position 5, 6 and we need to compute the total
# Total # Total
parts[1] = int(parts[5]) + int(parts[6]) # Total parts[1] = int(parts[5]) + int(parts[6]) # Total
parts[2] = int(parts[5]) # Used parts[2] = int(parts[5]) # Used
parts[3] = int(parts[6]) # Available parts[3] = int(parts[6]) # Available
elif monagent.common.util.Platform.is_freebsd(platform_name): elif monasca_agent.common.util.Platform.is_freebsd(platform_name):
# Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted # Filesystem 1K-blocks Used Avail Capacity iused ifree %iused Mounted
# Inodes are in position 5, 6 and we need to compute the total # Inodes are in position 5, 6 and we need to compute the total
parts[1] = int(parts[5]) + int(parts[6]) # Total parts[1] = int(parts[5]) + int(parts[6]) # Total
@ -207,10 +207,10 @@ class Disk(monagent.collector.checks.check.Check):
return devices return devices
class IO(monagent.collector.checks.check.Check): class IO(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.header_re = re.compile(r'([%\\/\-_a-zA-Z0-9]+)[\s+]?') self.header_re = re.compile(r'([%\\/\-_a-zA-Z0-9]+)[\s+]?')
self.item_re = re.compile(r'^([a-zA-Z0-9\/]+)') self.item_re = re.compile(r'^([a-zA-Z0-9\/]+)')
self.value_re = re.compile(r'\d+\.\d+') self.value_re = re.compile(r'\d+\.\d+')
@ -300,7 +300,7 @@ class IO(monagent.collector.checks.check.Check):
""" """
io = {} io = {}
try: try:
if monagent.common.util.Platform.is_linux(): if monasca_agent.common.util.Platform.is_linux():
stdout = sp.Popen(['iostat', '-d', '1', '2', '-x', '-k'], stdout = sp.Popen(['iostat', '-d', '1', '2', '-x', '-k'],
stdout=sp.PIPE, stdout=sp.PIPE,
close_fds=True).communicate()[0] close_fds=True).communicate()[0]
@ -412,10 +412,13 @@ class IO(monagent.collector.checks.check.Check):
for dev_name, stats in filtered_io.iteritems(): for dev_name, stats in filtered_io.iteritems():
filtered_stats = {stat: stats[stat] filtered_stats = {stat: stats[stat]
for stat in stats.iterkeys() if stat not in self.stat_blacklist} for stat in stats.iterkeys() if stat not in self.stat_blacklist}
m_list = [monagent.common.metrics.Measurement(key, timestamp, value, {'device': dev_name, m_list = [monasca_agent.common.metrics.Measurement(key,
'service': 'monitoring', timestamp,
'component': 'monasca-agent'}, value,
None) {'device': dev_name,
'service': 'monitoring',
'component': 'monasca-agent'},
None)
for key, value in filtered_stats.iteritems()] for key, value in filtered_stats.iteritems()]
measurements.extend(m_list) measurements.extend(m_list)
@ -426,10 +429,10 @@ class IO(monagent.collector.checks.check.Check):
return {} return {}
class Load(monagent.collector.checks.check.Check): class Load(monasca_agent.collector.checks.check.Check):
def check(self): def check(self):
if monagent.common.util.Platform.is_linux(): if monasca_agent.common.util.Platform.is_linux():
try: try:
loadAvrgProc = open('/proc/loadavg', 'r') loadAvrgProc = open('/proc/loadavg', 'r')
uptime = loadAvrgProc.readlines() uptime = loadAvrgProc.readlines()
@ -458,10 +461,10 @@ class Load(monagent.collector.checks.check.Check):
} }
class Memory(monagent.collector.checks.check.Check): class Memory(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
macV = None macV = None
if sys.platform == 'darwin': if sys.platform == 'darwin':
macV = platform.mac_ver() macV = platform.mac_ver()
@ -485,7 +488,7 @@ class Memory(monagent.collector.checks.check.Check):
pass pass
def check(self): def check(self):
if monagent.common.util.Platform.is_linux(): if monasca_agent.common.util.Platform.is_linux():
try: try:
meminfoProc = open('/proc/meminfo', 'r') meminfoProc = open('/proc/meminfo', 'r')
lines = meminfoProc.readlines() lines = meminfoProc.readlines()
@ -756,7 +759,7 @@ class Memory(monagent.collector.checks.check.Check):
return {} return {}
class Cpu(monagent.collector.checks.check.Check): class Cpu(monasca_agent.collector.checks.check.Check):
def check(self): def check(self):
"""Return an aggregate of CPU stats across all CPUs. """Return an aggregate of CPU stats across all CPUs.
@ -789,7 +792,7 @@ class Cpu(monagent.collector.checks.check.Check):
self.logger.debug("Cannot extract cpu value %s from %s (%s)" % (name, data, legend)) self.logger.debug("Cannot extract cpu value %s from %s (%s)" % (name, data, legend))
return 0.0 return 0.0
if monagent.common.util.Platform.is_linux(): if monasca_agent.common.util.Platform.is_linux():
mpstat = sp.Popen(['mpstat', '1', '3'], stdout=sp.PIPE, close_fds=True).communicate()[0] mpstat = sp.Popen(['mpstat', '1', '3'], stdout=sp.PIPE, close_fds=True).communicate()[0]
# topdog@ip:~$ mpstat 1 3 # topdog@ip:~$ mpstat 1 3
# Linux 2.6.32-341-ec2 (ip) 01/19/2012 _x86_64_ (2 CPU) # Linux 2.6.32-341-ec2 (ip) 01/19/2012 _x86_64_ (2 CPU)

View File

@ -1,4 +1,4 @@
import monagent.collector.checks.check import monasca_agent.collector.checks.check
try: try:
import wmi import wmi
@ -15,10 +15,10 @@ B2MB = float(1048576)
KB2MB = B2KB = float(1024) KB2MB = B2KB = float(1024)
class Processes(monagent.collector.checks.check.Check): class Processes(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.gauge('system.proc.queue_length') self.gauge('system.proc.queue_length')
self.gauge('system.proc.count') self.gauge('system.proc.count')
@ -44,10 +44,10 @@ class Processes(monagent.collector.checks.check.Check):
return self.get_metrics() return self.get_metrics()
class Memory(monagent.collector.checks.check.Check): class Memory(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.logger = logger self.logger = logger
self.gauge('system.mem.free') self.gauge('system.mem.free')
self.gauge('system.mem.used') self.gauge('system.mem.used')
@ -84,10 +84,10 @@ class Memory(monagent.collector.checks.check.Check):
return self.get_metrics() return self.get_metrics()
class Cpu(monagent.collector.checks.check.Check): class Cpu(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.logger = logger self.logger = logger
self.gauge('system.cpu.user') self.gauge('system.cpu.user')
self.gauge('system.cpu.idle') self.gauge('system.cpu.idle')
@ -143,10 +143,10 @@ class Cpu(monagent.collector.checks.check.Check):
return val return val
class Network(monagent.collector.checks.check.Check): class Network(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.logger = logger self.logger = logger
self.gauge('system.net.bytes_rcvd') self.gauge('system.net.bytes_rcvd')
self.gauge('system.net.bytes_sent') self.gauge('system.net.bytes_sent')
@ -170,10 +170,10 @@ class Network(monagent.collector.checks.check.Check):
return self.get_metrics() return self.get_metrics()
class Disk(monagent.collector.checks.check.Check): class Disk(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.logger = logger self.logger = logger
self.gauge('system.disk.free') self.gauge('system.disk.free')
self.gauge('system.disk.total') self.gauge('system.disk.total')
@ -204,10 +204,10 @@ class Disk(monagent.collector.checks.check.Check):
return self.get_metrics() return self.get_metrics()
class IO(monagent.collector.checks.check.Check): class IO(monasca_agent.collector.checks.check.Check):
def __init__(self, logger): def __init__(self, logger):
monagent.collector.checks.check.Check.__init__(self, logger) monasca_agent.collector.checks.check.Check.__init__(self, logger)
self.logger = logger self.logger = logger
self.gauge('system.io.wkb_s') self.gauge('system.io.wkb_s')
self.gauge('system.io.w_s') self.gauge('system.io.w_s')

View File

@ -1,8 +1,8 @@
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.collector.checks.utils import add_basic_auth from monasca_agent.collector.checks.utils import add_basic_auth
from monagent.common.util import headers from monasca_agent.common.util import headers
class Apache(AgentCheck): class Apache(AgentCheck):

View File

@ -3,7 +3,7 @@ from fnmatch import fnmatch
import os import os
import time import time
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
CFUNC_TO_AGGR = { CFUNC_TO_AGGR = {
'AVERAGE': 'avg', 'AVERAGE': 'avg',

View File

@ -1,8 +1,8 @@
import json import json
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import headers from monasca_agent.common.util import headers
class CouchDb(AgentCheck): class CouchDb(AgentCheck):

View File

@ -3,9 +3,9 @@ import urllib2
import re import re
import sys import sys
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.collector.checks.utils import add_basic_auth from monasca_agent.collector.checks.utils import add_basic_auth
from monagent.common.util import headers from monasca_agent.common.util import headers
# Constants # Constants

View File

@ -6,7 +6,7 @@ from os.path import exists
from os.path import join from os.path import join
import time import time
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class DirectoryCheck(AgentCheck): class DirectoryCheck(AgentCheck):

View File

@ -7,7 +7,7 @@ import urllib2
import urllib import urllib
from urlparse import urlsplit from urlparse import urlsplit
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
DEFAULT_MAX_CONTAINERS = 20 DEFAULT_MAX_CONTAINERS = 20

View File

@ -6,9 +6,9 @@ import time
import urllib2 import urllib2
import urlparse import urlparse
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.collector.checks.utils import add_basic_auth from monasca_agent.collector.checks.utils import add_basic_auth
from monagent.common.util import headers from monasca_agent.common.util import headers
class NodeNotFound(Exception): class NodeNotFound(Exception):

View File

@ -1,4 +1,4 @@
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class Gearman(AgentCheck): class Gearman(AgentCheck):

View File

@ -13,7 +13,7 @@ except ImportError:
psutil = None psutil = None
# project # project
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class GUnicornCheck(AgentCheck): class GUnicornCheck(AgentCheck):

View File

@ -2,8 +2,8 @@ from collections import defaultdict
import time import time
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import headers from monasca_agent.common.util import headers
STATS_URL = "/;csv;norefresh" STATS_URL = "/;csv;norefresh"

View File

@ -1,4 +1,4 @@
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class HDFSCheck(AgentCheck): class HDFSCheck(AgentCheck):

View File

@ -7,8 +7,8 @@ import socket
import subprocess import subprocess
import sys import sys
from monagent.collector.checks.services_checks import ServicesCheck from monasca_agent.collector.checks.services_checks import ServicesCheck
from monagent.collector.checks.services_checks import Status from monasca_agent.collector.checks.services_checks import Status
class HostAlive(ServicesCheck): class HostAlive(ServicesCheck):

View File

@ -12,10 +12,9 @@ from httplib2 import Http
from httplib2 import httplib from httplib2 import httplib
from httplib2 import HttpLib2Error from httplib2 import HttpLib2Error
from monagent.collector.checks.check import AgentCheck from monasca_agent.collector.checks.check import AgentCheck
from monagent.collector.checks.services_checks import ServicesCheck from monasca_agent.collector.checks.services_checks import ServicesCheck
from monagent.collector.checks.services_checks import Status from monasca_agent.collector.checks.services_checks import Status
from monagent.common.keystone import Keystone
class HTTPCheck(ServicesCheck): class HTTPCheck(ServicesCheck):

View File

@ -6,7 +6,7 @@ try:
except Exception: except Exception:
wmi = None wmi = None
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class IIS(AgentCheck): class IIS(AgentCheck):

View File

@ -11,8 +11,8 @@ except ImportError:
except ImportError: except ImportError:
pass pass
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import get_hostname from monasca_agent.common.util import get_hostname
class Skip(Exception): class Skip(Exception):

View File

@ -7,7 +7,7 @@ if sys.version_info < (2, 6):
raise Exception('kafka_consumer check requires at least Python 2.6') raise Exception('kafka_consumer check requires at least Python 2.6')
from collections import defaultdict from collections import defaultdict
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
try: try:
from kafka.client import KafkaClient from kafka.client import KafkaClient

View File

@ -2,7 +2,7 @@ from collections import defaultdict
import re import re
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
db_stats = re.compile(r'^db_(\d)+$') db_stats = re.compile(r'^db_(\d)+$')

View File

@ -22,8 +22,8 @@ import yaml
from calendar import timegm from calendar import timegm
from datetime import datetime from datetime import datetime
from monagent.collector.virt import inspector from monasca_agent.collector.virt import inspector
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class LibvirtCheck(AgentCheck): class LibvirtCheck(AgentCheck):

View File

@ -1,8 +1,8 @@
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.collector.checks.utils import add_basic_auth from monasca_agent.collector.checks.utils import add_basic_auth
from monagent.common.util import headers from monasca_agent.common.util import headers
class Lighttpd(AgentCheck): class Lighttpd(AgentCheck):

View File

@ -1,4 +1,4 @@
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
# Reference: http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt # Reference: http://code.sixapart.com/svn/memcached/trunk/server/doc/protocol.txt
# Name Type Meaning # Name Type Meaning

View File

@ -2,8 +2,8 @@ import re
import time import time
import types import types
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import get_hostname from monasca_agent.common.util import get_hostname
# When running with pymongo < 2.0 # When running with pymongo < 2.0

View File

@ -4,7 +4,7 @@ import subprocess
import sys import sys
import traceback import traceback
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
GAUGE = "gauge" GAUGE = "gauge"

View File

@ -11,7 +11,7 @@ import socket
import subprocess import subprocess
import time import time
from monagent.collector.checks.services_checks import ServicesCheck, Status from monasca_agent.collector.checks.services_checks import ServicesCheck, Status
class WrapNagios(ServicesCheck): class WrapNagios(ServicesCheck):

View File

@ -7,8 +7,8 @@ import re
import subprocess import subprocess
# project # project
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import Platform from monasca_agent.common.util import Platform
class Network(AgentCheck): class Network(AgentCheck):

View File

@ -1,9 +1,9 @@
import re import re
import urllib2 import urllib2
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.collector.checks.utils import add_basic_auth from monasca_agent.collector.checks.utils import add_basic_auth
from monagent.common.util import headers from monasca_agent.common.util import headers
class Nginx(AgentCheck): class Nginx(AgentCheck):

View File

@ -1,6 +1,6 @@
import os import os
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class PostfixCheck(AgentCheck): class PostfixCheck(AgentCheck):

View File

@ -1,5 +1,5 @@
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.exceptions import CheckException from monasca_agent.common.exceptions import CheckException
class ShouldRestartException(Exception): class ShouldRestartException(Exception):

View File

@ -1,8 +1,8 @@
"""Gather metrics on specific processes. """Gather metrics on specific processes.
""" """
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
from monagent.common.util import Platform from monasca_agent.common.util import Platform
class ProcessCheck(AgentCheck): class ProcessCheck(AgentCheck):

View File

@ -3,7 +3,7 @@ import time
import urllib2 import urllib2
import urlparse import urlparse
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
EVENT_TYPE = SOURCE_TYPE_NAME = 'rabbitmq' EVENT_TYPE = SOURCE_TYPE_NAME = 'rabbitmq'

View File

@ -4,7 +4,7 @@
import re import re
import time import time
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class Redis(AgentCheck): class Redis(AgentCheck):

View File

@ -5,7 +5,7 @@ import json
import socket import socket
import time import time
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class Riak(AgentCheck): class Riak(AgentCheck):

View File

@ -3,7 +3,7 @@
""" """
import traceback import traceback
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
ALL_INSTANCES = 'ALL' ALL_INSTANCES = 'ALL'

View File

@ -1,9 +1,9 @@
import socket import socket
import time import time
from monagent.collector.checks.services_checks import EventType from monasca_agent.collector.checks.services_checks import EventType
from monagent.collector.checks.services_checks import ServicesCheck from monasca_agent.collector.checks.services_checks import ServicesCheck
from monagent.collector.checks.services_checks import Status from monasca_agent.collector.checks.services_checks import Status
class BadConfException(Exception): class BadConfException(Exception):

View File

@ -2,7 +2,7 @@ import re
import subprocess import subprocess
import xml.parsers.expat # python 2.4 compatible import xml.parsers.expat # python 2.4 compatible
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class Varnish(AgentCheck): class Varnish(AgentCheck):

View File

@ -8,7 +8,7 @@ try:
except Exception: except Exception:
wmi = None wmi = None
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
SOURCE_TYPE_NAME = 'event viewer' SOURCE_TYPE_NAME = 'event viewer'
EVENT_TYPE = 'win32_log_event' EVENT_TYPE = 'win32_log_event'

View File

@ -9,7 +9,7 @@ try:
except Exception: except Exception:
wmi = None wmi = None
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
UP_METRIC = 'Up' UP_METRIC = 'Up'
SEARCH_WILDCARD = '*' SEARCH_WILDCARD = '*'

View File

@ -27,7 +27,7 @@ import socket
from StringIO import StringIO from StringIO import StringIO
import struct import struct
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
class Zookeeper(AgentCheck): class Zookeeper(AgentCheck):

View File

@ -11,14 +11,14 @@ import time
# Custom modules # Custom modules
import checks.collector import checks.collector
import jmxfetch import jmxfetch
import monagent.common.check_status import monasca_agent.common.check_status
import monagent.common.config import monasca_agent.common.config
import monagent.common.daemon import monasca_agent.common.daemon
import monagent.common.emitter import monasca_agent.common.emitter
import monagent.common.util import monasca_agent.common.util
# set up logging before importing any other components # set up logging before importing any other components
monagent.common.config.initialize_logging('collector') monasca_agent.common.config.initialize_logging('collector')
os.umask(0o22) os.umask(0o22)
# Check we're not using an old version of Python. We need 2.4 above because # Check we're not using an old version of Python. We need 2.4 above because
@ -39,14 +39,14 @@ log = logging.getLogger('collector')
# todo the collector has daemon code but is always run in foreground mode # todo the collector has daemon code but is always run in foreground mode
# from the supervisor, is there a reason for the daemon code then? # from the supervisor, is there a reason for the daemon code then?
class CollectorDaemon(monagent.common.daemon.Daemon): class CollectorDaemon(monasca_agent.common.daemon.Daemon):
"""The agent class is a daemon that runs the collector in a background process. """The agent class is a daemon that runs the collector in a background process.
""" """
def __init__(self, pidfile, autorestart, start_event=True): def __init__(self, pidfile, autorestart, start_event=True):
monagent.common.daemon.Daemon.__init__(self, pidfile, autorestart=autorestart) monasca_agent.common.daemon.Daemon.__init__(self, pidfile, autorestart=autorestart)
self.run_forever = True self.run_forever = True
self.collector = None self.collector = None
self.start_event = start_event self.start_event = start_event
@ -68,7 +68,7 @@ class CollectorDaemon(monagent.common.daemon.Daemon):
def info(self, verbose=None): def info(self, verbose=None):
logging.getLogger().setLevel(logging.ERROR) logging.getLogger().setLevel(logging.ERROR)
return monagent.common.check_status.CollectorStatus.print_latest_status(verbose=verbose) return monasca_agent.common.check_status.CollectorStatus.print_latest_status(verbose=verbose)
def run(self, config=None): def run(self, config=None):
"""Main loop of the collector. """Main loop of the collector.
@ -85,15 +85,15 @@ class CollectorDaemon(monagent.common.daemon.Daemon):
signal.signal(signal.SIGINT, self._handle_sigterm) signal.signal(signal.SIGINT, self._handle_sigterm)
# Save the agent start-up stats. # Save the agent start-up stats.
monagent.common.check_status.CollectorStatus().persist() monasca_agent.common.check_status.CollectorStatus().persist()
# Intialize the collector. # Intialize the collector.
if config is None: if config is None:
config = monagent.common.config.get_config(parse_args=True) config = monasca_agent.common.config.get_config(parse_args=True)
# Load the checks_d checks # Load the checks_d checks
checksd = monagent.common.config.load_check_directory(config) checksd = monasca_agent.common.config.load_check_directory(config)
self.collector = checks.collector.Collector(config, monagent.common.emitter.http_emitter, checksd) self.collector = checks.collector.Collector(config, monasca_agent.common.emitter.http_emitter, checksd)
# Configure the watchdog. # Configure the watchdog.
check_frequency = int(config['check_freq']) check_frequency = int(config['check_freq'])
@ -147,7 +147,7 @@ class CollectorDaemon(monagent.common.daemon.Daemon):
# Now clean-up. # Now clean-up.
try: try:
monagent.common.check_status.CollectorStatus.remove_latest_status() monasca_agent.common.check_status.CollectorStatus.remove_latest_status()
except Exception: except Exception:
pass pass
@ -160,9 +160,9 @@ class CollectorDaemon(monagent.common.daemon.Daemon):
def _get_watchdog(check_freq, agentConfig): def _get_watchdog(check_freq, agentConfig):
watchdog = None watchdog = None
if agentConfig.get("watchdog", True): if agentConfig.get("watchdog", True):
watchdog = monagent.common.util.Watchdog(check_freq * WATCHDOG_MULTIPLIER, watchdog = monasca_agent.common.util.Watchdog(check_freq * WATCHDOG_MULTIPLIER,
max_mem_mb=agentConfig.get('limit_memory_consumption', max_mem_mb=agentConfig.get('limit_memory_consumption',
None)) None))
watchdog.reset() watchdog.reset()
return watchdog return watchdog
@ -175,12 +175,12 @@ class CollectorDaemon(monagent.common.daemon.Daemon):
log.info("Running an auto-restart.") log.info("Running an auto-restart.")
if self.collector: if self.collector:
self.collector.stop() self.collector.stop()
sys.exit(monagent.common.daemon.AgentSupervisor.RESTART_EXIT_STATUS) sys.exit(monasca_agent.common.daemon.AgentSupervisor.RESTART_EXIT_STATUS)
def main(): def main():
options, args = monagent.common.config.get_parsed_args() options, args = monasca_agent.common.config.get_parsed_args()
agentConfig = monagent.common.config.get_config(options=options) agentConfig = monasca_agent.common.config.get_config(options=options)
# todo autorestart isn't used remove # todo autorestart isn't used remove
autorestart = agentConfig.get('autorestart', False) autorestart = agentConfig.get('autorestart', False)
@ -206,7 +206,7 @@ def main():
sys.stderr.write("Unknown command: %s\n" % command) sys.stderr.write("Unknown command: %s\n" % command)
return 3 return 3
pid_file = monagent.common.util.PidFile('monasca-agent') pid_file = monasca_agent.common.util.PidFile('monasca-agent')
if options.clean: if options.clean:
pid_file.clean() pid_file.clean()
@ -214,7 +214,7 @@ def main():
agent = CollectorDaemon(pid_file.get_path(), autorestart) agent = CollectorDaemon(pid_file.get_path(), autorestart)
if command in START_COMMANDS: if command in START_COMMANDS:
log.info('Agent version %s' % monagent.common.config.get_version()) log.info('Agent version %s' % monasca_agent.common.config.get_version())
if 'start' == command: if 'start' == command:
log.info('Start daemon') log.info('Start daemon')
@ -246,14 +246,14 @@ def main():
def parent_func(): def parent_func():
agent.start_event = False agent.start_event = False
monagent.common.daemon.AgentSupervisor.start(parent_func, child_func) monasca_agent.common.daemon.AgentSupervisor.start(parent_func, child_func)
else: else:
# Run in the standard foreground. # Run in the standard foreground.
agent.run(config=agentConfig) agent.run(config=agentConfig)
elif 'check' == command: elif 'check' == command:
check_name = args[1] check_name = args[1]
checks = monagent.common.config.load_check_directory(agentConfig) checks = monasca_agent.common.config.load_check_directory(agentConfig)
for check in checks['initialized_checks']: for check in checks['initialized_checks']:
if check.name == check_name: if check.name == check_name:
check.run() check.run()
@ -268,7 +268,7 @@ def main():
elif 'check_all' == command: elif 'check_all' == command:
print("Loading check directory...") print("Loading check directory...")
checks = monagent.common.config.load_check_directory(agentConfig) checks = monasca_agent.common.config.load_check_directory(agentConfig)
print("...directory loaded.\n") print("...directory loaded.\n")
for check in checks['initialized_checks']: for check in checks['initialized_checks']:
print("#" * 80) print("#" * 80)
@ -279,12 +279,12 @@ def main():
print("#" * 80 + "\n\n") print("#" * 80 + "\n\n")
elif 'configcheck' == command or 'configtest' == command: elif 'configcheck' == command or 'configtest' == command:
osname = monagent.common.util.get_os() osname = monasca_agent.common.util.get_os()
all_valid = True all_valid = True
for conf_path in glob.glob(os.path.join(monagent.common.config.get_confd_path(osname), "*.yaml")): for conf_path in glob.glob(os.path.join(monasca_agent.common.config.get_confd_path(osname), "*.yaml")):
basename = os.path.basename(conf_path) basename = os.path.basename(conf_path)
try: try:
monagent.common.config.check_yaml(conf_path) monasca_agent.common.config.check_yaml(conf_path)
except Exception as e: except Exception as e:
all_valid = False all_valid = False
print("%s contains errors:\n %s" % (basename, e)) print("%s contains errors:\n %s" % (basename, e))
@ -316,11 +316,11 @@ def main():
else: else:
jmx_command = args[1] jmx_command = args[1]
checks_list = args[2:] checks_list = args[2:]
confd_directory = monagent.common.config.get_confd_path(monagent.common.util.get_os()) confd_directory = monasca_agent.common.config.get_confd_path(monasca_agent.common.util.get_os())
should_run = jmxfetch.JMXFetch.init( should_run = jmxfetch.JMXFetch.init(
confd_directory, confd_directory,
agentConfig, agentConfig,
monagent.common.config.get_logging_config(), monasca_agent.common.config.get_logging_config(),
15, 15,
jmx_command, jmx_command,
checks_list, checks_list,

View File

@ -1,7 +1,7 @@
from datetime import datetime from datetime import datetime
import re import re
from monagent.collector.dogstream import common from monasca_agent.collector.dogstream import common
LOG4J_PRIORITY = [ LOG4J_PRIORITY = [

View File

@ -8,7 +8,7 @@ import time
import yaml import yaml
import monagent.common.util import monasca_agent.common.util
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -50,7 +50,7 @@ class InvalidJMXConfiguration(Exception):
class JMXFetch(object): class JMXFetch(object):
pid_file = monagent.common.util.PidFile("jmxfetch") pid_file = monasca_agent.common.util.PidFile("jmxfetch")
pid_file_path = pid_file.get_path() pid_file_path = pid_file.get_path()
@classmethod @classmethod
@ -234,7 +234,7 @@ class JMXFetch(object):
except Exception: except Exception:
return False return False
if monagent.common.util.get_os() != 'windows': if monasca_agent.common.util.get_os() != 'windows':
try: try:
os.kill(pid, 0) os.kill(pid, 0)
# os.kill(pid, 0) will throw an exception if pid is not running # os.kill(pid, 0) will throw an exception if pid is not running
@ -290,7 +290,7 @@ class JMXFetch(object):
@classmethod @classmethod
def get_path_to_jmxfetch(cls): def get_path_to_jmxfetch(cls):
if monagent.common.util.get_os() != 'windows': if monasca_agent.common.util.get_os() != 'windows':
return os.path.realpath( return os.path.realpath(
os.path.join(os.path.abspath(__file__), "..", "../collector/checks", "libs", os.path.join(os.path.abspath(__file__), "..", "../collector/checks", "libs",
JMX_FETCH_JAR_NAME)) JMX_FETCH_JAR_NAME))
@ -301,7 +301,7 @@ class JMXFetch(object):
@classmethod @classmethod
def start(cls, confd_path, agentConfig, logging_config, path_to_java, java_run_opts, def start(cls, confd_path, agentConfig, logging_config, path_to_java, java_run_opts,
default_check_frequency, jmx_checks, command, reporter=None): default_check_frequency, jmx_checks, command, reporter=None):
statsd_port = agentConfig.get('monstatsd_port', "8125") statsd_port = agentConfig.get('monasca_statsd_port', "8125")
if reporter is None: if reporter is None:
reporter = "statsd:%s" % str(statsd_port) reporter = "statsd:%s" % str(statsd_port)

View File

@ -18,8 +18,8 @@
from oslo.utils import units from oslo.utils import units
from monagent.collector.virt.hyperv import utilsv2 from monasca_agent.collector.virt.hyperv import utilsv2
from monagent.collector.virt import inspector as virt_inspector from monasca_agent.collector.virt import inspector as virt_inspector
class HyperVInspector(virt_inspector.Inspector): class HyperVInspector(virt_inspector.Inspector):

View File

@ -25,7 +25,7 @@ import sys
if sys.platform == 'win32': if sys.platform == 'win32':
import wmi import wmi
from monagent.collector.virt import inspector from monasca_agent.collector.virt import inspector
class HyperVException(inspector.InspectorException): class HyperVException(inspector.InspectorException):

View File

@ -215,7 +215,7 @@ class Inspector(object):
def get_hypervisor_inspector(): def get_hypervisor_inspector():
try: try:
namespace = 'monagent.collector.virt' namespace = 'monasca_agent.collector.virt'
mgr = driver.DriverManager(namespace, mgr = driver.DriverManager(namespace,
cfg.CONF.hypervisor_inspector, cfg.CONF.hypervisor_inspector,
invoke_on_load=True) invoke_on_load=True)

View File

@ -20,7 +20,7 @@ from lxml import etree
from oslo.config import cfg from oslo.config import cfg
import six import six
from monagent.collector.virt import inspector as virt_inspector from monasca_agent.collector.virt import inspector as virt_inspector
libvirt = None libvirt = None

View File

@ -19,8 +19,8 @@ from oslo.config import cfg
from oslo.utils import units from oslo.utils import units
from oslo.vmware import api from oslo.vmware import api
from monagent.collector.virt import inspector as virt_inspector from monasca_agent.collector.virt import inspector as virt_inspector
from monagent.collector.virt.vmware import vsphere_operations from monasca_agent.collector.virt.vmware import vsphere_operations
opt_group = cfg.OptGroup(name='vmware', opt_group = cfg.OptGroup(name='vmware',

View File

@ -24,7 +24,7 @@ except ImportError:
api = None api = None
from ceilometer.compute.pollsters import util from ceilometer.compute.pollsters import util
from monagent.collector.virt import inspector as virt_inspector from monasca_agent.collector.virt import inspector as virt_inspector
opt_group = cfg.OptGroup(name='xenapi', opt_group = cfg.OptGroup(name='xenapi',
title='Options for XenAPI') title='Options for XenAPI')

View File

@ -1,9 +1,9 @@
""" Aggregation classes used by the collector and monstatsd to batch messages sent to the forwarder. """ Aggregation classes used by the collector and statsd to batch messages sent to the forwarder.
""" """
import logging import logging
from time import time from time import time
from monagent.common.metrics import Gauge, BucketGauge, Counter, Histogram, Measurement, Set, Rate from monasca_agent.common.metrics import Gauge, BucketGauge, Counter, Histogram, Measurement, Set, Rate
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -512,9 +512,9 @@ class CollectorStatus(AgentStatus):
return status_info return status_info
class MonstatsdStatus(AgentStatus): class MonascaStatsdStatus(AgentStatus):
NAME = 'Monstatsd' NAME = 'Monasca_Statsd'
def __init__(self, flush_count=0, packet_count=0, def __init__(self, flush_count=0, packet_count=0,
packets_per_second=0, metric_count=0, event_count=0): packets_per_second=0, metric_count=0, event_count=0):

View File

@ -25,7 +25,7 @@ except ImportError:
# project # project
from util import get_os from util import get_os
from monagent.collector.jmxfetch import JMXFetch, JMX_COLLECT_COMMAND from monasca_agent.collector.jmxfetch import JMXFetch, JMX_COLLECT_COMMAND
# CONSTANTS # CONSTANTS
AGENT_CONF = "agent.conf" AGENT_CONF = "agent.conf"
@ -190,10 +190,10 @@ def get_config(parse_args=True, cfg_path=None, options=None):
# General config # General config
agent_config = { agent_config = {
'check_freq': DEFAULT_CHECK_FREQUENCY, 'check_freq': DEFAULT_CHECK_FREQUENCY,
'monstatsd_interval': DEFAULT_STATSD_FREQUENCY, 'monasca_statsd_interval': DEFAULT_STATSD_FREQUENCY,
'monstatsd_agregator_bucket_size': DEFAULT_STATSD_BUCKET_SIZE, 'monasca_statsd_agregator_bucket_size': DEFAULT_STATSD_BUCKET_SIZE,
'monstatsd_normalize': 'yes', 'monasca_statsd_normalize': 'yes',
'monstatsd_port': 8125, 'monasca_statsd_port': 8125,
'forwarder_url': 'http://localhost:17123', 'forwarder_url': 'http://localhost:17123',
'hostname': None, 'hostname': None,
'listen_port': None, 'listen_port': None,
@ -202,8 +202,8 @@ def get_config(parse_args=True, cfg_path=None, options=None):
'additional_checksd': DEFAULT_CONFIG_DIR + '/checks_d/', 'additional_checksd': DEFAULT_CONFIG_DIR + '/checks_d/',
} }
monstatsd_interval = DEFAULT_STATSD_FREQUENCY monasca_statsd_interval = DEFAULT_STATSD_FREQUENCY
monstatsd_agregator_bucket_size = DEFAULT_STATSD_BUCKET_SIZE monasca_statsd_agregator_bucket_size = DEFAULT_STATSD_BUCKET_SIZE
# Config handling # Config handling
try: try:
@ -258,14 +258,14 @@ def get_config(parse_args=True, cfg_path=None, options=None):
if config.get('Main', 'watchdog').lower() in ('no', 'false'): if config.get('Main', 'watchdog').lower() in ('no', 'false'):
agent_config['watchdog'] = False agent_config['watchdog'] = False
# monstatsd config # monasca_statsd config
monstatsd_defaults = { monasca_statsd_defaults = {
'monstatsd_port': 8125, 'monasca_statsd_port': 8125,
'monstatsd_interval': monstatsd_interval, 'monasca_statsd_interval': monasca_statsd_interval,
'monstatsd_agregator_bucket_size': monstatsd_agregator_bucket_size, 'monasca_statsd_agregator_bucket_size': monasca_statsd_agregator_bucket_size,
'monstatsd_normalize': 'yes', 'monasca_statsd_normalize': 'yes',
} }
for key, value in monstatsd_defaults.iteritems(): for key, value in monasca_statsd_defaults.iteritems():
if config.has_option('Main', key): if config.has_option('Main', key):
agent_config[key] = config.get('Main', key) agent_config[key] = config.get('Main', key)
else: else:
@ -278,8 +278,8 @@ def get_config(parse_args=True, cfg_path=None, options=None):
agent_config['statsd_forward_port'] = int(config.get('Main', 'statsd_forward_port')) agent_config['statsd_forward_port'] = int(config.get('Main', 'statsd_forward_port'))
# normalize 'yes'/'no' to boolean # normalize 'yes'/'no' to boolean
monstatsd_defaults['monstatsd_normalize'] = _is_affirmative( monasca_statsd_defaults['monasca_statsd_normalize'] = _is_affirmative(
monstatsd_defaults['monstatsd_normalize']) monasca_statsd_defaults['monasca_statsd_normalize'])
# Optional config # Optional config
# FIXME not the prettiest code ever... # FIXME not the prettiest code ever...
@ -511,7 +511,7 @@ def load_check_directory(agent_config):
''' Return the initialized checks from checks_d, and a mapping of checks that failed to ''' Return the initialized checks from checks_d, and a mapping of checks that failed to
initialize. Only checks that have a configuration initialize. Only checks that have a configuration
file in conf.d will be returned. ''' file in conf.d will be returned. '''
from monagent.collector.checks import AgentCheck from monasca_agent.collector.checks import AgentCheck
initialized_checks = {} initialized_checks = {}
init_failed_checks = {} init_failed_checks = {}
@ -680,7 +680,7 @@ def get_logging_config(cfg_path=None):
'log_level': None, 'log_level': None,
'collector_log_file': DEFAULT_LOG_DIR + '/collector.log', 'collector_log_file': DEFAULT_LOG_DIR + '/collector.log',
'forwarder_log_file': DEFAULT_LOG_DIR + '/forwarder.log', 'forwarder_log_file': DEFAULT_LOG_DIR + '/forwarder.log',
'monstatsd_log_file': DEFAULT_LOG_DIR + '/monstatsd.log', 'statsd_log_file': DEFAULT_LOG_DIR + '/statsd.log',
'jmxfetch_log_file': DEFAULT_LOG_DIR + '/jmxfetch.log', 'jmxfetch_log_file': DEFAULT_LOG_DIR + '/jmxfetch.log',
'log_to_event_viewer': False, 'log_to_event_viewer': False,
'log_to_syslog': True, 'log_to_syslog': True,

View File

@ -2,7 +2,7 @@ from hashlib import md5
import json import json
import urllib2 import urllib2
from monagent.common.metrics import Measurement from monasca_agent.common.metrics import Measurement
def post_headers(payload): def post_headers(payload):
@ -24,7 +24,7 @@ def http_emitter(message, log, url):
partial_payload = [] partial_payload = []
for measurement in message: for measurement in message:
if not isinstance(measurement, Measurement): if not isinstance(measurement, Measurement):
log.error('Data was not in the form of a monagent.common.metrics.Measurement') log.error('Data was not in the form of a monasca_agent.common.metrics.Measurement')
continue continue
# Measurements need their __dict__ encoded to avoid being expressed as a tuple # Measurements need their __dict__ encoded to avoid being expressed as a tuple
partial_payload.append(measurement.__dict__) partial_payload.append(measurement.__dict__)

View File

@ -4,7 +4,7 @@ from collections import namedtuple
import logging import logging
from time import time from time import time
from monagent.common.exceptions import Infinity, UnknownValue from monasca_agent.common.exceptions import Infinity, UnknownValue
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -144,7 +144,7 @@ def get_hostname(config=None):
# first, try the config # first, try the config
if config is None: if config is None:
from monagent.common.config import get_config from monasca_agent.common.config import get_config
config = get_config(parse_args=True) config = get_config(parse_args=True)
config_hostname = config.get('hostname') config_hostname = config.get('hostname')
if config_hostname and is_valid_hostname(config_hostname): if config_hostname and is_valid_hostname(config_hostname):

View File

@ -3,8 +3,8 @@ import logging
from collections import deque from collections import deque
from monascaclient import exc as exc, client from monascaclient import exc as exc, client
from monagent.common.keystone import Keystone from monasca_agent.common.keystone import Keystone
from monagent.common.util import get_hostname from monasca_agent.common.util import get_hostname
import requests import requests

View File

@ -11,11 +11,11 @@
""" """
# set up logging before importing any other components # set up logging before importing any other components
from monagent.common.config import initialize_logging from monasca_agent.common.config import initialize_logging
from monagent.forwarder.api.mon import MonAPI from monasca_agent.forwarder.api.mon import MonAPI
initialize_logging('forwarder') initialize_logging('forwarder')
from monagent.common.config import get_logging_config from monasca_agent.common.config import get_logging_config
import os import os
os.umask(0o22) os.umask(0o22)
@ -36,10 +36,10 @@ from tornado.escape import json_decode
from tornado.options import define, parse_command_line, options from tornado.options import define, parse_command_line, options
# agent import # agent import
from monagent.common.check_status import ForwarderStatus from monasca_agent.common.check_status import ForwarderStatus
from monagent.common.config import get_config from monasca_agent.common.config import get_config
from monagent.common.metrics import Measurement from monasca_agent.common.metrics import Measurement
from monagent.common.util import Watchdog, get_tornado_ioloop from monasca_agent.common.util import Watchdog, get_tornado_ioloop
from transaction import Transaction, TransactionManager from transaction import Transaction, TransactionManager
log = logging.getLogger('forwarder') log = logging.getLogger('forwarder')
@ -137,7 +137,7 @@ class AgentInputHandler(tornado.web.RequestHandler):
""" """
# read the message it should be a list of # read the message it should be a list of
# monagent.common.metrics.Measurements expressed as a dict # monasca_agent.common.metrics.Measurements expressed as a dict
msg = tornado.escape.json_decode(self.request.body) msg = tornado.escape.json_decode(self.request.body)
try: try:
measurements = [Measurement(**m) for m in msg] measurements = [Measurement(**m) for m in msg]

View File

@ -6,8 +6,8 @@ import logging
from operator import attrgetter from operator import attrgetter
# project # project
from monagent.common.check_status import ForwarderStatus from monasca_agent.common.check_status import ForwarderStatus
from monagent.common.util import get_tornado_ioloop, plural from monasca_agent.common.util import get_tornado_ioloop, plural
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -4,11 +4,11 @@ A Python Statsd implementation with dimensions added
""" """
# set up logging before importing any other components # set up logging before importing any other components
from monagent.common.config import initialize_logging from monasca_agent.common.config import initialize_logging
from monagent.monstatsd.reporter import Reporter from monasca_agent.statsd.reporter import Reporter
from monagent.monstatsd.udp import Server from monasca_agent.statsd.udp import Server
initialize_logging('monstatsd') initialize_logging('monasca_statsd')
import os import os
os.umask(0o22) os.umask(0o22)
@ -20,18 +20,18 @@ import signal
import sys import sys
# project # project
from monagent.common.aggregator import MetricsBucketAggregator from monasca_agent.common.aggregator import MetricsBucketAggregator
from monagent.common.check_status import MonstatsdStatus from monasca_agent.common.check_status import MonascaStatsdStatus
from monagent.common.config import get_config from monasca_agent.common.config import get_config
from monagent.common.daemon import Daemon, AgentSupervisor from monasca_agent.common.daemon import Daemon, AgentSupervisor
from monagent.common.util import PidFile, get_hostname from monasca_agent.common.util import PidFile, get_hostname
log = logging.getLogger('monstatsd') log = logging.getLogger('monasca_statsd')
class Monstatsd(Daemon): class MonascaStatsd(Daemon):
""" This class is the monstatsd daemon. """ """ This class is the monasca_statsd daemon. """
def __init__(self, pid_file, server, reporter, autorestart): def __init__(self, pid_file, server, reporter, autorestart):
Daemon.__init__(self, pid_file, autorestart=autorestart) Daemon.__init__(self, pid_file, autorestart=autorestart)
@ -63,25 +63,25 @@ class Monstatsd(Daemon):
# the reporting thread. # the reporting thread.
self.reporter.stop() self.reporter.stop()
self.reporter.join() self.reporter.join()
log.info("Monstatsd is stopped") log.info("monasca_statsd is stopped")
# Restart if asked to restart # Restart if asked to restart
if self.autorestart: if self.autorestart:
sys.exit(AgentSupervisor.RESTART_EXIT_STATUS) sys.exit(AgentSupervisor.RESTART_EXIT_STATUS)
def info(self): def info(self):
logging.getLogger().setLevel(logging.ERROR) logging.getLogger().setLevel(logging.ERROR)
return MonstatsdStatus.print_latest_status() return MonascaStatsdStatus.print_latest_status()
def init_monstatsd(config_path=None, use_watchdog=False): def init_monasca_statsd(config_path=None, use_watchdog=False):
"""Configure the server and the reporting thread. """Configure the server and the reporting thread.
""" """
c = get_config(parse_args=False, cfg_path=config_path) c = get_config(parse_args=False, cfg_path=config_path)
log.debug("Configuration monstatsd") log.debug("Configuration monasca_statsd")
port = c['monstatsd_port'] port = c['monasca_statsd_port']
interval = int(c['monstatsd_interval']) interval = int(c['monasca_statsd_interval'])
aggregator_interval = int(c['monstatsd_agregator_bucket_size']) aggregator_interval = int(c['monasca_statsd_agregator_bucket_size'])
non_local_traffic = c['non_local_traffic'] non_local_traffic = c['non_local_traffic']
forward_to_host = c.get('statsd_forward_host') forward_to_host = c.get('statsd_forward_host')
forward_to_port = c.get('statsd_forward_port') forward_to_port = c.get('statsd_forward_port')
@ -119,14 +119,14 @@ def init_monstatsd(config_path=None, use_watchdog=False):
def main(config_path=None): def main(config_path=None):
""" The main entry point for the unix version of monstatsd. """ """ The main entry point for the unix version of monasca_statsd. """
parser = optparse.OptionParser("%prog [start|stop|restart|status]") parser = optparse.OptionParser("%prog [start|stop|restart|status]")
opts, args = parser.parse_args() opts, args = parser.parse_args()
reporter, server, cnf = init_monstatsd(config_path, use_watchdog=True) reporter, server, cnf = init_monasca_statsd(config_path, use_watchdog=True)
pid_file = PidFile('monstatsd') pid_file = PidFile('monasca_statsd')
daemon = Monstatsd(pid_file.get_path(), server, reporter, daemon = monasca_statsd(pid_file.get_path(), server, reporter,
cnf.get('autorestart', False)) cnf.get('autorestart', False))
# If no args were passed in, run the server in the foreground. # If no args were passed in, run the server in the foreground.
# todo does this need to be a daemon even when it basically always runs in the foreground, if not # todo does this need to be a daemon even when it basically always runs in the foreground, if not

View File

@ -1,12 +1,12 @@
import json import json
import logging import logging
import threading import threading
from monagent.common.check_status import MonstatsdStatus from monasca_agent.common.check_status import MonascaStatsdStatus
from monagent.common.emitter import http_emitter from monasca_agent.common.emitter import http_emitter
from monagent.common.util import plural from monasca_agent.common.util import plural
from monagent.common.config import initialize_logging from monasca_agent.common.config import initialize_logging
initialize_logging('monstatsd') initialize_logging('monasca_statsd')
log = logging.getLogger('monstatsd') log = logging.getLogger('monasca_statsd')
WATCHDOG_TIMEOUT = 120 WATCHDOG_TIMEOUT = 120
@ -35,7 +35,7 @@ class Reporter(threading.Thread):
self.watchdog = None self.watchdog = None
if use_watchdog: if use_watchdog:
from monagent.common.util import Watchdog from monasca_agent.common.util import Watchdog
self.watchdog = Watchdog(WATCHDOG_TIMEOUT) self.watchdog = Watchdog(WATCHDOG_TIMEOUT)
self.api_host = api_host self.api_host = api_host
@ -55,7 +55,7 @@ class Reporter(threading.Thread):
log.debug("Watchdog enabled: %s" % bool(self.watchdog)) log.debug("Watchdog enabled: %s" % bool(self.watchdog))
# Persist a start-up message. # Persist a start-up message.
MonstatsdStatus().persist() MonascaStatsdStatus().persist()
while not self.finished.isSet(): # Use camel case isSet for 2.4 support. while not self.finished.isSet(): # Use camel case isSet for 2.4 support.
self.finished.wait(self.interval) self.finished.wait(self.interval)
@ -65,7 +65,7 @@ class Reporter(threading.Thread):
# Clean up the status messages. # Clean up the status messages.
log.debug("Stopped reporter") log.debug("Stopped reporter")
MonstatsdStatus.remove_latest_status() MonascaStatsdStatus.remove_latest_status()
def flush(self): def flush(self):
try: try:
@ -106,7 +106,7 @@ class Reporter(threading.Thread):
# Persist a status message. # Persist a status message.
packet_count = self.aggregator.total_count packet_count = self.aggregator.total_count
packets_per_second = self.aggregator.packets_per_second(self.interval) packets_per_second = self.aggregator.packets_per_second(self.interval)
MonstatsdStatus( MonascaStatsdStatus(
flush_count=self.flush_count, flush_count=self.flush_count,
packet_count=packet_count, packet_count=packet_count,
packets_per_second=packets_per_second, packets_per_second=packets_per_second,

View File

@ -2,9 +2,9 @@ import ast
import logging import logging
import select import select
import socket import socket
from monagent.common.config import initialize_logging from monasca_agent.common.config import initialize_logging
initialize_logging('monstatsd') initialize_logging('monasca_statsd')
log = logging.getLogger('monstatsd') log = logging.getLogger('monasca_statsd')
UDP_SOCKET_TIMEOUT = 5 UDP_SOCKET_TIMEOUT = 5

View File

@ -1,8 +1,8 @@
# set up logging before importing any other components # set up logging before importing any other components
from config import initialize_logging from config import initialize_logging
from monagent.pup import pup from monasca_agent.pup import pup
from collector import modules from collector import modules
from monstatsd import dogstatsd from monasca_agent.statsd import daemon
initialize_logging('collector') initialize_logging('collector')
@ -21,16 +21,16 @@ from ddagent import Application
from win32.common import handle_exe_click from win32.common import handle_exe_click
from collector.jmxfetch import JMXFetch from collector.jmxfetch import JMXFetch
from monagent.common.config import get_config, load_check_directory, set_win32_cert_path from monasca_agent.common.config import get_config, load_check_directory, set_win32_cert_path
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
RESTART_INTERVAL = 24 * 60 * 60 # Defaults to 1 day RESTART_INTERVAL = 24 * 60 * 60 # Defaults to 1 day
class AgentSvc(win32serviceutil.ServiceFramework): class AgentSvc(win32serviceutil.ServiceFramework):
_svc_name_ = "DatadogAgent" _svc_name_ = "MonascaAgent"
_svc_display_name_ = "Datadog Agent" _svc_display_name_ = "Monasca Agent"
_svc_description_ = "Sends metrics to Datadog" _svc_description_ = "Sends metrics to Monasca"
def __init__(self, args): def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args) win32serviceutil.ServiceFramework.__init__(self, args)
@ -50,10 +50,9 @@ class AgentSvc(win32serviceutil.ServiceFramework):
# Keep a list of running processes so we can start/end as needed. # Keep a list of running processes so we can start/end as needed.
# Processes will start started in order and stopped in reverse order. # Processes will start started in order and stopped in reverse order.
self.procs = { self.procs = {
'forwarder': DDForwarder(config), 'monasca-forwarder': MonascaForwarder(config),
'collector': DDAgent(agentConfig), 'monasca-collector': MonascaCollector(agentConfig),
'dogstatsd': DogstatsdProcess(config), 'monasca-statsd': MonascaStatsd(config),
'pup': PupProcess(config),
} }
def SvcStop(self): def SvcStop(self):
@ -107,10 +106,10 @@ class AgentSvc(win32serviceutil.ServiceFramework):
time.sleep(1) time.sleep(1)
class DDAgent(multiprocessing.Process): class MonascaCollector(multiprocessing.Process):
def __init__(self, agentConfig, start_event=True): def __init__(self, agentConfig, start_event=True):
multiprocessing.Process.__init__(self, name='ddagent') multiprocessing.Process.__init__(self, name='monasca-collector')
self.config = agentConfig self.config = agentConfig
self.start_event = start_event self.start_event = start_event
# FIXME: `running` flag should be handled by the service # FIXME: `running` flag should be handled by the service
@ -118,7 +117,7 @@ class DDAgent(multiprocessing.Process):
self.is_enabled = True self.is_enabled = True
def run(self): def run(self):
log.debug("Windows Service - Starting collector") log.debug("Windows Service - Starting monasca-collector")
emitters = self.get_emitters() emitters = self.get_emitters()
self.collector = Collector(self.config, emitters) self.collector = Collector(self.config, emitters)
@ -131,7 +130,7 @@ class DDAgent(multiprocessing.Process):
time.sleep(self.config['check_freq']) time.sleep(self.config['check_freq'])
def stop(self): def stop(self):
log.debug("Windows Service - Stopping collector") log.debug("Windows Service - Stopping monasca-collector")
self.collector.stop() self.collector.stop()
if JMXFetch.is_running(): if JMXFetch.is_running():
JMXFetch.stop() JMXFetch.stop()
@ -149,15 +148,15 @@ class DDAgent(multiprocessing.Process):
return emitters return emitters
class DDForwarder(multiprocessing.Process): class MonascaForwarder(multiprocessing.Process):
def __init__(self, agentConfig): def __init__(self, agentConfig):
multiprocessing.Process.__init__(self, name='ddforwarder') multiprocessing.Process.__init__(self, name='monasca-forwarder')
self.config = agentConfig self.config = agentConfig
self.is_enabled = True self.is_enabled = True
def run(self): def run(self):
log.debug("Windows Service - Starting forwarder") log.debug("Windows Service - Starting monasca-forwarder")
set_win32_cert_path() set_win32_cert_path()
port = self.config.get('listen_port', 17123) port = self.config.get('listen_port', 17123)
if port is None: if port is None:
@ -169,48 +168,30 @@ class DDForwarder(multiprocessing.Process):
self.forwarder.run() self.forwarder.run()
def stop(self): def stop(self):
log.debug("Windows Service - Stopping forwarder") log.debug("Windows Service - Stopping monasca-forwarder")
self.forwarder.stop() self.forwarder.stop()
class DogstatsdProcess(multiprocessing.Process): class MonascaStatsdProcess(multiprocessing.Process):
def __init__(self, agentConfig): def __init__(self, agentConfig):
multiprocessing.Process.__init__(self, name='dogstatsd') multiprocessing.Process.__init__(self, name='monasca-statsd')
self.config = agentConfig self.config = agentConfig
self.is_enabled = True self.is_enabled = True
def run(self): def run(self):
log.debug("Windows Service - Starting Monstatsd server") log.debug("Windows Service - Starting monasca-statsd server")
self.reporter, self.server, _ = dogstatsd.init() self.reporter, self.server, _ = daemon.init_monasca_statsd()
self.reporter.start() self.reporter.start()
self.server.start() self.server.start()
def stop(self): def stop(self):
log.debug("Windows Service - Stopping Monstatsd server") log.debug("Windows Service - Stopping monasca-statsd server")
self.server.stop() self.server.stop()
self.reporter.stop() self.reporter.stop()
self.reporter.join() self.reporter.join()
class PupProcess(multiprocessing.Process):
def __init__(self, agentConfig):
multiprocessing.Process.__init__(self, name='pup')
self.config = agentConfig
self.is_enabled = self.config.get('use_web_info_page', True)
def run(self):
self.pup = pup
if self.is_enabled:
log.debug("Windows Service - Starting Pup")
self.pup.run_pup(self.config)
def stop(self):
if self.is_enabled:
log.debug("Windows Service - Stopping Pup")
self.pup.stop()
if __name__ == '__main__': if __name__ == '__main__':
multiprocessing.freeze_support() multiprocessing.freeze_support()
if len(sys.argv) == 1: if len(sys.argv) == 1:

Some files were not shown because too many files have changed in this diff Show More