new format
This commit is contained in:
@@ -5,29 +5,15 @@ import serial
|
||||
import select
|
||||
from collections import deque
|
||||
|
||||
def parse_to_graphite(data, root='rc.bms', timestamp=None):
|
||||
if not timestamp:
|
||||
timestamp = int(time.time())
|
||||
def parse_to_graphite(data):
|
||||
timestamp = int(time.time())
|
||||
results = []
|
||||
|
||||
lines = data.strip().split('\n')
|
||||
for line in lines:
|
||||
if line.startswith('BMS'):
|
||||
parts = line.split()
|
||||
bank_battery = parts[1]
|
||||
metric_name = ' '.join(parts[2:-1]).replace(' ', '_')
|
||||
metric_value = parts[-1]
|
||||
|
||||
# Remove trailing colon in the metric name if present
|
||||
if metric_name.endswith(':'):
|
||||
metric_name = metric_name[:-1]
|
||||
|
||||
if 'Cell' in metric_name and 'Voltage' in metric_name and 'Cell' in metric_name.split('_')[0]:
|
||||
cell_number = metric_name.split('_')[1]
|
||||
metric_name = f"Cell.{cell_number}.Voltage"
|
||||
|
||||
metric_path = f"{root}.{bank_battery}.{metric_name}"
|
||||
results.append(f"{metric_path} {metric_value} {timestamp}")
|
||||
if line.startswith('>>>'):
|
||||
metric_path = line[3:].strip() # Remove the ">>>" prefix and any leading/trailing whitespace
|
||||
results.append(f"{metric_path} {timestamp}")
|
||||
return results
|
||||
|
||||
def send_to_graphite(data, host='10.6.0.1', port=2003):
|
||||
|
Reference in New Issue
Block a user