-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
counters.go
235 lines (182 loc) · 7.91 KB
/
counters.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:build windows
package activedirectorydsreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/activedirectorydsreceiver"
import (
"fmt"
"go.uber.org/multierr"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/winperfcounters"
)
const (
draInboundBytesCompressed = "DRA Inbound Bytes Compressed (Between Sites, After Compression) Since Boot"
draInboundBytesNotCompressed = "DRA Inbound Bytes Not Compressed (Within Site) Since Boot"
draOutboundBytesCompressed = "DRA Outbound Bytes Compressed (Between Sites, After Compression) Since Boot"
draOutboundBytesNotCompressed = "DRA Outbound Bytes Not Compressed (Within Site) Since Boot"
draInboundFullSyncObjectsRemaining = "DRA Inbound Full Sync Objects Remaining"
draInboundObjects = "DRA Inbound Objects/sec"
draOutboundObjects = "DRA Outbound Objects/sec"
draInboundProperties = "DRA Inbound Properties Total/sec"
draOutboundProperties = "DRA Outbound Properties/sec"
draInboundValuesDNs = "DRA Inbound Values (DNs only)/sec" //revive:disable-line:var-naming
draInboundValuesTotal = "DRA Inbound Values Total/sec"
draOutboundValuesDNs = "DRA Outbound Values (DNs only)/sec" //revive:disable-line:var-naming
draOutboundValuesTotal = "DRA Outbound Values Total/sec"
draPendingReplicationOperations = "DRA Pending Replication Operations"
draSyncFailuresSchemaMismatch = "DRA Sync Failures on Schema Mismatch"
draSyncRequestsSuccessful = "DRA Sync Requests Successful"
draSyncRequestsMade = "DRA Sync Requests Made"
dsDirectoryReads = "DS Directory Reads/sec"
dsDirectoryWrites = "DS Directory Writes/sec"
dsDirectorySearches = "DS Directory Searches/sec"
dsClientBinds = "DS Client Binds/sec"
dsServerBinds = "DS Server Binds/sec"
dsNameCacheHitRate = "DS Name Cache hit rate"
dsNotifyQueueSize = "DS Notify Queue Size"
dsSecurityDescriptorPropagationsEvents = "DS Security Descriptor Propagations Events"
dsSearchSubOperations = "DS Search sub-operations/sec"
dsSecurityDescripterSubOperations = "DS Security Descriptor sub-operations/sec"
dsThreadsInUse = "DS Threads in Use"
ldapClientSessions = "LDAP Client Sessions"
ldapBindTime = "LDAP Bind Time"
ldapSuccessfulBinds = "LDAP Successful Binds/sec"
ldapSearches = "LDAP Searches/sec"
)
type watchers struct {
closed bool
counterNameToWatcher map[string]winperfcounters.PerfCounterWatcher
}
func (w *watchers) Scrape(name string) (float64, error) {
v, ok := w.counterNameToWatcher[name]
if !ok {
return 0, fmt.Errorf("counter \"%s\" was not initialized", name)
}
cv, err := v.ScrapeData()
if err != nil {
return 0, err
}
return cv[0].Value, nil
}
func (w *watchers) Close() error {
if w == nil || w.closed {
return nil
}
var err error
for _, v := range w.counterNameToWatcher {
err = multierr.Append(err, v.Close())
}
return err
}
func getWatchers(wc watcherCreater) (*watchers, error) {
var err error
w := &watchers{
counterNameToWatcher: make(map[string]winperfcounters.PerfCounterWatcher),
}
if w.counterNameToWatcher[draInboundBytesCompressed], err = wc.Create(draInboundBytesCompressed); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundBytesNotCompressed], err = wc.Create(draInboundBytesNotCompressed); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundBytesCompressed], err = wc.Create(draOutboundBytesCompressed); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundBytesNotCompressed], err = wc.Create(draOutboundBytesNotCompressed); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundFullSyncObjectsRemaining], err = wc.Create(draInboundFullSyncObjectsRemaining); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundObjects], err = wc.Create(draInboundObjects); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundObjects], err = wc.Create(draOutboundObjects); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundProperties], err = wc.Create(draInboundProperties); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundProperties], err = wc.Create(draOutboundProperties); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundValuesDNs], err = wc.Create(draInboundValuesDNs); err != nil {
return nil, err
}
if w.counterNameToWatcher[draInboundValuesTotal], err = wc.Create(draInboundValuesTotal); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundValuesDNs], err = wc.Create(draOutboundValuesDNs); err != nil {
return nil, err
}
if w.counterNameToWatcher[draOutboundValuesTotal], err = wc.Create(draOutboundValuesTotal); err != nil {
return nil, err
}
if w.counterNameToWatcher[draPendingReplicationOperations], err = wc.Create(draPendingReplicationOperations); err != nil {
return nil, err
}
if w.counterNameToWatcher[draSyncFailuresSchemaMismatch], err = wc.Create(draSyncFailuresSchemaMismatch); err != nil {
return nil, err
}
if w.counterNameToWatcher[draSyncRequestsSuccessful], err = wc.Create(draSyncRequestsSuccessful); err != nil {
return nil, err
}
if w.counterNameToWatcher[draSyncRequestsMade], err = wc.Create(draSyncRequestsMade); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsDirectoryReads], err = wc.Create(dsDirectoryReads); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsDirectoryWrites], err = wc.Create(dsDirectoryWrites); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsDirectorySearches], err = wc.Create(dsDirectorySearches); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsClientBinds], err = wc.Create(dsClientBinds); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsServerBinds], err = wc.Create(dsServerBinds); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsNameCacheHitRate], err = wc.Create(dsNameCacheHitRate); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsNotifyQueueSize], err = wc.Create(dsNotifyQueueSize); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsSecurityDescriptorPropagationsEvents], err = wc.Create(dsSecurityDescriptorPropagationsEvents); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsSearchSubOperations], err = wc.Create(dsSearchSubOperations); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsSecurityDescripterSubOperations], err = wc.Create(dsSecurityDescripterSubOperations); err != nil {
return nil, err
}
if w.counterNameToWatcher[dsThreadsInUse], err = wc.Create(dsThreadsInUse); err != nil {
return nil, err
}
if w.counterNameToWatcher[ldapClientSessions], err = wc.Create(ldapClientSessions); err != nil {
return nil, err
}
if w.counterNameToWatcher[ldapBindTime], err = wc.Create(ldapBindTime); err != nil {
return nil, err
}
if w.counterNameToWatcher[ldapSuccessfulBinds], err = wc.Create(ldapSuccessfulBinds); err != nil {
return nil, err
}
if w.counterNameToWatcher[ldapSearches], err = wc.Create(ldapSearches); err != nil {
return nil, err
}
return w, nil
}
type watcherCreater interface {
Create(counterName string) (winperfcounters.PerfCounterWatcher, error)
}
const (
instanceName = "NTDS"
object = "DirectoryServices"
)
type defaultWatcherCreater struct{}
func (defaultWatcherCreater) Create(counterName string) (winperfcounters.PerfCounterWatcher, error) {
return winperfcounters.NewWatcher(object, instanceName, counterName)
}