Skip to content

Commit 1d624ef

Browse files
committed
in_windows_exporter_metrics: Handle Cache and System special types
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 0a57f15 commit 1d624ef

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

plugins/in_windows_exporter_metrics/we.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ struct we_perflib_object {
8282
int64_t hundred_ns_time;
8383
size_t counter_count;
8484
size_t instance_count;
85+
size_t total_byte_length;
86+
size_t definition_length;
8587
struct flb_hash_table *instances;
8688
struct mk_list counter_definitions;
8789
};

plugins/in_windows_exporter_metrics/we_perflib.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ static int we_perflib_process_object_type(
492492
perflib_object->counter_count = perf_object->NumCounters;
493493
perflib_object->instance_count = perf_object->NumInstances;
494494

495+
perflib_object->total_byte_length = perf_object->TotalByteLength;
496+
perflib_object->definition_length = perf_object->DefinitionLength;
495497

496498
perflib_object->instances = flb_hash_table_create(
497499
FLB_HASH_TABLE_EVICT_NONE,
@@ -795,11 +797,57 @@ static int we_perflib_process_instances(struct we_perflib_context *context,
795797
{
796798
struct we_perflib_instance *perflib_instance;
797799
size_t instance_index;
800+
size_t total_instance_data_size;
801+
PERF_COUNTER_BLOCK *first_counter_block;
798802
int result;
799803
int offset;
800804

801805
offset = 0;
802806

807+
/* Calculate the total size of all instance and counter data blocks */
808+
total_instance_data_size = perflib_object->total_byte_length -
809+
perflib_object->definition_length;
810+
811+
/*
812+
* If the total size of instance data is exactly equal to the
813+
* size of the first counter block, we can infer this is a single-instance
814+
* object that lacks a PERF_INSTANCE_DEFINITION block.
815+
*/
816+
if (perflib_object->instance_count == PERF_NO_INSTANCES) {
817+
first_counter_block = (PERF_COUNTER_BLOCK *)input_data_block;
818+
819+
if (first_counter_block->ByteLength == total_instance_data_size) {
820+
/* Path for special single-instance objects like "Cache" and "System" */
821+
perflib_instance = we_perflib_create_instance(perflib_object->counter_count);
822+
if (perflib_instance == NULL) {
823+
return -1;
824+
}
825+
826+
perflib_instance->name = flb_strdup("_Total");
827+
perflib_instance->parent = perflib_object;
828+
829+
result = we_perflib_process_counters(context, perflib_object,
830+
perflib_instance, input_data_block);
831+
832+
if (result < 0) {
833+
we_perflib_destroy_instance(perflib_instance);
834+
return -1;
835+
}
836+
offset += result;
837+
838+
result = flb_hash_table_add(perflib_object->instances,
839+
perflib_instance->name, strlen(perflib_instance->name),
840+
perflib_instance, 0);
841+
842+
if (result < 0) {
843+
we_perflib_destroy_instance(perflib_instance);
844+
return -2;
845+
}
846+
847+
return offset;
848+
}
849+
}
850+
803851
for (instance_index = 0 ;
804852
instance_index < perflib_object->instance_count ;
805853
instance_index++) {

0 commit comments

Comments
 (0)