-
Notifications
You must be signed in to change notification settings - Fork 73
/
metrics2csv
executable file
·121 lines (105 loc) · 3.7 KB
/
metrics2csv
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Usage:
#
# metrics2csv test server
#
# Or recursive re-processing of an entire directory tree instead:
#
# metrics2csv recurse
source ./config
TEST=$1
RESULTPSQL="psql -h $RESULTHOST -U $RESULTUSER -p $RESULTPORT -d $RESULTDB"
# Scaffolding for re-testing the import code
function clear {
$RESULTPSQL -c "TRUNCATE TABLE test_metrics_data;"
}
function show {
$RESULTPSQL -c "SELECT metric,collected,value FROM test_metrics_data WHERE server='${SERVERNAME}' and test=${TEST} ORDER BY collected,metric LIMIT 10"
}
function process {
# In theory I could rely on existing environment variables to figure these both
# out. In practice that's already caused one bug, so parameters for these two.
TESTNUM="$1"
H="$2"
if [ ! -f "results.txt" ] ; then
echo Not a test result directory, skipping
return 1
fi
if [ -s "meminfo.log" ] ; then
# Linux
echo Processing Linux formatted log files server ${H} test $TESTNUM
../../../csv2gnuplot -i iostat.log -d iostat -s "Device" -t "pgbench disk" --disks=${DISKLIST} -o iostat
../../../csv2gnuplot -i vmstat.log -d vmstat -s "cache" -t "pgbench vmstat" -o vmstat
../../../dirty-plot < meminfo.log > dirtydata.txt
else
# Assume Darwin for now, eventually others?
echo Processing Darwin formatted log files server $H test $TESTNUM
../../../csv2gnuplot -i iostat.log -d iostat -s "KB/t" -t "pgbench disk" -o iostat
../../../csv2gnuplot -i vmstat.log -d vmstat -s "wired" -t "pgbench vmstat" -o vmstat
fi
$RESULTPSQL -f ../../../export-latency-metric.sql
$RESULTPSQL -c "TRUNCATE TABLE tmp_metric_import;"
$RESULTPSQL -c "\copy tmp_metric_import FROM 'psql.log' WITH DELIMITER '|'"
$RESULTPSQL -c "\copy tmp_metric_import FROM 'latency_metric.csv' WITH CSV HEADER"
$RESULTPSQL -c "\copy tmp_metric_import FROM 'vmstat.csv' WITH CSV HEADER"
$RESULTPSQL -c "\copy tmp_metric_import FROM 'iostat.csv' WITH CSV HEADER"
if [ -f "meminfo.csv" ] ; then
$RESULTPSQL -c "\copy tmp_metric_import FROM 'meminfo.csv' WITH CSV HEADER"
fi
$RESULTPSQL -c "DELETE FROM test_metrics_data WHERE test=${TESTNUM} AND server='${H}'"
$RESULTPSQL -e -c "INSERT INTO test_metrics_data (collected,value,metric,test,server) SELECT collected,value,metric,${TESTNUM},'${H}' FROM tmp_metric_import;"
$RESULTPSQL -e -c "
WITH S AS (
SELECT test,server,date_trunc('second',ts) AS collected,
round(min(schedule_lag)::numeric / 1000,3) AS min_schedule_lag_ms,
round(avg(schedule_lag)::numeric / 1000,3) AS avg_schedule_lag_ms,
round(max(schedule_lag)::numeric / 1000,3) AS max_schedule_lag_ms
FROM timing GROUP BY test,server,date_trunc('second',ts)),
L AS (
SELECT test,server,collected,min_schedule_lag_ms AS lag_val,'min_schedule_lag_ms' AS metric FROM S UNION
SELECT test,server,collected,max_schedule_lag_ms,'max_schedule_lag_ms' FROM S UNION
SELECT test,server,collected,avg_schedule_lag_ms,'avg_schedule_lag_ms' FROM S)
INSERT INTO test_metrics_data (collected,value,metric,test,server)
SELECT collected,lag_val,metric,test,server FROM l;"
}
#
# Recurse import an entire directory tree
#
function reprocess {
shopt -s nullglob
pushd results
for serv in *
do
if [ -d $serv ] ; then
pushd $serv
echo "Server directory $serv"
for t in *
do
if [ -d $t ] ; then
pushd $t
echo "Result directory $d/$f"
process $t $serv
popd
fi
done
popd
fi
done
}
#
# Main
#
if [ "$1" = "recurse" ] ; then
echo "Recursion mode"
reprocess
elif [ -n "$2" ] ; then
# Try to handle being called from test results directory or from
# toolkit base directory
if [ ! -f "iostat.log" ] ; then
pushd results/$2/$1
fi
process $1 $2
else
echo "Usage: metrics2csv test server."
echo "Or use 'recurse' from the code directory for automatic mode."
fi