summaryrefslogtreecommitdiff
path: root/.clusterman.py
diff options
context:
space:
mode:
authorLoic Guegan <loic.guegan@mailbox.org>2024-04-09 14:04:16 +0200
committerLoic Guegan <loic.guegan@mailbox.org>2024-04-09 14:04:16 +0200
commita1b14f62af435d1dd5a4d7b1464eed7d44b31fe5 (patch)
treec9f75157321e80f49a9596819eb4d78101d9fd14 /.clusterman.py
parente9d443ea7286fceea3c071988226a16c0d5b0b97 (diff)
Add python version of clusterman plugin
Diffstat (limited to '.clusterman.py')
-rw-r--r--.clusterman.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/.clusterman.py b/.clusterman.py
new file mode 100644
index 0000000..8dbc28b
--- /dev/null
+++ b/.clusterman.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+
+import sys, json, os, argparse
+
+#### Signal must be handled to use pipe the command line (e.g: ./.clusterman.py node-pi-1 1712660604 1712660705|head)
+from signal import signal, SIGPIPE, SIG_DFL
+signal(SIGPIPE,SIG_DFL)
+
+#### Parse arguments
+parser = argparse.ArgumentParser(description="Script to collect power measurements")
+parser.add_argument('key', help='Key to use e.g: hostname')
+parser.add_argument('start', help='Starting timestamp')
+parser.add_argument('end', help='Ending timestamp')
+parser.add_argument('-u', '--unique', help="Do not report duplication power measurements", action="store_true")
+args=parser.parse_args()
+
+#### Loading arguments
+key=args.key
+startTime=int(args.start)
+endTime=int(args.end)
+unique=args.unique
+
+#### Init various constancs
+LOG_INTERVAL=20
+POWER_PATH="/home/loic/power/"
+MAP_FILE="/home/loic/map.json"
+# Getting measuremnts location according to key
+with open(MAP_FILE) as f:
+ global MAP
+ MAP = json.load(f)
+MEASUREMENTS_LOCATION=os.path.join(POWER_PATH,MAP[key])
+START_INTERVAL=startTime-(startTime%LOG_INTERVAL)
+END_INTERVAL=endTime-(endTime%LOG_INTERVAL)
+
+#### Init various variables
+showHeader=True
+interval=START_INTERVAL
+lastPower="" # Store last read measurement
+finalLinePrinted=False
+finalLine=""
+# Start reporting
+while True:
+ # Open the correct measurement file
+ path=os.path.join(MEASUREMENTS_LOCATION,str(interval))
+ theFile = open(path, 'r')
+
+ # Start reading lines in the file
+ linum=0
+ while True:
+ line = theFile.readline()
+ if not line:
+ break
+ linum+=1
+ line=line.strip() # Remove newline char at the end
+ if linum <= 1 and showHeader:
+ print(line)
+ showHeader=False
+ elif linum > 1:
+ if unique:
+ split=line.split(",")
+ if lastPower != "" and split[2] != lastPower:
+ print(line)
+ finalLine=line
+ lastPower=split[2]
+ else:
+ print(line)
+ theFile.close()
+
+ # Update interval
+ if interval >= END_INTERVAL:
+ break
+ interval+=LOG_INTERVAL
+
+#### Check if last power measurement need to be explicitely printed
+if unique and not finalLinePrinted:
+ print(finalLine)