summaryrefslogtreecommitdiff
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
parente9d443ea7286fceea3c071988226a16c0d5b0b97 (diff)
Add python version of clusterman plugin
-rw-r--r--.clusterman.py76
-rw-r--r--.map.json18
2 files changed, 94 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)
diff --git a/.map.json b/.map.json
new file mode 100644
index 0000000..939835e
--- /dev/null
+++ b/.map.json
@@ -0,0 +1,18 @@
+{
+ "node-pi-1": "bbb1/2-0041",
+ "node-pi-2":"bbb1/2-0042",
+ "node-pi-3":"bbb1/2-0043",
+ "node-pi-4":"bbb1/2-0040",
+ "node-pi-6":"bbb2/2-0041",
+ "node-pi-8":"bbb2/2-0047",
+ "node-pi-7":"bbb2/2-004f",
+ "node-pi-5":"bbb2/2-0040",
+ "node-pi-9":"bbb3/2-0048",
+ "node-pi-10":"bbb3/2-0044",
+ "node-pi-11":"bbb3/2-0045",
+ "node-pi-12":"bbb3/2-0046",
+ "node-pi-13":"bbb4/2-0042",
+ "node-pi-14":"bbb4/2-004b",
+ "node-pi-15":"bbb4/2-0040",
+ "node-pi-16":"bbb4/2-0049"
+}