forked from simagix/mongo-ftdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attribs.go
127 lines (118 loc) · 6.24 KB
/
attribs.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2020-present Kuei-chun Chen. All rights reserved.
// attribs.go
package ftdc
import (
"math"
"strings"
"time"
"github.com/simagix/mongo-ftdc/decoder"
)
// Attribs stores attribs map
type Attribs struct {
attribsMap *map[string][]uint64
}
// NewAttribs returns Attribs structure
func NewAttribs(attribsMap *map[string][]uint64) *Attribs {
return &Attribs{attribsMap: attribsMap}
}
// GetServerStatusDataPoints returns server status
func (attr *Attribs) GetServerStatusDataPoints(i int) ServerStatusDoc {
ss := ServerStatusDoc{}
ss.LocalTime = time.Unix(0, int64(time.Millisecond)*int64(attr.get("serverStatus/localTime", i)))
ss.Mem.Resident = attr.get("serverStatus/mem/resident", i)
ss.Mem.Virtual = attr.get("serverStatus/mem/virtual", i)
ss.Network.BytesIn = attr.get("serverStatus/network/bytesIn", i)
ss.Network.BytesOut = attr.get("serverStatus/network/bytesOut", i)
ss.Network.NumRequests = attr.get("serverStatus/network/numRequests", i)
ss.Network.PhysicalBytesIn = attr.get("serverStatus/network/physicalBytesIn", i)
ss.Network.PhysicalBytesOut = attr.get("serverStatus/network/physicalBytesOut", i)
ss.Connections.Current = attr.get("serverStatus/connections/current", i)
ss.Connections.TotalCreated = attr.get("serverStatus/connections/totalCreated", i)
ss.Connections.Available = attr.get("serverStatus/connections/available", i)
ss.Connections.Active = attr.get("serverStatus/connections/active", i)
ss.ExtraInfo.PageFaults = attr.get("serverStatus/extra_info/page_faults", i)
ss.GlobalLock.ActiveClients.Readers = attr.get("serverStatus/globalLock/activeClients/readers", i)
ss.GlobalLock.ActiveClients.Writers = attr.get("serverStatus/globalLock/activeClients/writers", i)
ss.GlobalLock.CurrentQueue.Readers = attr.get("serverStatus/globalLock/currentQueue/readers", i)
ss.GlobalLock.CurrentQueue.Writers = attr.get("serverStatus/globalLock/currentQueue/writers", i)
ss.Metrics.QueryExecutor.Scanned = attr.get("serverStatus/metrics/queryExecutor/scanned", i)
ss.Metrics.QueryExecutor.ScannedObjects = attr.get("serverStatus/metrics/queryExecutor/scannedObjects", i)
ss.Metrics.Operation.ScanAndOrder = attr.get("serverStatus/metrics/operation/scanAndOrder", i)
ss.OpLatencies.Commands.Latency = attr.get("serverStatus/opLatencies/commands/latency", i)
ss.OpLatencies.Commands.Ops = attr.get("serverStatus/opLatencies/commands/ops", i)
ss.OpLatencies.Reads.Latency = attr.get("serverStatus/opLatencies/reads/latency", i)
ss.OpLatencies.Reads.Ops = attr.get("serverStatus/opLatencies/reads/ops", i)
ss.OpLatencies.Writes.Latency = attr.get("serverStatus/opLatencies/writes/latency", i)
ss.OpLatencies.Writes.Ops = attr.get("serverStatus/opLatencies/writes/ops", i)
ss.OpCounters.Command = attr.get("serverStatus/opcounters/command", i)
ss.OpCounters.Delete = attr.get("serverStatus/opcounters/delete", i)
ss.OpCounters.Getmore = attr.get("serverStatus/opcounters/getmore", i)
ss.OpCounters.Insert = attr.get("serverStatus/opcounters/insert", i)
ss.OpCounters.Query = attr.get("serverStatus/opcounters/query", i)
ss.OpCounters.Update = attr.get("serverStatus/opcounters/update", i)
ss.Uptime = attr.get("serverStatus/uptime", i)
ss.WiredTiger.BlockManager.BytesRead = attr.get("serverStatus/wiredTiger/block-manager/bytes read", i)
ss.WiredTiger.BlockManager.BytesWritten = attr.get("serverStatus/wiredTiger/block-manager/bytes written", i)
ss.WiredTiger.BlockManager.BytesWrittenCheckPoint = attr.get("serverStatus/wiredTiger/block-manager/bytes written for checkpoint", i)
ss.WiredTiger.Cache.CurrentlyInCache = attr.get("serverStatus/wiredTiger/cache/bytes currently in the cache", i)
ss.WiredTiger.Cache.MaxBytesConfigured = attr.get("serverStatus/wiredTiger/cache/maximum bytes configured", i)
ss.WiredTiger.Cache.ModifiedPagesEvicted = attr.get("serverStatus/wiredTiger/cache/modified pages evicted", i)
ss.WiredTiger.Cache.BytesReadIntoCache = attr.get("serverStatus/wiredTiger/cache/bytes read into cache", i)
ss.WiredTiger.Cache.BytesWrittenFromCache = attr.get("serverStatus/wiredTiger/cache/bytes written from cache", i)
ss.WiredTiger.Cache.TrackedDirtyBytes = attr.get("serverStatus/wiredTiger/cache/tracked dirty bytes in the cache", i)
ss.WiredTiger.Cache.UnmodifiedPagesEvicted = attr.get("serverStatus/wiredTiger/cache/unmodified pages evicted", i)
ss.WiredTiger.DataHandle.Active = attr.get("serverStatus/wiredTiger/data-handle/connection data handles currently active", i)
ss.WiredTiger.ConcurrentTransactions.Read.Available = attr.get("serverStatus/wiredTiger/concurrentTransactions/read/available", i)
ss.WiredTiger.ConcurrentTransactions.Write.Available = attr.get("serverStatus/wiredTiger/concurrentTransactions/write/available", i)
return ss
}
// GetSystemMetricsDataPoints returns system metrics
func (attr *Attribs) GetSystemMetricsDataPoints(i int) SystemMetricsDoc {
attribs := *attr.attribsMap
sm := SystemMetricsDoc{Disks: map[string]DiskMetrics{}}
sm.Start = time.Unix(0, int64(time.Millisecond)*int64(attr.get("serverStatus/localTime", i)))
sm.CPU.IdleMS = attr.get("systemMetrics/cpu/idle_ms", i)
sm.CPU.UserMS = attr.get("systemMetrics/cpu/user_ms", i)
sm.CPU.IOWaitMS = attr.get("systemMetrics/cpu/iowait_ms", i)
sm.CPU.NiceMS = attr.get("systemMetrics/cpu/nice_ms", i)
sm.CPU.SoftirqMS = attr.get("systemMetrics/cpu/softirq_ms", i)
sm.CPU.StealMS = attr.get("systemMetrics/cpu/steal_ms", i)
sm.CPU.SystemMS = attr.get("systemMetrics/cpu/system_ms", i)
for key := range attribs {
if strings.Index(key, "systemMetrics/disks/") != 0 {
continue
}
tokens := strings.Split(key, decoder.PathSeparator)
disk := tokens[2]
stats := tokens[3]
if _, ok := sm.Disks[disk]; !ok {
sm.Disks[disk] = DiskMetrics{}
}
m := sm.Disks[disk]
switch stats {
case "read_time_ms":
m.ReadTimeMS = attr.get(key, i)
case "write_time_ms":
m.WriteTimeMS = attr.get(key, i)
case "io_queued_ms":
m.IOQueuedMS = attr.get(key, i)
case "io_time_ms":
m.IOTimeMS = attr.get(key, i)
case "reads":
m.Reads = attr.get(key, i)
case "writes":
m.Writes = attr.get(key, i)
case "io_in_progress":
m.IOInProgress = attr.get(key, i)
}
sm.Disks[disk] = m
}
return sm
}
func (attr *Attribs) get(key string, i int) uint64 {
arr := (*attr.attribsMap)[key]
if i < len(arr) && !math.IsNaN(float64(arr[i])) {
return arr[i]
}
return 0
}