summaryrefslogtreecommitdiff
path: root/.clusterman.sh
blob: 8da5146f1f437ad2889a0af353508183133c6939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# This script assumes that the keys used by publishers
# corresponds to the UNIQUE hostname of each monitored node

# Check parameters
[ $# -ne 3 ] && { echo "Usage: $0 <key> <from> <to>"; exit 1; }

# Load parameters
key=$1
from=$2
to=$3

# Load configuration
wai=$(dirname $(readlink -f "$0")) # Current script directory
source ${wai}/config.mk

# Compute intervals
ifrom=$(echo $from $LOG_INTERVAL | awk '{print($1-($1%$2))}')
ito=$(echo $to $LOG_INTERVAL | awk '{print($1-($1%$2))}')

# Search for power measurements
nfolder=$(readlink -f ${wai}/${SUBSCRIBER_DIR}/$key/) # Node Folder
[ ! -d "$nfolder" ] && { echo "Node \"$key\" has not power measurements."; exit 2; }
cfolder=${nfolder}/$(ls $nfolder/|head -n1)/ # Client FOlder
[ ! -d "$cfolder" ] && { echo "Node \"$key\" has no client folder yet."; exit 3; }
# Set from file and to file
ffile=${cfolder}/$ifrom
tfile=${cfolder}/$ito
[ ! -f "$ffile" ] && { echo "Node power measurements starting at $2."; exit 4; }
[ ! -f "$tfile" ] && { echo "Node power measurements up to $3."; exit 5; }
# Give files to the user
missings=0
header=0
for interval in $(seq $ifrom $LOG_INTERVAL $ito)
do
    file=${cfolder}/${interval}
    if [ ! -f "$file" ]
    then
        missings=$(( missings + 1 ))
        continue
    fi
    # Cat files
    if [ $header -eq 0 ]
    then
        cat $file
        header=1
    else
        tail -n +2 $file
    fi
done

# Report missings
[ $missings -gt 0 ] && { echo "Some power measurements are missings ($missings intervals of ${LOG_INTERVAL}s)" >&2; exit 6; }