summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Chacon Piza <MartinDavid.ChaconPiza@ts.fujitsu.com>2018-04-18 13:34:16 +0200
committerMartin Chacon Piza <MartinDavid.ChaconPiza@ts.fujitsu.com>2018-05-14 11:52:52 +0200
commitcdb2e4398d397a405f7729fea482e07699d23dfc (patch)
treead2eec80478e1da74a6a189d91fea582993ef6fe
parentd396753a839c1317a59fb2867dc2188fc88cf95a (diff)
Make statsd self-monitoring optional
Notes
Notes (review): Code-Review+2: Stefano Canepa (sc) <sc@linux.it> Code-Review+1: wu.chunyang <wu.chunyang@99cloud.net> Code-Review+2: Witold Bedyk <witold.bedyk@est.fujitsu.com> Workflow+1: Witold Bedyk <witold.bedyk@est.fujitsu.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 14 May 2018 15:01:26 +0000 Reviewed-on: https://review.openstack.org/562248 Project: openstack/monasca-notification Branch: refs/heads/master
-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.'),