Update windows.plugin (#21466)
thiagoftsm committed
Dec 16, 2025 at 21:48 UTC
00427eb60839a40b04d7cdc9a8c73989a53cd9de
5 files changed
+130
-141
src/collectors/windows.plugin/GetServicesStatus.c
+12
-35
@@ -42,7 +42,7 @@ static void initialize(void)
42
static BOOL fill_dictionary_with_content()
43
{
44
PVOID buffer = NULL;
45
- static DWORD bytes_needed = 0;
45
+ DWORD bytes_needed = 0;
46
47
LPENUM_SERVICE_STATUS_PROCESS service, services;
48
DWORD total_services = 0;
@@ -64,47 +64,24 @@ static BOOL fill_dictionary_with_content()
64
NULL,
65
NULL);
66
67
- DWORD test = GetLastError();
68
- if (test == ERROR_MORE_DATA) {
69
- if (unlikely(!buffer))
70
- buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes_needed);
71
- else
72
- buffer = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer, bytes_needed);
73
- } else {
74
- switch (test) {
75
- case ERROR_ACCESS_DENIED:
76
- case ERROR_INVALID_PARAMETER:
77
- case ERROR_INVALID_HANDLE:
78
- case ERROR_INVALID_LEVEL:
79
- case ERROR_SHUTDOWN_IN_PROGRESS:
80
- ret = FALSE;
81
- goto endServiceCollection;
82
- default:
83
- ret = TRUE;
84
- }
67
+ if (ret) {
68
+ // This only happens if there are truly 0 services in the system (a valid edge case).
69
+ goto endServiceCollection;
70
+ }
71
+
72
+ if (GetLastError() != ERROR_MORE_DATA) {
73
+ goto endServiceCollection;
74
}
75
76
+ buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes_needed);
77
if (!buffer) {
78
ret = FALSE;
79
goto endServiceCollection;
80
}
81
92
- if (!ret) {
93
- ret = EnumServicesStatusEx(
94
- ndSCMH,
95
- SC_ENUM_PROCESS_INFO,
96
- SERVICE_WIN32,
97
- SERVICE_STATE_ALL,
98
- (LPBYTE)buffer,
99
- bytes_needed,
100
- (LPDWORD)&bytes_needed,
101
- (LPDWORD)&total_services,
102
- NULL,
103
- NULL);
104
-
105
- if (!ret) {
106
- goto endServiceCollection;
107
- }
82
+ if (!EnumServicesStatusEx(ndSCMH, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL,
83
+ (LPBYTE)buffer, bytes_needed, &bytes_needed, &total_services, NULL, NULL)) {
84
+ goto endServiceCollection;
85
}
86
87
services = (LPENUM_SERVICE_STATUS_PROCESS)buffer;
src/collectors/windows.plugin/perflib-ad.c
+98
-89
@@ -3,11 +3,6 @@
3
#include "windows_plugin.h"
4
#include "windows-internals.h"
5
6
-static void initialize(void)
7
-{
8
- ;
9
-}
10
-
6
static void netdata_ad_directory(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
7
{
8
static COUNTER_DATA directoryPercReadsFromDCA = {.key = "DS % Reads from DRA"};
@@ -119,9 +114,12 @@ static void netdata_ad_cache_lookups(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TY
114
static RRDSET *st_name_cache_lookups_total = NULL;
115
static RRDDIM *rd_name_cache_lookups_total = NULL;
116
122
- if (perflibGetObjectCounter(pDataBlock, pObjectType, &nameCacheLookupsTotal)) {
123
- if (unlikely(!st_name_cache_lookups_total)) {
124
- st_name_cache_lookups_total = rrdset_create_localhost(
117
+ if (!perflibGetObjectCounter(pDataBlock, pObjectType, &nameCacheLookupsTotal)) {
118
+ return;
119
+ }
120
+
121
+ if (unlikely(!st_name_cache_lookups_total)) {
122
+ st_name_cache_lookups_total = rrdset_create_localhost(
123
"ad",
124
"name_cache_lookups",
125
NULL,
@@ -135,16 +133,15 @@ static void netdata_ad_cache_lookups(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TY
133
update_every,
134
RRDSET_TYPE_LINE);
135
138
- rd_name_cache_lookups_total =
136
+ rd_name_cache_lookups_total =
137
rrddim_add(st_name_cache_lookups_total, "lookups", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
140
- }
138
+ }
139
142
- rrddim_set_by_pointer(
140
+ rrddim_set_by_pointer(
141
st_name_cache_lookups_total,
142
rd_name_cache_lookups_total,
143
(collected_number)nameCacheLookupsTotal.current.Data);
146
- rrdset_done(st_name_cache_lookups_total);
147
- }
144
+ rrdset_done(st_name_cache_lookups_total);
145
}
146
147
static void netdata_ad_cache_hits(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
@@ -154,9 +151,12 @@ static void netdata_ad_cache_hits(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE
151
static RRDSET *st_name_cache_hits_total = NULL;
152
static RRDDIM *rd_name_cache_hits_total = NULL;
153
157
- if (perflibGetObjectCounter(pDataBlock, pObjectType, &nameCacheHitsTotal)) {
158
- if (unlikely(!st_name_cache_hits_total)) {
159
- st_name_cache_hits_total = rrdset_create_localhost(
154
+ if (!perflibGetObjectCounter(pDataBlock, pObjectType, &nameCacheHitsTotal)) {
155
+ return;
156
+ }
157
+
158
+ if (unlikely(!st_name_cache_hits_total)) {
159
+ st_name_cache_hits_total = rrdset_create_localhost(
160
"ad",
161
"name_cache_hits",
162
NULL,
@@ -170,14 +170,13 @@ static void netdata_ad_cache_hits(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE
170
update_every,
171
RRDSET_TYPE_LINE);
172
173
- rd_name_cache_hits_total =
173
+ rd_name_cache_hits_total =
174
rrddim_add(st_name_cache_hits_total, "hits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
175
- }
175
+ }
176
177
- rrddim_set_by_pointer(
177
+ rrddim_set_by_pointer(
178
st_name_cache_hits_total, rd_name_cache_hits_total, (collected_number)nameCacheHitsTotal.current.Data);
179
- rrdset_done(st_name_cache_hits_total);
180
- }
179
+ rrdset_done(st_name_cache_hits_total);
180
}
181
182
static void netdata_ad_searches(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
@@ -522,19 +521,18 @@ netdata_ad_service_threads_in_use(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE
521
rrdset_done(st_directory_services_threads);
522
}
523
525
-static void netdata_ad_bind(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
524
+static void netdata_ad_bind_time(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
525
{
526
static COUNTER_DATA ldapLastBindTimeSecondsTotal = {.key = "DAP Bind Time"};
528
- static COUNTER_DATA bindsTotal = {.key = "DS Server Binds/sec"};
529
-
527
static RRDSET *st_ldap_last_bind_time_seconds_total = NULL;
528
static RRDDIM *rd_ldap_last_bind_time_seconds_total = NULL;
532
- static RRDSET *st_binds_total = NULL;
533
- static RRDDIM *rd_binds_total = NULL;
529
535
- if (perflibGetObjectCounter(pDataBlock, pObjectType, &ldapLastBindTimeSecondsTotal)) {
536
- if (unlikely(!st_ldap_last_bind_time_seconds_total)) {
537
- st_ldap_last_bind_time_seconds_total = rrdset_create_localhost(
530
+ if (!perflibGetObjectCounter(pDataBlock, pObjectType, &ldapLastBindTimeSecondsTotal)) {
531
+ return;
532
+ }
533
+
534
+ if (unlikely(!st_ldap_last_bind_time_seconds_total)) {
535
+ st_ldap_last_bind_time_seconds_total = rrdset_create_localhost(
536
"ad",
537
"ldap_last_bind_time",
538
NULL,
@@ -548,16 +546,23 @@ static void netdata_ad_bind(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObje
546
update_every,
547
RRDSET_TYPE_LINE);
548
551
- rd_ldap_last_bind_time_seconds_total =
549
+ rd_ldap_last_bind_time_seconds_total =
550
rrddim_add(st_ldap_last_bind_time_seconds_total, "last_bind", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
553
- }
551
+ }
552
555
- rrddim_set_by_pointer(
553
+ rrddim_set_by_pointer(
554
st_ldap_last_bind_time_seconds_total,
555
rd_ldap_last_bind_time_seconds_total,
556
(collected_number)ldapLastBindTimeSecondsTotal.current.Data);
559
- rrdset_done(st_ldap_last_bind_time_seconds_total);
560
- }
557
+ rrdset_done(st_ldap_last_bind_time_seconds_total);
558
+}
559
+
560
+static void netdata_ad_binds(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
561
+{
562
+ static COUNTER_DATA bindsTotal = {.key = "DS Server Binds/sec"};
563
+
564
+ static RRDSET *st_binds_total = NULL;
565
+ static RRDDIM *rd_binds_total = NULL;
566
567
if (perflibGetObjectCounter(pDataBlock, pObjectType, &bindsTotal)) {
568
if (unlikely(!st_binds_total)) {
@@ -583,46 +588,19 @@ static void netdata_ad_bind(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObje
588
}
589
}
590
586
-static void netdata_ad_atq(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
591
+static void netdata_ad_bind(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
592
{
588
- static COUNTER_DATA atqAverageRequestLatency = {.key = "ATQ Request Latency"};
589
- //static COUNTER_DATA atqOutstandingRequests = { .key = "ATQ Outstanding Queued Requests" };
593
+ netdata_ad_bind_time(pDataBlock, pObjectType, update_every);
594
+ netdata_ad_binds(pDataBlock, pObjectType, update_every);
595
+}
596
591
- static RRDSET *st_atq_average_request_latency = NULL;
592
- static RRDDIM *rd_atq_average_request_latency = NULL;
593
- /* TODO: Check why values are growing forever in our setup
597
+/* TODO: Check why values are growing forever in our setup
598
+static void netdata_ad_atq_queue_requests(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
599
+{
600
+ static COUNTER_DATA atqOutstandingRequests = { .key = "ATQ Outstanding Queued Requests" };
601
static RRDSET *st_atq_outstanding_requests = NULL;
602
static RRDDIM *rd_atq_outstanding_requests = NULL;
596
- */
597
-
598
- if (perflibGetObjectCounter(pDataBlock, pObjectType, &atqAverageRequestLatency)) {
599
- if (unlikely(!st_atq_average_request_latency)) {
600
- st_atq_average_request_latency = rrdset_create_localhost(
601
- "ad",
602
- "atq_average_request_latency",
603
- NULL,
604
- "queue",
605
- "ad.atq_average_request_latency",
606
- "Average request processing time",
607
- "seconds",
608
- PLUGIN_WINDOWS_NAME,
609
- "PerflibAD",
610
- PRIO_AD_AVG_REQUEST_LATENCY,
611
- update_every,
612
- RRDSET_TYPE_LINE);
603
614
- rd_atq_average_request_latency =
615
- rrddim_add(st_atq_average_request_latency, "time", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
616
- }
617
-
618
- rrddim_set_by_pointer(
619
- st_atq_average_request_latency,
620
- rd_atq_average_request_latency,
621
- (collected_number)atqAverageRequestLatency.current.Data);
622
- rrdset_done(st_atq_average_request_latency);
623
- }
624
-
625
- /*
604
if(perflibGetObjectCounter(pDataBlock, pObjectType, &atqOutstandingRequests)) {
605
if (unlikely(!st_atq_outstanding_requests)) {
606
st_atq_outstanding_requests = rrdset_create_localhost("ad"
@@ -650,7 +628,44 @@ static void netdata_ad_atq(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjec
628
rd_atq_outstanding_requests,
629
(collected_number)atqOutstandingRequests.current.Data);
630
rrdset_done(st_atq_outstanding_requests);
653
- } */
631
+ }
632
+}
633
+ */
634
+
635
+static void netdata_ad_atq_latency(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
636
+{
637
+ static COUNTER_DATA atqAverageRequestLatency = {.key = "ATQ Request Latency"};
638
+
639
+ static RRDSET *st_atq_average_request_latency = NULL;
640
+ static RRDDIM *rd_atq_average_request_latency = NULL;
641
+
642
+ if (!perflibGetObjectCounter(pDataBlock, pObjectType, &atqAverageRequestLatency))
643
+ return;
644
+
645
+ if (unlikely(!st_atq_average_request_latency)) {
646
+ st_atq_average_request_latency = rrdset_create_localhost(
647
+ "ad",
648
+ "atq_average_request_latency",
649
+ NULL,
650
+ "queue",
651
+ "ad.atq_average_request_latency",
652
+ "Average request processing time",
653
+ "seconds",
654
+ PLUGIN_WINDOWS_NAME,
655
+ "PerflibAD",
656
+ PRIO_AD_AVG_REQUEST_LATENCY,
657
+ update_every,
658
+ RRDSET_TYPE_LINE);
659
+
660
+ rd_atq_average_request_latency =
661
+ rrddim_add(st_atq_average_request_latency, "time", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE);
662
+ }
663
+
664
+ rrddim_set_by_pointer(
665
+ st_atq_average_request_latency,
666
+ rd_atq_average_request_latency,
667
+ (collected_number)atqAverageRequestLatency.current.Data);
668
+ rrdset_done(st_atq_average_request_latency);
669
}
670
671
static void netdata_ad_op_total(PERF_DATA_BLOCK *pDataBlock, PERF_OBJECT_TYPE *pObjectType, int update_every)
@@ -729,17 +744,17 @@ static bool do_AD(PERF_DATA_BLOCK *pDataBlock, int update_every)
744
return false;
745
746
static void (*doAD[])(PERF_DATA_BLOCK *, PERF_OBJECT_TYPE *, int) = {
732
- netdata_ad_directory,
733
- netdata_ad_cache_lookups,
734
- netdata_ad_properties,
735
- netdata_ad_compressed_traffic,
736
- netdata_ad_sync,
737
- netdata_ad_cache_hits,
738
- netdata_ad_service_threads_in_use,
739
- netdata_ad_bind,
740
- netdata_ad_searches,
741
- netdata_ad_atq,
742
- netdata_ad_op_total,
747
+ netdata_ad_directory,
748
+ netdata_ad_cache_lookups,
749
+ netdata_ad_properties,
750
+ netdata_ad_compressed_traffic,
751
+ netdata_ad_sync,
752
+ netdata_ad_cache_hits,
753
+ netdata_ad_service_threads_in_use,
754
+ netdata_ad_bind,
755
+ netdata_ad_searches,
756
+ netdata_ad_atq_latency,
757
+ netdata_ad_op_total,
758
759
// This must be the end
760
NULL};
@@ -752,13 +767,6 @@ static bool do_AD(PERF_DATA_BLOCK *pDataBlock, int update_every)
767
768
int do_PerflibAD(int update_every, usec_t dt __maybe_unused)
769
{
755
- static bool initialized = false;
756
-
757
- if (unlikely(!initialized)) {
758
- initialize();
759
- initialized = true;
760
- }
761
-
770
DWORD id = RegistryFindIDByName("DirectoryServices");
771
if (id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
772
return -1;
@@ -767,7 +775,8 @@ int do_PerflibAD(int update_every, usec_t dt __maybe_unused)
775
if (!pDataBlock)
776
return -1;
777
770
- do_AD(pDataBlock, update_every);
778
+ if (!do_AD(pDataBlock, update_every))
779
+ return -1;
780
781
return 0;
782
}
src/collectors/windows.plugin/perflib-adcs.c
+5
-3
@@ -649,9 +649,10 @@ static void netdata_adcs_signed_certificate_timetamp_list_processing(
649
rrdset_done(ac->st_adcs_signed_certificate_timestamp_list_processing_time_seconds);
650
}
651
652
+#define CERTIFICATION_AUTHORITY "Certification Authority"
653
static bool do_ADCS(PERF_DATA_BLOCK *pDataBlock, int update_every)
654
{
654
- PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, "Certification Authority");
655
+ PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, CERTIFICATION_AUTHORITY);
656
if (!pObjectType)
657
return false;
658
@@ -703,7 +704,7 @@ int do_PerflibADCS(int update_every, usec_t dt __maybe_unused)
704
initialized = true;
705
}
706
706
- DWORD id = RegistryFindIDByName("Certification Authority");
707
+ DWORD id = RegistryFindIDByName(CERTIFICATION_AUTHORITY);
708
if (id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
709
return -1;
710
@@ -711,7 +712,8 @@ int do_PerflibADCS(int update_every, usec_t dt __maybe_unused)
712
if (!pDataBlock)
713
return -1;
714
714
- do_ADCS(pDataBlock, update_every);
715
+ if (!do_ADCS(pDataBlock, update_every))
716
+ return -1;
717
718
return 0;
719
}
src/collectors/windows.plugin/perflib-adfs.c
+13
-13
@@ -943,7 +943,7 @@ void netdata_adfs_oauth_logon_certificate_request(
943
"requests/s",
944
PLUGIN_WINDOWS_NAME,
945
"PerflibADFS",
946
- PRIO_ADFS_OAUTH_CLIENT_WINDOWS_AUTH,
946
+ PRIO_ADFS_OAUTH_LOGON_CERTIFICATE_REQUESTS,
947
update_every,
948
RRDSET_TYPE_LINE);
949
@@ -979,18 +979,18 @@ void netdata_adfs_oauth_password_grant_requests(
979
980
if (!adfs.st_adfs_oauth_password_grant_requests) {
981
adfs.st_adfs_oauth_password_grant_requests = rrdset_create_localhost(
982
- "adfs",
983
- "oauth_password_grant_requests",
984
- NULL,
985
- "oauth",
986
- "adfs.oauth_password_grant_requests",
987
- "OAuth password grant requests",
988
- "authentications/s",
989
- PLUGIN_WINDOWS_NAME,
990
- "PerflibADFS",
991
- PRIO_ADFS_OAUTH_TOKEN_REQUESTS_SUCCESS,
992
- update_every,
993
- RRDSET_TYPE_LINE);
982
+ "adfs",
983
+ "oauth_password_grant_requests",
984
+ NULL,
985
+ "oauth",
986
+ "adfs.oauth_password_grant_requests",
987
+ "OAuth password grant requests",
988
+ "authentications/s",
989
+ PLUGIN_WINDOWS_NAME,
990
+ "PerflibADFS",
991
+ PRIO_ADFS_OAUTH_PASSWORD_GRANT_REQUESTS,
992
+ update_every,
993
+ RRDSET_TYPE_LINE);
994
995
adfs.rd_adfs_oauth_password_grant_requests_success =
996
rrddim_add(adfs.st_adfs_oauth_password_grant_requests, "success", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
src/collectors/windows.plugin/windows_plugin.h
+2
-1
@@ -257,7 +257,8 @@ enum PERFLIB_PRIO {
257
PRIO_ADFS_OAUTH_CLIENT_SECRET_BASIC_AUTH,
258
PRIO_ADFS_OAUTH_CLIENT_SECRET_POST_AUTH,
259
PRIO_ADFS_OAUTH_CLIENT_WINDOWS_AUTH,
260
- PRIO_ADFS_OAUTH_TOKEN_REQUESTS_SUCCESS,
260
+ PRIO_ADFS_OAUTH_LOGON_CERTIFICATE_REQUESTS,
261
+ PRIO_ADFS_OAUTH_PASSWORD_GRANT_REQUESTS,
262
263
PRIO_ADFS_PASSIVE_REQUESTS,
264
PRIO_ADFS_PASSPORT_AUTHENTICATOR,