File tree 4 files changed +77
-2
lines changed
4 files changed +77
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ type LoadAvgMetrics struct {
14
14
Load15M float64
15
15
}
16
16
17
- // LoadAvg : Parsing the /proc/loadavg output for disk monitoring
17
+ // LoadAvg : Parsing the /proc/loadavg output for load average monitoring
18
18
type LoadAvg struct {
19
19
fields
20
20
Values LoadAvgMetrics
Original file line number Diff line number Diff line change
1
+ package inspector
2
+
3
+ import (
4
+ "strconv"
5
+ "strings"
6
+
7
+ log "github.com/sirupsen/logrus"
8
+ )
9
+
10
+ // UptimeMetrics : Metrics used by Uptime
11
+ type UptimeMetrics struct {
12
+ Up float64
13
+ Idle float64
14
+ }
15
+
16
+ // Uptime : Parsing the /proc/uptime output for uptime monitoring
17
+ type Uptime struct {
18
+ fields
19
+ Values UptimeMetrics
20
+ }
21
+
22
+ // Parse : run custom parsing on output of the command
23
+ func (i * Uptime ) Parse (output string ) {
24
+ var err error
25
+ log .Debug ("Parsing ouput string in Uptime inspector" )
26
+ columns := strings .Fields (output )
27
+ Up , err := strconv .ParseFloat (columns [0 ], 64 )
28
+ Idle , err := strconv .ParseFloat (columns [1 ], 64 )
29
+ if err != nil {
30
+ log .Fatalf (`Error Parsing Uptime: %s ` , err )
31
+ }
32
+
33
+ i .Values = UptimeMetrics {
34
+ Up ,
35
+ Idle ,
36
+ }
37
+ }
38
+
39
+ // NewUptime : Initialize a new Uptime instance
40
+ func NewUptime () * Uptime {
41
+ return & Uptime {
42
+ fields : fields {
43
+ Type : File ,
44
+ FilePath : `/proc/uptime` ,
45
+ },
46
+ }
47
+
48
+ }
Original file line number Diff line number Diff line change @@ -88,3 +88,16 @@ func TestLoadAvgonSSH(t *testing.T) {
88
88
t .Errorf ("%f" , i .Values .Load1M )
89
89
}
90
90
}
91
+
92
+ func TestUptimeonSSH (t * testing.T ) {
93
+ d := driver .NewSSHForTest ()
94
+ i := inspector .NewUptime ()
95
+ output , err := d .ReadFile (i .String ())
96
+ if err != nil {
97
+ t .Error (err )
98
+ }
99
+ i .Parse (output )
100
+ if i .Values .Up == 0 {
101
+ t .Errorf ("%f" , i .Values .Up )
102
+ }
103
+ }
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ func TestCustomonLocal(t *testing.T) {
105
105
}
106
106
107
107
func TestLoadAvgonLocal (t * testing.T ) {
108
- d := driver .NewSSHForTest ()
108
+ d := driver.Local {}
109
109
i := inspector .NewLoadAvg ()
110
110
output , err := d .ReadFile (i .String ())
111
111
if err != nil {
@@ -117,3 +117,17 @@ func TestLoadAvgonLocal(t *testing.T) {
117
117
}
118
118
fmt .Printf ("%#v" , i .Values )
119
119
}
120
+
121
+ func TestUptimeonLocal (t * testing.T ) {
122
+ d := driver.Local {}
123
+ i := inspector .NewUptime ()
124
+ output , err := d .ReadFile (i .String ())
125
+ if err != nil {
126
+ t .Error (err )
127
+ }
128
+ i .Parse (output )
129
+ if i .Values .Up == 0 {
130
+ t .Errorf ("%f" , i .Values .Up )
131
+ }
132
+ fmt .Printf ("%#v" , i .Values )
133
+ }
You can’t perform that action at this time.
0 commit comments