perfmonger 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +6 -2
- data/HOWTO.md +0 -1
- data/NEWS +15 -6
- data/README.md +77 -27
- data/Rakefile +18 -9
- data/core/Makefile +2 -18
- data/core/build.sh +1 -1
- data/core/perfmonger-player.go +71 -40
- data/core/perfmonger-plot-formatter.go +18 -4
- data/core/perfmonger-recorder.go +16 -2
- data/core/perfmonger-summarizer.go +19 -13
- data/core/subsystem/usage.go +143 -66
- data/core/subsystem/usage_test.go +62 -32
- data/{bin → exe}/perfmonger +0 -0
- data/lib/perfmonger/command/fingerprint.rb +26 -1
- data/lib/perfmonger/command/live.rb +19 -0
- data/lib/perfmonger/command/play.rb +16 -0
- data/lib/perfmonger/command/plot.rb +16 -10
- data/lib/perfmonger/command/server.rb +1 -1
- data/lib/perfmonger/version.rb +1 -1
- data/misc/werker-box/Dockerfile +35 -0
- data/misc/werker-box/build-push.sh +5 -0
- data/perfmonger.gemspec +2 -1
- data/spec/data/busy100.pgr.played +3 -3
- data/spec/fingerprint_spec.rb +1 -1
- data/spec/live_spec.rb +2 -3
- data/spec/perfmonger_spec.rb +1 -1
- data/spec/play_spec.rb +1 -1
- data/spec/plot_spec.rb +16 -1
- data/spec/record_spec.rb +10 -1
- data/spec/spec_helper.rb +28 -3
- data/spec/stat_spec.rb +2 -2
- data/spec/summary_spec.rb +1 -1
- data/wercker.yml +47 -16
- metadata +25 -10
@@ -11,23 +11,30 @@ import (
|
|
11
11
|
"io"
|
12
12
|
"io/ioutil"
|
13
13
|
"os"
|
14
|
+
"regexp"
|
14
15
|
"sort"
|
15
16
|
|
16
17
|
ss "github.com/hayamiz/perfmonger/core/subsystem"
|
17
18
|
)
|
18
19
|
|
19
20
|
type CmdOption struct {
|
20
|
-
DiskFile
|
21
|
-
CpuFile
|
22
|
-
PerfmongerFile
|
21
|
+
DiskFile string
|
22
|
+
CpuFile string
|
23
|
+
PerfmongerFile string
|
24
|
+
disk_only string
|
25
|
+
disk_only_regex *regexp.Regexp
|
23
26
|
}
|
24
27
|
|
25
28
|
func parseArgs() *CmdOption {
|
29
|
+
var err error
|
30
|
+
|
26
31
|
opt := new(CmdOption)
|
27
32
|
|
28
33
|
flag.StringVar(&opt.DiskFile, "diskfile", "./disk.dat", "Disk performance data file")
|
29
34
|
flag.StringVar(&opt.CpuFile, "cpufile", "./cpu.dat", "CPU performance data file")
|
30
35
|
flag.StringVar(&opt.PerfmongerFile, "perfmonger", "", "Perfmonger log file")
|
36
|
+
flag.StringVar(&opt.disk_only, "disk-only",
|
37
|
+
"", "Select disk devices by regex")
|
31
38
|
|
32
39
|
flag.Parse()
|
33
40
|
|
@@ -36,6 +43,11 @@ func parseArgs() *CmdOption {
|
|
36
43
|
os.Exit(1)
|
37
44
|
}
|
38
45
|
|
46
|
+
opt.disk_only_regex, err = regexp.Compile(opt.disk_only)
|
47
|
+
if err != nil {
|
48
|
+
panic(err)
|
49
|
+
}
|
50
|
+
|
39
51
|
return opt
|
40
52
|
}
|
41
53
|
|
@@ -192,7 +204,9 @@ func main() {
|
|
192
204
|
}
|
193
205
|
|
194
206
|
// Disk usage
|
195
|
-
dusage, err := ss.
|
207
|
+
dusage, err := ss.GetDiskUsage1(prev_rec.Time, prev_rec.Disk,
|
208
|
+
cur_rec.Time, cur_rec.Disk,
|
209
|
+
opt.disk_only_regex)
|
196
210
|
if err != nil {
|
197
211
|
panic(err)
|
198
212
|
}
|
data/core/perfmonger-recorder.go
CHANGED
@@ -43,6 +43,8 @@ type RecorderOption struct {
|
|
43
43
|
targetDisks *map[string]bool
|
44
44
|
background bool
|
45
45
|
gzip bool
|
46
|
+
color bool
|
47
|
+
pretty bool
|
46
48
|
}
|
47
49
|
|
48
50
|
var option RecorderOption
|
@@ -86,6 +88,10 @@ func parseArgs() {
|
|
86
88
|
"", "Run perfmonger-player to show JSON output")
|
87
89
|
flag.BoolVar(&option.gzip, "gzip",
|
88
90
|
false, "Save a logfile in gzipped format")
|
91
|
+
flag.BoolVar(&option.color, "color",
|
92
|
+
false, "Colored output (for live subcmd)")
|
93
|
+
flag.BoolVar(&option.pretty, "pretty",
|
94
|
+
false, "Pretty output (for live subcmd)")
|
89
95
|
|
90
96
|
flag.Parse()
|
91
97
|
|
@@ -190,7 +196,7 @@ func main() {
|
|
190
196
|
parseArgs()
|
191
197
|
|
192
198
|
hostname, _ := os.Hostname()
|
193
|
-
cheader := &ss.CommonHeader{ss.Linux, hostname, time.Now()}
|
199
|
+
cheader := &ss.CommonHeader{Platform: ss.Linux, Hostname: hostname, StartTime: time.Now()}
|
194
200
|
|
195
201
|
platform_header := ss.NewPlatformHeader()
|
196
202
|
|
@@ -206,7 +212,15 @@ func main() {
|
|
206
212
|
var player_stdout io.ReadCloser = nil
|
207
213
|
|
208
214
|
if option.player_bin != "" {
|
209
|
-
|
215
|
+
if option.color {
|
216
|
+
if option.pretty {
|
217
|
+
player_cmd = exec.Command(option.player_bin, "-color", "-pretty")
|
218
|
+
} else {
|
219
|
+
player_cmd = exec.Command(option.player_bin, "-color")
|
220
|
+
}
|
221
|
+
} else {
|
222
|
+
player_cmd = exec.Command(option.player_bin)
|
223
|
+
}
|
210
224
|
player_stdin, err = player_cmd.StdinPipe()
|
211
225
|
if err != nil {
|
212
226
|
fmt.Fprintf(os.Stderr, "Failed to get stdin of %s", option.player_bin)
|
@@ -3,7 +3,6 @@
|
|
3
3
|
package main
|
4
4
|
|
5
5
|
import (
|
6
|
-
"bytes"
|
7
6
|
"encoding/gob"
|
8
7
|
"flag"
|
9
8
|
"fmt"
|
@@ -12,6 +11,7 @@ import (
|
|
12
11
|
"regexp"
|
13
12
|
"sort"
|
14
13
|
|
14
|
+
projson "github.com/hayamiz/go-projson"
|
15
15
|
ss "github.com/hayamiz/perfmonger/core/subsystem"
|
16
16
|
)
|
17
17
|
|
@@ -137,32 +137,38 @@ func main() {
|
|
137
137
|
interval := lst_record.Time.Sub(fst_record.Time)
|
138
138
|
|
139
139
|
if option.json {
|
140
|
-
|
140
|
+
printer := projson.NewPrinter()
|
141
141
|
|
142
|
-
|
142
|
+
printer.BeginObject()
|
143
|
+
printer.PutKey("exectime")
|
144
|
+
printer.PutFloatFmt(interval.Seconds(), "%.3f")
|
143
145
|
if cpu_usage != nil {
|
144
|
-
|
145
|
-
cpu_usage.WriteJsonTo(
|
146
|
+
printer.PutKey("cpu")
|
147
|
+
cpu_usage.WriteJsonTo(printer)
|
146
148
|
}
|
147
149
|
|
148
150
|
if intr_usage != nil {
|
149
|
-
|
150
|
-
intr_usage.WriteJsonTo(
|
151
|
+
printer.PutKey("intr")
|
152
|
+
intr_usage.WriteJsonTo(printer)
|
151
153
|
}
|
152
154
|
|
153
155
|
if disk_usage != nil {
|
154
|
-
|
155
|
-
disk_usage.WriteJsonTo(
|
156
|
+
printer.PutKey("disk")
|
157
|
+
disk_usage.WriteJsonTo(printer)
|
156
158
|
}
|
157
159
|
|
158
160
|
if net_usage != nil {
|
159
|
-
|
160
|
-
net_usage.WriteJsonTo(
|
161
|
+
printer.PutKey("net")
|
162
|
+
net_usage.WriteJsonTo(printer)
|
161
163
|
}
|
162
164
|
|
163
|
-
|
165
|
+
printer.FinishObject()
|
164
166
|
|
165
|
-
|
167
|
+
if str, err := printer.String(); err != nil {
|
168
|
+
fmt.Println("skip by err")
|
169
|
+
} else {
|
170
|
+
fmt.Println(str)
|
171
|
+
}
|
166
172
|
} else {
|
167
173
|
if option.title == "" {
|
168
174
|
fmt.Println("== performance summary ==")
|
data/core/subsystem/usage.go
CHANGED
@@ -2,12 +2,13 @@ package subsystem
|
|
2
2
|
|
3
3
|
import (
|
4
4
|
"bytes"
|
5
|
-
"encoding/json"
|
6
5
|
"errors"
|
7
6
|
"fmt"
|
8
7
|
"regexp"
|
9
8
|
"sort"
|
10
9
|
"time"
|
10
|
+
|
11
|
+
projson "github.com/hayamiz/go-projson"
|
11
12
|
)
|
12
13
|
|
13
14
|
type CpuCoreUsage struct {
|
@@ -84,25 +85,52 @@ type NetUsageEntry struct {
|
|
84
85
|
|
85
86
|
type NetUsage map[string]*NetUsageEntry
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
ccusage.Hardirq, ccusage.Softirq, ccusage.Steal, ccusage.Guest, ccusage.GuestNice))
|
88
|
+
var UseColor = false
|
89
|
+
|
90
|
+
func SetUseColor(use_color bool) {
|
91
|
+
UseColor = use_color
|
92
92
|
}
|
93
93
|
|
94
|
-
func (
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
94
|
+
func (ccusage *CpuCoreUsage) WriteJsonTo(printer *projson.JsonPrinter) {
|
95
|
+
printer.BeginObject()
|
96
|
+
printer.PutKey("usr")
|
97
|
+
printer.PutFloatFmt(ccusage.User, "%.2f")
|
98
|
+
printer.PutKey("nice")
|
99
|
+
printer.PutFloatFmt(ccusage.Nice, "%.2f")
|
100
|
+
printer.PutKey("sys")
|
101
|
+
printer.PutFloatFmt(ccusage.Sys, "%.2f")
|
102
|
+
printer.PutKey("idle")
|
103
|
+
printer.PutFloatFmt(ccusage.Idle, "%.2f")
|
104
|
+
printer.PutKey("iowait")
|
105
|
+
printer.PutFloatFmt(ccusage.Iowait, "%.2f")
|
106
|
+
printer.PutKey("hardirq")
|
107
|
+
printer.PutFloatFmt(ccusage.Hardirq, "%.2f")
|
108
|
+
printer.PutKey("softirq")
|
109
|
+
printer.PutFloatFmt(ccusage.Softirq, "%.2f")
|
110
|
+
printer.PutKey("steal")
|
111
|
+
printer.PutFloatFmt(ccusage.Steal, "%.2f")
|
112
|
+
printer.PutKey("guest")
|
113
|
+
printer.PutFloatFmt(ccusage.Guest, "%.2f")
|
114
|
+
printer.PutKey("guestnice")
|
115
|
+
printer.PutFloatFmt(ccusage.GuestNice, "%.2f")
|
116
|
+
printer.FinishObject()
|
117
|
+
}
|
118
|
+
|
119
|
+
func (cusage *CpuUsage) WriteJsonTo(printer *projson.JsonPrinter) {
|
120
|
+
printer.BeginObject()
|
121
|
+
printer.PutKey("num_core")
|
122
|
+
printer.PutInt(cusage.NumCore)
|
123
|
+
printer.PutKey("all")
|
124
|
+
|
125
|
+
cusage.All.WriteJsonTo(printer)
|
126
|
+
|
127
|
+
printer.PutKey("cores")
|
128
|
+
printer.BeginArray()
|
129
|
+
for _, ccusage := range cusage.CoreUsages {
|
130
|
+
ccusage.WriteJsonTo(printer)
|
104
131
|
}
|
105
|
-
|
132
|
+
printer.FinishArray()
|
133
|
+
printer.FinishObject()
|
106
134
|
}
|
107
135
|
|
108
136
|
func GetCpuCoreUsage(c1 *CpuCoreStat, c2 *CpuCoreStat) (*CpuCoreUsage, error) {
|
@@ -225,35 +253,68 @@ func GetInterruptUsage(t1 time.Time, i1 *InterruptStat, t2 time.Time, i2 *Interr
|
|
225
253
|
return usage, nil
|
226
254
|
}
|
227
255
|
|
228
|
-
func (intr_usage *InterruptUsage) WriteJsonTo(
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
}
|
235
|
-
fmt.Fprintf(buf, "%.2f", core_usage.Device)
|
256
|
+
func (intr_usage *InterruptUsage) WriteJsonTo(printer *projson.JsonPrinter) {
|
257
|
+
printer.BeginObject()
|
258
|
+
printer.PutKey("core_dev_intr")
|
259
|
+
printer.BeginArray()
|
260
|
+
for _, core_usage := range intr_usage.CoreIntrUsages {
|
261
|
+
printer.PutFloatFmt(core_usage.Device, "%.2f")
|
236
262
|
}
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
263
|
+
printer.FinishArray()
|
264
|
+
|
265
|
+
printer.PutKey("core_sys_intr")
|
266
|
+
printer.BeginArray()
|
267
|
+
for _, core_usage := range intr_usage.CoreIntrUsages {
|
268
|
+
printer.PutFloatFmt(core_usage.System, "%.2f")
|
243
269
|
}
|
244
|
-
|
245
|
-
|
270
|
+
printer.FinishArray()
|
271
|
+
printer.FinishObject()
|
272
|
+
}
|
273
|
+
|
274
|
+
func (duentry *DiskUsageEntry) WriteJsonTo(printer *projson.JsonPrinter) {
|
275
|
+
printer.BeginObject()
|
276
|
+
printer.PutKey("riops")
|
277
|
+
printer.PutFloatFmt(duentry.RdIops, "%.2f")
|
278
|
+
printer.PutKey("wiops")
|
279
|
+
printer.PutFloatFmt(duentry.WrIops, "%.2f")
|
280
|
+
printer.PutKey("rkbyteps")
|
281
|
+
printer.PutFloatFmt(duentry.RdSecps/2.0, "%.2f")
|
282
|
+
printer.PutKey("wkbyteps")
|
283
|
+
printer.PutFloatFmt(duentry.WrSecps/2.0, "%.2f")
|
284
|
+
printer.PutKey("rlatency")
|
285
|
+
printer.PutFloatFmt(duentry.RdLatency, "%.3f")
|
286
|
+
printer.PutKey("wlatency")
|
287
|
+
printer.PutFloatFmt(duentry.WrLatency, "%.3f")
|
288
|
+
printer.PutKey("rsize")
|
289
|
+
printer.PutFloatFmt(duentry.AvgRdSize, "%.2f")
|
290
|
+
printer.PutKey("wsize")
|
291
|
+
printer.PutFloatFmt(duentry.AvgWrSize, "%.2f")
|
292
|
+
printer.PutKey("qlen")
|
293
|
+
printer.PutFloatFmt(duentry.ReqQlen, "%.2f")
|
294
|
+
printer.FinishObject()
|
246
295
|
}
|
247
296
|
|
248
|
-
func (
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
297
|
+
func strarrayToString(arr []string) string {
|
298
|
+
buf := bytes.NewBuffer([]byte{})
|
299
|
+
|
300
|
+
fmt.Fprintf(buf, "[")
|
301
|
+
for i, elem := range arr {
|
302
|
+
if i > 0 {
|
303
|
+
fmt.Fprintf(buf, ",")
|
304
|
+
}
|
305
|
+
|
306
|
+
if UseColor {
|
307
|
+
fmt.Fprintf(buf, "\033[35m\"%s\"\033[0m", elem)
|
308
|
+
} else {
|
309
|
+
fmt.Fprintf(buf, "\"%s\"", elem)
|
310
|
+
}
|
311
|
+
}
|
312
|
+
fmt.Fprintf(buf, "]")
|
313
|
+
|
314
|
+
return buf.String()
|
254
315
|
}
|
255
316
|
|
256
|
-
func (dusage *DiskUsage) WriteJsonTo(
|
317
|
+
func (dusage *DiskUsage) WriteJsonTo(printer *projson.JsonPrinter) {
|
257
318
|
var devices []string
|
258
319
|
|
259
320
|
for device, _ := range *dusage {
|
@@ -263,23 +324,24 @@ func (dusage *DiskUsage) WriteJsonTo(buf *bytes.Buffer) {
|
|
263
324
|
}
|
264
325
|
sort.Strings(devices)
|
265
326
|
|
266
|
-
|
267
|
-
|
268
|
-
|
327
|
+
printer.BeginObject()
|
328
|
+
printer.PutKey("devices")
|
329
|
+
printer.BeginArray()
|
330
|
+
for _, device := range devices {
|
331
|
+
printer.PutString(device)
|
269
332
|
}
|
270
|
-
|
333
|
+
printer.FinishArray()
|
271
334
|
|
272
335
|
devices = append(devices, "total")
|
273
336
|
|
274
337
|
for _, device := range devices {
|
275
338
|
usage := (*dusage)[device]
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
usage.WriteJsonTo(buf)
|
339
|
+
|
340
|
+
printer.PutKey(device)
|
341
|
+
usage.WriteJsonTo(printer)
|
280
342
|
}
|
281
343
|
|
282
|
-
|
344
|
+
printer.FinishObject()
|
283
345
|
}
|
284
346
|
|
285
347
|
func avgDelta(v int64, w int64, interval float64) float64 {
|
@@ -470,7 +532,7 @@ func GetNetUsage(t1 time.Time, d1 *NetStat, t2 time.Time, d2 *NetStat) (*NetUsag
|
|
470
532
|
return net_usage, nil
|
471
533
|
}
|
472
534
|
|
473
|
-
func (nusage *NetUsage) WriteJsonTo(
|
535
|
+
func (nusage *NetUsage) WriteJsonTo(printer *projson.JsonPrinter) {
|
474
536
|
var devices []string
|
475
537
|
|
476
538
|
for device, _ := range *nusage {
|
@@ -480,30 +542,45 @@ func (nusage *NetUsage) WriteJsonTo(buf *bytes.Buffer) {
|
|
480
542
|
}
|
481
543
|
sort.Strings(devices)
|
482
544
|
|
483
|
-
|
484
|
-
|
485
|
-
|
545
|
+
printer.BeginObject()
|
546
|
+
printer.PutKey("devices")
|
547
|
+
printer.BeginArray()
|
548
|
+
for _, device := range devices {
|
549
|
+
printer.PutString(device)
|
486
550
|
}
|
487
|
-
|
551
|
+
printer.FinishArray()
|
488
552
|
|
489
553
|
devices = append(devices, "total")
|
490
554
|
|
491
555
|
for _, device := range devices {
|
492
556
|
usage := (*nusage)[device]
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
usage.WriteJsonTo(buf)
|
557
|
+
|
558
|
+
printer.PutKey(device)
|
559
|
+
usage.WriteJsonTo(printer)
|
497
560
|
}
|
498
561
|
|
499
|
-
|
562
|
+
printer.FinishObject()
|
500
563
|
}
|
501
564
|
|
502
|
-
func (entry *NetUsageEntry) WriteJsonTo(
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
565
|
+
func (entry *NetUsageEntry) WriteJsonTo(printer *projson.JsonPrinter) {
|
566
|
+
printer.BeginObject()
|
567
|
+
|
568
|
+
printer.PutKey("rxkbyteps")
|
569
|
+
printer.PutFloatFmt(entry.RxBytesPerSec/1024.0, "%.2f")
|
570
|
+
printer.PutKey("rxpktps")
|
571
|
+
printer.PutFloatFmt(entry.RxPacketsPerSec, "%.2f")
|
572
|
+
printer.PutKey("rxerrps")
|
573
|
+
printer.PutFloatFmt(entry.RxErrorsPerSec, "%.2f")
|
574
|
+
printer.PutKey("rxdropps")
|
575
|
+
printer.PutFloatFmt(entry.RxDropsPerSec, "%.2f")
|
576
|
+
printer.PutKey("txkbyteps")
|
577
|
+
printer.PutFloatFmt(entry.TxBytesPerSec/1024.0, "%.2f")
|
578
|
+
printer.PutKey("txpktps")
|
579
|
+
printer.PutFloatFmt(entry.TxPacketsPerSec, "%.2f")
|
580
|
+
printer.PutKey("txerrps")
|
581
|
+
printer.PutFloatFmt(entry.TxErrorsPerSec, "%.2f")
|
582
|
+
printer.PutKey("txdropps")
|
583
|
+
printer.PutFloatFmt(entry.TxDropsPerSec, "%.2f")
|
584
|
+
|
585
|
+
printer.FinishObject()
|
509
586
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
package subsystem
|
2
2
|
|
3
3
|
import (
|
4
|
-
"bytes"
|
5
4
|
"encoding/json"
|
6
5
|
"math"
|
7
6
|
"regexp"
|
@@ -9,6 +8,8 @@ import (
|
|
9
8
|
"strings"
|
10
9
|
"testing"
|
11
10
|
"time"
|
11
|
+
|
12
|
+
projson "github.com/hayamiz/go-projson"
|
12
13
|
)
|
13
14
|
|
14
15
|
func isValidJson(byt []byte) bool {
|
@@ -89,7 +90,7 @@ func TestGetCoreUsage(t *testing.T) {
|
|
89
90
|
usage.Steal == 0 &&
|
90
91
|
usage.Guest == 0 &&
|
91
92
|
usage.GuestNice == 0) {
|
92
|
-
t.Error("usage is not 0
|
93
|
+
t.Error("usage is not 0 percent, want 0 percent")
|
93
94
|
}
|
94
95
|
|
95
96
|
// should return error if c1.Uptime() is larger than c2.Uptime()
|
@@ -120,10 +121,14 @@ func TestGetCoreUsage(t *testing.T) {
|
|
120
121
|
t.Errorf("usage.Sys = %v, want 25.0", usage.User)
|
121
122
|
}
|
122
123
|
|
123
|
-
|
124
|
-
usage.WriteJsonTo(
|
125
|
-
if
|
126
|
-
t.Errorf("
|
124
|
+
printer := projson.NewPrinter()
|
125
|
+
usage.WriteJsonTo(printer)
|
126
|
+
if str, err := printer.String(); err != nil {
|
127
|
+
t.Errorf("failed to print JSON")
|
128
|
+
} else {
|
129
|
+
if !isValidJson([]byte(str)) {
|
130
|
+
t.Errorf("Invalid JSON: %s", str)
|
131
|
+
}
|
127
132
|
}
|
128
133
|
}
|
129
134
|
|
@@ -207,15 +212,20 @@ func TestGetCpuUsage(t *testing.T) {
|
|
207
212
|
t.Errorf("usage.Sys = %v, want 25.0", usage.CoreUsages[1].User)
|
208
213
|
}
|
209
214
|
|
210
|
-
|
211
|
-
usage.WriteJsonTo(
|
212
|
-
|
213
|
-
|
215
|
+
printer := projson.NewPrinter()
|
216
|
+
usage.WriteJsonTo(printer)
|
217
|
+
str, err := printer.String()
|
218
|
+
if err != nil {
|
219
|
+
t.Errorf("failed printing JSON")
|
220
|
+
} else {
|
221
|
+
if !isValidJson([]byte(str)) {
|
222
|
+
t.Errorf("Invalid JSON: %s", str)
|
223
|
+
}
|
214
224
|
}
|
215
225
|
|
216
226
|
assertHasKey := func(key_path string) {
|
217
|
-
if !jsonHasKey(
|
218
|
-
t.Errorf("%v is not present in JSON:\n%v", key_path,
|
227
|
+
if !jsonHasKey([]byte(str), key_path) {
|
228
|
+
t.Errorf("%v is not present in JSON:\n%v", key_path, str)
|
219
229
|
}
|
220
230
|
}
|
221
231
|
assertHasKey("num_core")
|
@@ -291,10 +301,15 @@ func TestDiskUsage(t *testing.T) {
|
|
291
301
|
t.Errorf("sda.RdSectors = %v, want %v", (*usage)["sda"].RdSectors, 350)
|
292
302
|
}
|
293
303
|
|
294
|
-
|
295
|
-
usage.WriteJsonTo(
|
296
|
-
|
297
|
-
|
304
|
+
printer := projson.NewPrinter()
|
305
|
+
usage.WriteJsonTo(printer)
|
306
|
+
str, err := printer.String()
|
307
|
+
if err != nil {
|
308
|
+
t.Errorf("failed printing JSON")
|
309
|
+
} else {
|
310
|
+
if !isValidJson([]byte(str)) {
|
311
|
+
t.Errorf("invalid json: %s", str)
|
312
|
+
}
|
298
313
|
}
|
299
314
|
|
300
315
|
d1.Entries = append(d1.Entries, NewDiskStatEntry())
|
@@ -347,15 +362,20 @@ func TestDiskUsage(t *testing.T) {
|
|
347
362
|
t.Errorf("total.RdSectors = %v, want %v", (*usage)["total"].RdSectors, 350)
|
348
363
|
}
|
349
364
|
|
350
|
-
|
351
|
-
usage.WriteJsonTo(
|
352
|
-
|
353
|
-
|
365
|
+
printer = projson.NewPrinter()
|
366
|
+
usage.WriteJsonTo(printer)
|
367
|
+
str, err = printer.String()
|
368
|
+
if err != nil {
|
369
|
+
t.Errorf("failed printing JSON")
|
370
|
+
} else {
|
371
|
+
if !isValidJson([]byte(str)) {
|
372
|
+
t.Errorf("invalid json: %s", str)
|
373
|
+
}
|
354
374
|
}
|
355
375
|
|
356
376
|
assertHasKey := func(key_path string) {
|
357
|
-
if !jsonHasKey(
|
358
|
-
t.Errorf("%v is not present in JSON:\n%v", key_path,
|
377
|
+
if !jsonHasKey([]byte(str), key_path) {
|
378
|
+
t.Errorf("%v is not present in JSON:\n%v", key_path, str)
|
359
379
|
}
|
360
380
|
}
|
361
381
|
assertHasKey("devices")
|
@@ -428,10 +448,15 @@ func TestGetNetUsage(t *testing.T) {
|
|
428
448
|
t.Errorf("lo.RxPacketsPerSec = %v, want %v", (*usage)["lo"].RxPacketsPerSec, 100.0/interval)
|
429
449
|
}
|
430
450
|
|
431
|
-
|
432
|
-
usage.WriteJsonTo(
|
433
|
-
|
434
|
-
|
451
|
+
printer := projson.NewPrinter()
|
452
|
+
usage.WriteJsonTo(printer)
|
453
|
+
str, err := printer.String()
|
454
|
+
if err != nil {
|
455
|
+
t.Errorf("failed printing JSON")
|
456
|
+
} else {
|
457
|
+
if !isValidJson([]byte(str)) {
|
458
|
+
t.Errorf("invalid json: %s", str)
|
459
|
+
}
|
435
460
|
}
|
436
461
|
|
437
462
|
n1.Entries = append(n1.Entries, NewNetStatEntry())
|
@@ -483,15 +508,20 @@ func TestGetNetUsage(t *testing.T) {
|
|
483
508
|
(100.0+150.0)/interval)
|
484
509
|
}
|
485
510
|
|
486
|
-
|
487
|
-
usage.WriteJsonTo(
|
488
|
-
|
489
|
-
|
511
|
+
printer = projson.NewPrinter()
|
512
|
+
usage.WriteJsonTo(printer)
|
513
|
+
str, err = printer.String()
|
514
|
+
if err != nil {
|
515
|
+
t.Errorf("failed printing JSON")
|
516
|
+
} else {
|
517
|
+
if !isValidJson([]byte(str)) {
|
518
|
+
t.Errorf("invalid json: %s", str)
|
519
|
+
}
|
490
520
|
}
|
491
521
|
|
492
522
|
assertHasKey := func(key_path string) {
|
493
|
-
if !jsonHasKey(
|
494
|
-
t.Errorf("%v is not present in JSON:\n%v", key_path,
|
523
|
+
if !jsonHasKey([]byte(str), key_path) {
|
524
|
+
t.Errorf("%v is not present in JSON:\n%v", key_path, str)
|
495
525
|
}
|
496
526
|
}
|
497
527
|
assertHasKey("devices")
|