summaryrefslogtreecommitdiffstats
path: root/docker/storperf-master/storperf/carbon
diff options
context:
space:
mode:
Diffstat (limited to 'docker/storperf-master/storperf/carbon')
-rw-r--r--docker/storperf-master/storperf/carbon/__init__.py8
-rw-r--r--docker/storperf-master/storperf/carbon/converter.py57
-rw-r--r--docker/storperf-master/storperf/carbon/emitter.py38
3 files changed, 103 insertions, 0 deletions
diff --git a/docker/storperf-master/storperf/carbon/__init__.py b/docker/storperf-master/storperf/carbon/__init__.py
new file mode 100644
index 0000000..73334c7
--- /dev/null
+++ b/docker/storperf-master/storperf/carbon/__init__.py
@@ -0,0 +1,8 @@
+##############################################################################
+# Copyright (c) 2015 EMC and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
diff --git a/docker/storperf-master/storperf/carbon/converter.py b/docker/storperf-master/storperf/carbon/converter.py
new file mode 100644
index 0000000..623c144
--- /dev/null
+++ b/docker/storperf-master/storperf/carbon/converter.py
@@ -0,0 +1,57 @@
+##############################################################################
+# Copyright (c) 2015 EMC and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import calendar
+import logging
+import time
+
+
+class Converter(object):
+
+ def __init__(self):
+ self.logger = logging.getLogger(__name__)
+
+ def convert_json_to_flat(self, json_object, prefix=None):
+ # Use the timestamp reported by fio, or current time if
+ # not present.
+ if 'timestamp' in json_object:
+ timestamp = str(json_object.pop('timestamp'))
+ else:
+ timestamp = str(calendar.timegm(time.gmtime()))
+
+ self.flat_dictionary = {}
+ self.flat_dictionary['timestamp'] = timestamp
+
+ self.resurse_to_flat_dictionary(json_object, prefix)
+ return self.flat_dictionary
+
+ def resurse_to_flat_dictionary(self, json, prefix=None):
+ if type(json) == dict:
+ for k, v in json.items():
+ if prefix is None:
+ key = k.decode("utf-8").replace(" ", "_")
+ else:
+ key = prefix + "." + k.decode("utf-8").replace(" ", "_")
+ if hasattr(v, '__iter__'):
+ self.resurse_to_flat_dictionary(v, key)
+ else:
+ self.flat_dictionary[key] = str(v).replace(" ", "_")
+ elif type(json) == list:
+ index = 0
+ for v in json:
+ index += 1
+ if hasattr(v, '__iter__'):
+ self.resurse_to_flat_dictionary(
+ v, prefix + "." + str(index))
+ else:
+ if prefix is None:
+ self.flat_dictionary[index] = str(v).replace(" ", "_")
+ + " " + self.timestamp
+ else:
+ key = prefix + "." + index
+ self.flat_dictionary[key] = str(v).replace(" ", "_")
diff --git a/docker/storperf-master/storperf/carbon/emitter.py b/docker/storperf-master/storperf/carbon/emitter.py
new file mode 100644
index 0000000..e23dc79
--- /dev/null
+++ b/docker/storperf-master/storperf/carbon/emitter.py
@@ -0,0 +1,38 @@
+##############################################################################
+# Copyright (c) 2015 EMC and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import calendar
+import logging
+import socket
+import time
+
+
+class CarbonMetricTransmitter():
+
+ carbon_host = '127.0.0.1'
+ carbon_port = 2003
+
+ def __init__(self):
+ self.logger = logging.getLogger(__name__)
+
+ def transmit_metrics(self, metrics):
+ if 'timestamp' in metrics:
+ metrics.pop('timestamp')
+ timestamp = str(calendar.timegm(time.gmtime()))
+
+ carbon_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ carbon_socket.connect((self.carbon_host, self.carbon_port))
+
+ for key, metric in metrics.items():
+ message = key + " " + metric + " " + timestamp
+ self.logger.debug("Metric: " + message)
+ carbon_socket.send(message + '\n')
+
+ carbon_socket.close()
+ self.logger.info("Sent metrics to carbon with timestamp %s"
+ % timestamp)