forked from influxdata/influxdb-relay
/
windows_points.go
94 lines (79 loc) · 2.21 KB
/
windows_points.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
package relay
import (
"regexp"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric"
)
// GraphiteMetric transforms a BeringeiPoint to Graphite compatible format
func GraphiteWindowsMetric(metricName string, tags map[string]string, timestamp int64, value interface{}, field string) telegraf.Metric {
var parsedMetric map[string]interface{}
switch metricName {
case "cpu":
parsedMetric, metricName = parseWindowsCPU(tags, field, metricName, value)
case "disk":
parsedMetric = map[string]interface{}{field: value}
metricName = "disk." + tags["device"]
case "diskio":
parsedMetric = map[string]interface{}{field: value}
metricName = "diskio." + tags["name"]
case "net":
parsedMetric = map[string]interface{}{field: value}
metricName = "net." + tags["interface"]
case "mem":
parsedMetric, metricName = parseMem(tags, field, metricName, value)
case "system":
parsedMetric, metricName = parseSystem(tags, field, metricName, value)
case "swap":
parsedMetric = parseSwap(tags, field, value)
default:
parsedMetric = map[string]interface{}{field: value}
}
if parsedMetric != nil {
m1, _ := metric.New(
metricName,
map[string]string{"id": tags["machine_id"]},
parsedMetric,
time.Unix(timestamp/1000000000, 0).UTC(),
)
return m1
}
return nil
}
func parseWindowsCPU(tags map[string]string, field, metricName string, value interface{}) (parsedMetric map[string]interface{}, metricNameFixed string) {
metricNameFixed = "cpu_extra.total"
// We only accept cpu-total for windows (for now)
if tags["cpu"] != "cpu-total" {
return nil, ""
}
r, _ := regexp.Compile(`usage_(.*[a-zA-Z0-9])`)
match := r.FindStringSubmatch(field)
var fieldFix string
if len(match) > 0 {
fieldFix = match[len(match)-1]
} else {
fieldFix = field
}
// transform fields to collectd compatible ones
switch fieldFix {
case "iowait":
fieldFix = "wait"
case "irq":
fieldFix = "interrupt"
}
parsedMetric = map[string]interface{}{fieldFix: value}
switch fieldFix {
case "idle",
"interrupt",
"nice",
"softirq",
"steal",
"system",
"user",
"wait":
return parsedMetric, metricNameFixed
default:
metricNameFixed = "cpu_extra"
return parsedMetric, metricNameFixed
}
}