122
|
1 |
#! /bin/zsh |
|
2 |
# |
|
3 |
# Instance statistics for a given period (default: 4 last weeks) |
|
4 |
# |
|
5 |
# Usage: $0 [[--server INSTANCE] Number_of_weeks] |
|
6 |
# |
|
7 |
# Mikael |
|
8 |
|
|
9 |
if [[ $1 == "--server" || $1 == "-i" ]]; then |
|
10 |
opt=("--server" "$2") |
|
11 |
shift 2 |
|
12 |
fi |
|
13 |
|
|
14 |
w=${1:-4} |
|
15 |
|
|
16 |
TMPL='({{(.date | fromunix).Format "2006-01-02"}}) {{.instance_name}}: {{printf "%.0f users, %.0f statuses\n" .users .statuses}}' |
|
17 |
|
|
18 |
typeset -i wa="$w" |
|
19 |
while (( wa >= 0 )); do |
|
20 |
when="$wa weeks ago" |
|
21 |
s=$(date +%s -d "$when") |
|
22 |
stats="$(madonctl instance ${opt[*]} --stats --template "$TMPL" \ |
|
23 |
--start "$(( s-3600 ))" --end "$s" | tail -1)" |
|
24 |
if [[ -n $stats ]]; then |
|
25 |
echo "$when $stats" |
|
26 |
fi |
|
27 |
(( wa-=1 )) |
|
28 |
done |