Make statsd self-monitoring optional
Story: 2001873 Task: 14333 Change-Id: I35eaa298f1153e6b71a5bfe33a894adec6b593a3
This commit is contained in:
parent
d396753a83
commit
cdb2e4398d
@ -79,9 +79,57 @@ def grab_stored_notification_method(db_repo, notification_id):
|
|||||||
def get_statsd_client(dimensions=None):
|
def get_statsd_client(dimensions=None):
|
||||||
local_dims = dimensions.copy() if dimensions else {}
|
local_dims = dimensions.copy() if dimensions else {}
|
||||||
local_dims.update(NOTIFICATION_DIMENSIONS)
|
local_dims.update(NOTIFICATION_DIMENSIONS)
|
||||||
client = monascastatsd.Client(name='monasca',
|
if CONF.statsd.enable:
|
||||||
host=CONF.statsd.host,
|
LOG.debug("Establishing connection with statsd on {0}:{1}"
|
||||||
port=CONF.statsd.port,
|
.format(CONF.statsd.host, CONF.statsd.port))
|
||||||
dimensions=local_dims)
|
client = monascastatsd.Client(name='monasca',
|
||||||
|
host=CONF.statsd.host,
|
||||||
|
port=CONF.statsd.port,
|
||||||
|
dimensions=local_dims)
|
||||||
|
else:
|
||||||
|
LOG.warn("StatsD monitoring disabled. Overriding monascastatsd.Client to use it offline")
|
||||||
|
client = OfflineClient(name='monasca',
|
||||||
|
host=CONF.statsd.host,
|
||||||
|
port=CONF.statsd.port,
|
||||||
|
dimensions=local_dims)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
class OfflineClient(monascastatsd.Client):
|
||||||
|
|
||||||
|
def _set_connection(self, connection, host, port):
|
||||||
|
if connection is None:
|
||||||
|
self.connection = OfflineConnection(host=host,
|
||||||
|
port=port,
|
||||||
|
max_buffer_size=self._max_buffer_size)
|
||||||
|
else:
|
||||||
|
self.connection = connection
|
||||||
|
|
||||||
|
|
||||||
|
class OfflineConnection(monascastatsd.Connection):
|
||||||
|
|
||||||
|
def __init__(self, host='localhost', port=8125, max_buffer_size=50):
|
||||||
|
"""Initialize an Offline Connection object.
|
||||||
|
|
||||||
|
>>> monascastatsd = MonascaStatsd()
|
||||||
|
|
||||||
|
:name: the name for this client. Everything sent by this client
|
||||||
|
will be prefixed by name
|
||||||
|
:param host: the host of the MonascaStatsd server.
|
||||||
|
:param port: the port of the MonascaStatsd server.
|
||||||
|
:param max_buffer_size: Maximum number of metric to buffer before
|
||||||
|
sending to the server if sending metrics in batch
|
||||||
|
"""
|
||||||
|
self.max_buffer_size = max_buffer_size
|
||||||
|
self._send = self._send_to_server
|
||||||
|
self.connect(host, port)
|
||||||
|
self.encoding = 'utf-8'
|
||||||
|
|
||||||
|
def connect(self, host, port):
|
||||||
|
"""Avoid connecting to the monascastatsd server.
|
||||||
|
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _send_to_server(self, packet):
|
||||||
|
pass
|
||||||
|
@ -24,6 +24,8 @@ statsd_group = cfg.OptGroup('statsd',
|
|||||||
'to statsd server launched by monasca-agent.')
|
'to statsd server launched by monasca-agent.')
|
||||||
|
|
||||||
statsd_opts = [
|
statsd_opts = [
|
||||||
|
cfg.BoolOpt('enable', default=True,
|
||||||
|
help='Enable or disable self monitoring.'),
|
||||||
cfg.HostAddressOpt('host', default=_DEFAULT_HOST,
|
cfg.HostAddressOpt('host', default=_DEFAULT_HOST,
|
||||||
help='IP address of statsd server.'),
|
help='IP address of statsd server.'),
|
||||||
cfg.PortOpt('port', default=_DEFAULT_PORT, help='Port of statsd server.'),
|
cfg.PortOpt('port', default=_DEFAULT_PORT, help='Port of statsd server.'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user