Whitespace cleanups; rename InfluxDB field from "gauge" to "value"
... this abandons Prometheus "compatibility" for a better fit with InfluxDB naming.
This commit is contained in:
parent
4e68925d34
commit
10bf0b4f1e
25
bms.py
25
bms.py
@ -225,11 +225,11 @@ def parse_03_response(response):
|
|||||||
|
|
||||||
current = bytes_to_digits(response[6], response[7])
|
current = bytes_to_digits(response[6], response[7])
|
||||||
current = convert_to_signed(current) * 0.01
|
current = convert_to_signed(current) * 0.01
|
||||||
data["bms_current_amps"] = dict()
|
data['bms_current_amps'] = dict()
|
||||||
data["bms_current_amps"]['help'] = "Current"
|
data['bms_current_amps']['help'] = "Current"
|
||||||
data["bms_current_amps"]['raw_value'] = current
|
data['bms_current_amps']['raw_value'] = current
|
||||||
data["bms_current_amps"]['value'] = "{:.2f}".format(current)
|
data['bms_current_amps']['value'] = "{:.2f}".format(current)
|
||||||
data["bms_current_amps"]['units'] = "A"
|
data['bms_current_amps']['units'] = "A"
|
||||||
if debug > 1:
|
if debug > 1:
|
||||||
print("Current: {:.2f}A".format(current))
|
print("Current: {:.2f}A".format(current))
|
||||||
|
|
||||||
@ -672,7 +672,7 @@ def influxdb_export(bucket, url=None, org=None, token=None, daemonize=True):
|
|||||||
influxclient.close()
|
influxclient.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
def influxdb_write_snapshot(bucket,data):
|
def influxdb_write_snapshot(bucket, data):
|
||||||
global debug
|
global debug
|
||||||
global influxclient
|
global influxclient
|
||||||
global writeapi
|
global writeapi
|
||||||
@ -689,15 +689,15 @@ def influxdb_create_snapshot(data):
|
|||||||
helpmsg = ''
|
helpmsg = ''
|
||||||
units = ''
|
units = ''
|
||||||
now = datetime.datetime.now(datetime.timezone.utc).isoformat()
|
now = datetime.datetime.now(datetime.timezone.utc).isoformat()
|
||||||
''' Note that the fieldname is set to "gauge" in order to retain
|
|
||||||
compatibility with data imported from Prometheus (and it's
|
|
||||||
as good a name as any). '''
|
|
||||||
for kind, contains in data.items():
|
for kind, contains in data.items():
|
||||||
|
helpmsg = None
|
||||||
if contains.get('help'):
|
if contains.get('help'):
|
||||||
helpmsg = contains.get('help')
|
helpmsg = contains.get('help')
|
||||||
|
units = None
|
||||||
if contains.get('units'):
|
if contains.get('units'):
|
||||||
units = contains.get('units')
|
units = contains.get('units')
|
||||||
# Simple values
|
# Simple values
|
||||||
|
value = None
|
||||||
if contains.get('raw_value') is not None:
|
if contains.get('raw_value') is not None:
|
||||||
value = contains.get('raw_value')
|
value = contains.get('raw_value')
|
||||||
if debug > 2:
|
if debug > 2:
|
||||||
@ -705,10 +705,11 @@ def influxdb_create_snapshot(data):
|
|||||||
point = Point(kind) \
|
point = Point(kind) \
|
||||||
.tag("units", units) \
|
.tag("units", units) \
|
||||||
.tag("help", helpmsg) \
|
.tag("help", helpmsg) \
|
||||||
.field("gauge", value) \
|
.field("value", value) \
|
||||||
.time(now)
|
.time(now)
|
||||||
points.append(point)
|
points.append(point)
|
||||||
# Doesn't have a value, but multiple values, each with a label:
|
# Doesn't have a value, but multiple values, each with a label:
|
||||||
|
label = None
|
||||||
if contains.get('raw_values') is not None and isinstance(contains.get('raw_values'), dict):
|
if contains.get('raw_values') is not None and isinstance(contains.get('raw_values'), dict):
|
||||||
label = contains.get('label')
|
label = contains.get('label')
|
||||||
for idx, label_value in contains.get('raw_values').items():
|
for idx, label_value in contains.get('raw_values').items():
|
||||||
@ -718,7 +719,7 @@ def influxdb_create_snapshot(data):
|
|||||||
.tag(label, idx) \
|
.tag(label, idx) \
|
||||||
.tag("units", units) \
|
.tag("units", units) \
|
||||||
.tag("help", helpmsg) \
|
.tag("help", helpmsg) \
|
||||||
.field("gauge", label_value) \
|
.field("value", label_value) \
|
||||||
.time(now)
|
.time(now)
|
||||||
points.append(point)
|
points.append(point)
|
||||||
# Information (like a manufacturing date or a serial number)
|
# Information (like a manufacturing date or a serial number)
|
||||||
@ -729,7 +730,7 @@ def influxdb_create_snapshot(data):
|
|||||||
point = Point(kind) \
|
point = Point(kind) \
|
||||||
.tag("units", units) \
|
.tag("units", units) \
|
||||||
.tag("help", helpmsg) \
|
.tag("help", helpmsg) \
|
||||||
.field("gauge", value) \
|
.field("value", value) \
|
||||||
.time(now)
|
.time(now)
|
||||||
points.append(point)
|
points.append(point)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user