summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/dispatcher/influxdb.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/yardstick/dispatcher/influxdb.py b/yardstick/dispatcher/influxdb.py
index 10fff4d1f..53af79c71 100644
--- a/yardstick/dispatcher/influxdb.py
+++ b/yardstick/dispatcher/influxdb.py
@@ -13,6 +13,7 @@ import logging
import os
import time
+import collections
import requests
import six
from oslo_serialization import jsonutils
@@ -55,15 +56,17 @@ class InfluxdbDispatcher(DispatchBase):
def _dict_key_flatten(self, data):
next_data = {}
- if not [v for v in data.values()
- if type(v) == dict or type(v) == list]:
+ # use list, because iterable is too generic
+ if not [v for v in data.values() if
+ isinstance(v, (collections.Mapping, list))]:
return data
for k, v in six.iteritems(data):
- if type(v) == dict:
+ if isinstance(v, collections.Mapping):
for n_k, n_v in six.iteritems(v):
next_data["%s.%s" % (k, n_k)] = n_v
- elif type(v) == list:
+ # use list because iterable is too generic
+ elif isinstance(v, list):
for index, item in enumerate(v):
next_data["%s%d" % (k, index)] = item
else:
@@ -95,11 +98,12 @@ class InfluxdbDispatcher(DispatchBase):
def _data_to_line_protocol(self, data):
msg = {}
- point = {}
- point["measurement"] = self.tc
- point["fields"] = self._dict_key_flatten(data["benchmark"]["data"])
- point["time"] = self._get_nano_timestamp(data)
- point["tags"] = self._get_extended_tags(data)
+ point = {
+ "measurement": self.tc,
+ "fields": self._dict_key_flatten(data["benchmark"]["data"]),
+ "time": self._get_nano_timestamp(data),
+ "tags": self._get_extended_tags(data),
+ }
msg["points"] = [point]
msg["tags"] = self.static_tags