forked from etcd-io/dbtester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_read_raw_data_to_test_data.go
110 lines (100 loc) · 2.75 KB
/
01_read_raw_data_to_test_data.go
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
// Copyright 2017 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package analyze
import (
"fmt"
"strconv"
"github.com/gyuho/dataframe"
)
// sysMetricsColumnsToRead is already aggregated
// and interpolated by unix second.
var sysMetricsColumnsToRead = []string{
"UNIX-SECOND",
"VOLUNTARY-CTXT-SWITCHES",
"NON-VOLUNTARY-CTXT-SWITCHES",
"CPU-NUM",
"LOAD-AVERAGE-1-MINUTE",
"VMRSS-NUM",
"READS-COMPLETED",
"READS-COMPLETED-DELTA",
"SECTORS-READ",
"SECTORS-READ-DELTA",
"WRITES-COMPLETED",
"WRITES-COMPLETED-DELTA",
"SECTORS-WRITTEN",
"SECTORS-WRITTEN-DELTA",
"READ-BYTES-DELTA",
"WRITE-BYTES-DELTA",
"RECEIVE-BYTES-NUM",
"RECEIVE-BYTES-NUM-DELTA",
"TRANSMIT-BYTES-NUM",
"TRANSMIT-BYTES-NUM-DELTA",
"EXTRA", // will be converted to 'CLIENT-NUM'
}
type testData struct {
filePath string
frontUnixSecond int64
lastUnixSecond int64
frame dataframe.Frame
}
// readSystemMetrics extracts only the columns that we need for analyze.
func readSystemMetrics(fpath string) (data testData, err error) {
originalFrame, err := dataframe.NewFromCSV(nil, fpath)
if err != nil {
return testData{}, err
}
data.filePath = fpath
data.frame = dataframe.New()
var unixSecondCol dataframe.Column
for _, name := range sysMetricsColumnsToRead {
var column dataframe.Column
column, err = originalFrame.Column(name)
if err != nil {
return testData{}, err
}
if err = data.frame.AddColumn(column); err != nil {
return testData{}, err
}
if name == "UNIX-SECOND" {
unixSecondCol = column
}
}
// get first(minimum) unix second
fv, ok := unixSecondCol.FrontNonNil()
if !ok {
return testData{}, fmt.Errorf("FrontNonNil %s has empty Unix time %v", fpath, fv)
}
fs, ok := fv.String()
if !ok {
return testData{}, fmt.Errorf("cannot String %v", fv)
}
data.frontUnixSecond, err = strconv.ParseInt(fs, 10, 64)
if err != nil {
return testData{}, err
}
// get last(maximum) unix second
bv, ok := unixSecondCol.BackNonNil()
if !ok {
return testData{}, fmt.Errorf("BackNonNil %s has empty Unix time %v", fpath, fv)
}
bs, ok := bv.String()
if !ok {
return testData{}, fmt.Errorf("cannot String %v", bv)
}
data.lastUnixSecond, err = strconv.ParseInt(bs, 10, 64)
if err != nil {
return testData{}, err
}
return
}