summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-05-14 15:01:26 +0000
committerGerrit Code Review <review@openstack.org>2018-05-14 15:01:26 +0000
commit3973f07a70a2787af3c9851e8580f1a2b4c2885b (patch)
tree663b1f60a11cbc72121b5c89f666acf07c998cc3
parent9ce5e2c7bba4c8a49dd5d0c9f38d86297b865376 (diff)
parentcdb2e4398d397a405f7729fea482e07699d23dfc (diff)
Merge "Make statsd self-monitoring optional"
-rw-r--r--monasca_notification/common/utils.py58
-rw-r--r--monasca_notification/conf/statsd.py2
2 files changed, 55 insertions, 5 deletions
diff --git a/monasca_notification/common/utils.py b/monasca_notification/common/utils.py
index 58c1984..cf84203 100644
--- a/monasca_notification/common/utils.py
+++ b/monasca_notification/common/utils.py
@@ -79,9 +79,57 @@ def grab_stored_notification_method(db_repo, notification_id):
79def get_statsd_client(dimensions=None): 79def get_statsd_client(dimensions=None):
80 local_dims = dimensions.copy() if dimensions else {} 80 local_dims = dimensions.copy() if dimensions else {}
81 local_dims.update(NOTIFICATION_DIMENSIONS) 81 local_dims.update(NOTIFICATION_DIMENSIONS)
82 client = monascastatsd.Client(name='monasca', 82 if CONF.statsd.enable:
83 host=CONF.statsd.host, 83 LOG.debug("Establishing connection with statsd on {0}:{1}"
84 port=CONF.statsd.port, 84 .format(CONF.statsd.host, CONF.statsd.port))
85 dimensions=local_dims) 85 client = monascastatsd.Client(name='monasca',
86 86 host=CONF.statsd.host,
87 port=CONF.statsd.port,
88 dimensions=local_dims)
89 else:
90 LOG.warn("StatsD monitoring disabled. Overriding monascastatsd.Client to use it offline")
91 client = OfflineClient(name='monasca',
92 host=CONF.statsd.host,
93 port=CONF.statsd.port,
94 dimensions=local_dims)
87 return client 95 return client
96
97
98class OfflineClient(monascastatsd.Client):
99
100 def _set_connection(self, connection, host, port):
101 if connection is None:
102 self.connection = OfflineConnection(host=host,
103 port=port,
104 max_buffer_size=self._max_buffer_size)
105 else:
106 self.connection = connection
107
108
109class OfflineConnection(monascastatsd.Connection):
110
111 def __init__(self, host='localhost', port=8125, max_buffer_size=50):
112 """Initialize an Offline Connection object.
113
114 >>> monascastatsd = MonascaStatsd()
115
116 :name: the name for this client. Everything sent by this client
117 will be prefixed by name
118 :param host: the host of the MonascaStatsd server.
119 :param port: the port of the MonascaStatsd server.
120 :param max_buffer_size: Maximum number of metric to buffer before
121 sending to the server if sending metrics in batch
122 """
123 self.max_buffer_size = max_buffer_size
124 self._send = self._send_to_server
125 self.connect(host, port)
126 self.encoding = 'utf-8'
127
128 def connect(self, host, port):
129 """Avoid connecting to the monascastatsd server.
130
131 """
132 pass
133
134 def _send_to_server(self, packet):
135 pass
diff --git a/monasca_notification/conf/statsd.py b/monasca_notification/conf/statsd.py
index 5d5275c..4b6a366 100644
--- a/monasca_notification/conf/statsd.py
+++ b/monasca_notification/conf/statsd.py
@@ -24,6 +24,8 @@ statsd_group = cfg.OptGroup('statsd',
24 'to statsd server launched by monasca-agent.') 24 'to statsd server launched by monasca-agent.')
25 25
26statsd_opts = [ 26statsd_opts = [
27 cfg.BoolOpt('enable', default=True,
28 help='Enable or disable self monitoring.'),
27 cfg.HostAddressOpt('host', default=_DEFAULT_HOST, 29 cfg.HostAddressOpt('host', default=_DEFAULT_HOST,
28 help='IP address of statsd server.'), 30 help='IP address of statsd server.'),
29 cfg.PortOpt('port', default=_DEFAULT_PORT, help='Port of statsd server.'), 31 cfg.PortOpt('port', default=_DEFAULT_PORT, help='Port of statsd server.'),