summaryrefslogtreecommitdiff
path: root/devstack
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@hpe.com>2016-05-27 17:05:13 +0100
committerFederico Ceratto <federico.ceratto@gmail.com>2016-09-09 17:50:11 +0000
commit2f061879cd0bda590b45fe1d82095b73f43f2041 (patch)
treeab0d6cd790e5d12b1e86afbfa31d659b353a34d7 /devstack
parent3941bb2088b9c8c356a420a9b8c3f5ff377bb450 (diff)
Add Monasca-statsd metric generation
Statsd integration is disabled by default. Add a simple local daemon for testing/devstack use. Change-Id: I990472fa059afde37f7e4a1284360c17162aab49
Notes
Notes (review): Code-Review+2: Kiall Mac Innes <kiall@macinnes.ie> Code-Review+2: Graham Hayes <graham.hayes@hpe.com> Workflow+1: Graham Hayes <graham.hayes@hpe.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 20 Sep 2016 13:02:10 +0000 Reviewed-on: https://review.openstack.org/322252 Project: openstack/designate Branch: refs/heads/master
Diffstat (limited to 'devstack')
-rwxr-xr-xdevstack/statsd_mock_server.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/devstack/statsd_mock_server.py b/devstack/statsd_mock_server.py
new file mode 100755
index 0000000..d65a458
--- /dev/null
+++ b/devstack/statsd_mock_server.py
@@ -0,0 +1,60 @@
1#!/usr/bin/env python
2# Copyright 2016 Hewlett Packard Enterprise Development Company LP
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16"""
17A simple mock UDP server to receive monasca-statsd traffic
18Log to stdout or to a file.
19"""
20
21from argparse import ArgumentParser
22from time import gmtime
23from time import strftime
24import SocketServer
25
26
27def parse_args():
28 ap = ArgumentParser()
29 ap.add_argument('--addr', default='127.0.0.1',
30 help='Listen IP addr (default: 127.0.0.1)')
31 ap.add_argument('--port', default=8125, type=int,
32 help='UDP port (default: 8125)')
33 ap.add_argument('--output-fname', default=None,
34 help='Output file (default: stdout)')
35 return ap.parse_args()
36
37
38class StatsdMessageHandler(SocketServer.BaseRequestHandler):
39
40 def handle(self):
41 data = self.request[0].strip()
42 tstamp = strftime("%Y-%m-%dT%H:%M:%S", gmtime())
43 if self._output_fd:
44 self._output_fd.write("%s %s\n" % (tstamp, data))
45 else:
46 print("%s %s" % (tstamp, data))
47
48
49def main():
50 args = parse_args()
51 fd = open(args.output_fname, 'a') if args.output_fname else None
52 StatsdMessageHandler._output_fd = fd
53 server = SocketServer.UDPServer(
54 (args.addr, args.port),
55 StatsdMessageHandler,
56 )
57 server.serve_forever()
58
59if __name__ == "__main__":
60 main()