bmr-cymru / dmioscope

Device-mapper IO visualisation tools
GNU General Public License v2.0
5 stars 1 forks source link

dmioscope: use an outer container in JSON files #12

Closed bmr-cymru closed 7 years ago

bmr-cymru commented 7 years ago

The current JSONLogger implementation writes a new root JST object for each change of IOScope configuration. This leads to a file stream containing multiple JSON objects, which is forbidden by the Python JSON decoder:

>>> jst = json.loads(jstr)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 367, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 97 column 1 - line 1140 column 1 (char 1957 - 22085)

Removing all but a single JST object allows the load to succeed:

>>> f = open("/tmp/data2.json", "r")
>>> jstr = f.read()
>>> jst = json.loads(jstr)
>>> jst
{u'recordCount': u'1', u'docType': u'jts', u'version': u'1.0', u'startTime': u'2016-09-29T21:13:09.751024', u'endTime': u'2016-09-29T21:13:09.751024', u'data': [{u'ts': u'2016-09-29T21:13:09.751024', u'f': {u'1': {u'v': 562}, u'0': {u'v': 866}, u'3': {u'v': 1100}, u'2': {u'v': 4675}, u'5': {u'v': 432}, u'4': {u'v': 822}, u'7': {u'v': 179}, u'6': {u'v': 0}}}], u'columns': {u'1': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'dm105c0p39bc9b4035f906d71', u'name': u'8388608', u'format': u'0'}, u'0': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d70', u'name': u'8388608', u'format': u'0'}, u'3': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d73', u'name': u'8388608', u'format': u'0'}, u'2': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d72', u'name': u'8388608', u'format': u'0'}, u'5': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d75', u'name': u'8388608', u'format': u'0'}, u'4': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d74', u'name': u'8388608', u'format': u'0'}, u'7': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d77', u'name': u'8388608', u'format': u'0'}, u'6': {u'dataType': u'NUMBER', u'renderType': u'VALUE', u'id': u'f1xm3a129bc9b4035f906d76', u'name': u'8388608', u'format': u'0'}}}

Fix this by wrapping each successive jst dictionary object inside an array so that the load returns an array of all available JST instances.