-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
scraper.go
257 lines (210 loc) · 10.1 KB
/
scraper.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// 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 (
"context"
"fmt"
"time"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scrapererror"
"go.uber.org/multierr"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/activedirectorydsreceiver/internal/metadata"
)
type activeDirectoryDSScraper struct {
mb *metadata.MetricsBuilder
w *watchers
}
func newActiveDirectoryDSScraper(mbc metadata.MetricsBuilderConfig, params receiver.Settings) *activeDirectoryDSScraper {
return &activeDirectoryDSScraper{
mb: metadata.NewMetricsBuilder(mbc, params),
}
}
func (a *activeDirectoryDSScraper) start(_ context.Context, _ component.Host) error {
watchers, err := getWatchers(defaultWatcherCreater{})
if err != nil {
return fmt.Errorf("failed to create performance counter watchers: %w", err)
}
a.w = watchers
a.mb.Reset()
return nil
}
func (a *activeDirectoryDSScraper) scrape(_ context.Context) (pmetric.Metrics, error) {
var multiErr error
now := pcommon.NewTimestampFromTime(time.Now())
draInboundBytesCompressed, err := a.w.Scrape(draInboundBytesCompressed)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationNetworkIoDataPoint(now, int64(draInboundBytesCompressed), metadata.AttributeDirectionReceived, metadata.AttributeNetworkDataTypeCompressed)
}
draInboundBytesNotCompressed, err := a.w.Scrape(draInboundBytesNotCompressed)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationNetworkIoDataPoint(now, int64(draInboundBytesNotCompressed), metadata.AttributeDirectionReceived, metadata.AttributeNetworkDataTypeUncompressed)
}
draOutboundBytesCompressed, err := a.w.Scrape(draOutboundBytesCompressed)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationNetworkIoDataPoint(now, int64(draOutboundBytesCompressed), metadata.AttributeDirectionSent, metadata.AttributeNetworkDataTypeCompressed)
}
draOutboundBytesNotCompressed, err := a.w.Scrape(draOutboundBytesNotCompressed)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationNetworkIoDataPoint(now, int64(draOutboundBytesNotCompressed), metadata.AttributeDirectionSent, metadata.AttributeNetworkDataTypeUncompressed)
}
draInboundFullSyncObjectsRemaining, err := a.w.Scrape(draInboundFullSyncObjectsRemaining)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationSyncObjectPendingDataPoint(now, int64(draInboundFullSyncObjectsRemaining))
}
draInboundObjects, err := a.w.Scrape(draInboundObjects)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationObjectRateDataPoint(now, draInboundObjects, metadata.AttributeDirectionReceived)
}
draOutboundObjects, err := a.w.Scrape(draOutboundObjects)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationObjectRateDataPoint(now, draOutboundObjects, metadata.AttributeDirectionSent)
}
draInboundProperties, err := a.w.Scrape(draInboundProperties)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationPropertyRateDataPoint(now, draInboundProperties, metadata.AttributeDirectionReceived)
}
draOutboundProperties, err := a.w.Scrape(draOutboundProperties)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationPropertyRateDataPoint(now, draOutboundProperties, metadata.AttributeDirectionSent)
}
//revive:disable-next-line:var-naming
draInboundValuesDNs, dnsErr := a.w.Scrape(draInboundValuesDNs)
multiErr = multierr.Append(multiErr, dnsErr)
if dnsErr == nil {
a.mb.RecordActiveDirectoryDsReplicationValueRateDataPoint(now, draInboundValuesDNs, metadata.AttributeDirectionReceived, metadata.AttributeValueTypeDistingushedNames)
}
draInboundValuesTotal, totalErr := a.w.Scrape(draInboundValuesTotal)
multiErr = multierr.Append(multiErr, totalErr)
if dnsErr == nil && totalErr == nil {
otherValuesInbound := draInboundValuesTotal - draInboundValuesDNs
a.mb.RecordActiveDirectoryDsReplicationValueRateDataPoint(now, otherValuesInbound, metadata.AttributeDirectionReceived, metadata.AttributeValueTypeOther)
}
//revive:disable-next-line:var-naming
draOutboundValuesDNs, dnsErr := a.w.Scrape(draOutboundValuesDNs)
multiErr = multierr.Append(multiErr, dnsErr)
if dnsErr == nil {
a.mb.RecordActiveDirectoryDsReplicationValueRateDataPoint(now, draOutboundValuesDNs, metadata.AttributeDirectionSent, metadata.AttributeValueTypeDistingushedNames)
}
draOutboundValuesTotal, totalErr := a.w.Scrape(draOutboundValuesTotal)
multiErr = multierr.Append(multiErr, totalErr)
if dnsErr == nil && totalErr == nil {
otherValuesOutbound := draOutboundValuesTotal - draOutboundValuesDNs
a.mb.RecordActiveDirectoryDsReplicationValueRateDataPoint(now, otherValuesOutbound, metadata.AttributeDirectionSent, metadata.AttributeValueTypeOther)
}
draPendingReplicationOperations, err := a.w.Scrape(draPendingReplicationOperations)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsReplicationOperationPendingDataPoint(now, int64(draPendingReplicationOperations))
}
draSyncFailuresSchemaMistmatch, schemaMismatchErr := a.w.Scrape(draSyncFailuresSchemaMismatch)
multiErr = multierr.Append(multiErr, schemaMismatchErr)
if schemaMismatchErr == nil {
a.mb.RecordActiveDirectoryDsReplicationSyncRequestCountDataPoint(now, int64(draSyncFailuresSchemaMistmatch), metadata.AttributeSyncResultSchemaMismatch)
}
draSyncRequestsSuccessful, requestsSuccessfulErr := a.w.Scrape(draSyncRequestsSuccessful)
multiErr = multierr.Append(multiErr, requestsSuccessfulErr)
if requestsSuccessfulErr == nil {
a.mb.RecordActiveDirectoryDsReplicationSyncRequestCountDataPoint(now, int64(draSyncRequestsSuccessful), metadata.AttributeSyncResultSuccess)
}
draSyncRequestsTotal, totalErr := a.w.Scrape(draSyncRequestsMade)
multiErr = multierr.Append(multiErr, totalErr)
if totalErr == nil && requestsSuccessfulErr == nil && schemaMismatchErr == nil {
otherReplicationSyncRequests := draSyncRequestsTotal - draSyncRequestsSuccessful - draSyncFailuresSchemaMistmatch
a.mb.RecordActiveDirectoryDsReplicationSyncRequestCountDataPoint(now, int64(otherReplicationSyncRequests), metadata.AttributeSyncResultOther)
}
dsDirectoryReads, err := a.w.Scrape(dsDirectoryReads)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsOperationRateDataPoint(now, dsDirectoryReads, metadata.AttributeOperationTypeRead)
}
dsDirectoryWrites, err := a.w.Scrape(dsDirectoryWrites)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsOperationRateDataPoint(now, dsDirectoryWrites, metadata.AttributeOperationTypeWrite)
}
dsDirectorySearches, err := a.w.Scrape(dsDirectorySearches)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsOperationRateDataPoint(now, dsDirectorySearches, metadata.AttributeOperationTypeSearch)
}
dsClientBinds, err := a.w.Scrape(dsClientBinds)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsBindRateDataPoint(now, dsClientBinds, metadata.AttributeBindTypeClient)
}
dsServerBinds, err := a.w.Scrape(dsServerBinds)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsBindRateDataPoint(now, dsServerBinds, metadata.AttributeBindTypeServer)
}
dsCacheHitRate, err := a.w.Scrape(dsNameCacheHitRate)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsNameCacheHitRateDataPoint(now, dsCacheHitRate)
}
dsNotifyQueueSize, err := a.w.Scrape(dsNotifyQueueSize)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsNotificationQueuedDataPoint(now, int64(dsNotifyQueueSize))
}
securityPropEvents, err := a.w.Scrape(dsSecurityDescriptorPropagationsEvents)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsSecurityDescriptorPropagationsEventQueuedDataPoint(now, int64(securityPropEvents))
}
securityDescSubops, err := a.w.Scrape(dsSecurityDescripterSubOperations)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsSuboperationRateDataPoint(now, securityDescSubops, metadata.AttributeSuboperationTypeSecurityDescriptorPropagationsEvent)
}
searchSubops, err := a.w.Scrape(dsSearchSubOperations)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsSuboperationRateDataPoint(now, searchSubops, metadata.AttributeSuboperationTypeSearch)
}
threadsInUse, err := a.w.Scrape(dsThreadsInUse)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsThreadCountDataPoint(now, int64(threadsInUse))
}
ldapClientSessions, err := a.w.Scrape(ldapClientSessions)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsLdapClientSessionCountDataPoint(now, int64(ldapClientSessions))
}
ldapBindTime, err := a.w.Scrape(ldapBindTime)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsLdapBindLastSuccessfulTimeDataPoint(now, int64(ldapBindTime))
}
ldapSuccessfulBinds, err := a.w.Scrape(ldapSuccessfulBinds)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsLdapBindRateDataPoint(now, ldapSuccessfulBinds)
}
ldapSearches, err := a.w.Scrape(ldapSearches)
multiErr = multierr.Append(multiErr, err)
if err == nil {
a.mb.RecordActiveDirectoryDsLdapSearchRateDataPoint(now, ldapSearches)
}
if multiErr != nil {
return a.mb.Emit(), scrapererror.NewPartialScrapeError(multiErr, len(multierr.Errors(multiErr)))
}
return a.mb.Emit(), nil
}
func (a *activeDirectoryDSScraper) shutdown(_ context.Context) error {
return a.w.Close()
}