diff --git a/bin/2graphite b/bin/2graphite index 996af69..ef924bb 100644 --- a/bin/2graphite +++ b/bin/2graphite @@ -1,3 +1,4 @@ +#/bin/python import socket import sys import time @@ -9,7 +10,7 @@ def parse_to_graphite(data, root='rc.bms', timestamp=None): if not timestamp: timestamp = int(time.time()) results = [] - + lines = data.strip().split('\n') for line in lines: if line.startswith('BMS'): @@ -36,7 +37,7 @@ def send_to_graphite(data, host='10.6.0.1', port=2003): while data: message = data.popleft() sock.sendall(message.encode('utf-8')) - print(f"Sent to Graphite: {message.strip()}") + #print(f"Sent to Graphite: {message.strip()}") except (socket.error, socket.timeout) as e: print(f"Failed to send data, will drop if buffer is full. Error: {e}", file=sys.stderr) @@ -50,18 +51,18 @@ def main(): if select.select([ser], [], [], 0)[0]: # Check if there is data to read line = ser.readline().decode('utf-8').strip() if line: - print(f"Raw Input: {line}") # Output raw line to screen + print(f"{line}") # Output raw line to screen graphite_data = parse_to_graphite(line) for data in graphite_data: if len(data_buffer) < data_buffer.maxlen: data_buffer.append(data + '\n') - print(f"Added to buffer: {data.strip()}") + #print(f"Added to buffer: {data.strip()}") else: print("Buffer full, dropping data", file=sys.stderr) # Try to send data if the buffer is not empty if data_buffer: - print("Attempting to send data to Graphite...") + #print("Attempting to send data to Graphite...") send_to_graphite(data_buffer) except KeyboardInterrupt: