summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/plugins/in_windows_exporter_metrics/we.h
blob: 1ec848893b95203387d04cc9fbdfa256b4151d21 (plain)
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*  Fluent Bit
 *  ==========
 *  Copyright (C) 2019-2021 The Fluent Bit Authors
 *  Copyright (C) 2015-2018 Treasure Data Inc.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef FLB_WINDOWS_EXPORTER_H
#define FLB_WINDOWS_EXPORTER_H

#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_input_plugin.h>
#include <fluent-bit/flb_hash_table.h>
#include <fluent-bit/flb_metrics.h>

#include <monkey/mk_core/mk_list.h>
#include <fluent-bit/flb_sds.h>

#include <windows.h>
#include <wbemidl.h>

#include "we_metric.h"

#define PERFLIB_COUNTER_TYPE_COUNTER          0x400
#define PERFLIB_COUNTER_FLAG_BASE_VALUE       0x00030000
#define PERFLIB_COUNTER_FLAG_BASE_NANOSECONDS 0x00100000

struct we_perflib_counter_definition {
    char          *name_index_str;
    uint32_t       name_index;
    char          *name;
    uint32_t       help_index;
    char          *help;

    uint32_t       type;
    uint32_t       size;
    uint32_t       offset;
    uint32_t       detail_level;

    struct mk_list _head;
};

union we_perflib_value {
    uint64_t as_qword;
    double   as_double;
    uint32_t as_dword;
    float    as_float;
};

struct we_perflib_counter {
    struct we_perflib_instance           *parent;
    struct we_perflib_counter_definition *definition;
    union  we_perflib_value               primary_value;
    union  we_perflib_value               secondary_value;
    struct mk_list                        _head;
};

struct we_perflib_instance {
    char                     *name;
    struct we_perflib_object *parent;
    struct flb_hash_table    *counters;
    struct mk_list            _head;
};

struct we_perflib_object {
    char             *name;
    int64_t           time;
    int64_t           frequency;
    int64_t           hundred_ns_time;
    size_t            counter_count;
    size_t            instance_count;
    struct flb_hash_table *instances;
    struct mk_list    counter_definitions;
};


struct we_perflib_context {
    struct flb_hash_table *counter_indexes;
};

struct we_cpu_counters {
    struct we_perflib_metric_source *metric_sources;
    struct we_perflib_metric_spec   *metric_specs;
    int                              operational;
    struct flb_hash_table           *metrics;
    char                            *query;
};

struct we_net_counters {
    struct we_perflib_metric_source *metric_sources;
    struct we_perflib_metric_spec   *metric_specs;
    int                              operational;
    struct flb_hash_table           *metrics;
    char                            *query;
};

struct we_logical_disk_counters {
    struct we_perflib_metric_source *metric_sources;
    struct we_perflib_metric_spec   *metric_specs;
    int                              operational;
    struct flb_hash_table           *metrics;
    char                            *query;
};

struct wmi_query_spec;

struct we_wmi_thermal_counters {
    struct wmi_query_spec *temperature_celsius;
    struct wmi_query_spec *percent_passive_limit;
    struct wmi_query_spec *throttle_reasons;
    int                    operational;
};

struct we_wmi_cpu_info_counters {
    struct wmi_query_spec *info;
    int                    operational;
};

struct we_wmi_logon_counters {
    struct wmi_query_spec *info;
    int                    operational;
};

struct we_wmi_system_counters {
    struct wmi_query_spec *info;
    struct cmt_gauge      *context_switches;
    struct cmt_gauge      *exception_dispatches;
    struct cmt_gauge      *processor_queue;
    struct cmt_gauge      *system_calls;
    struct cmt_gauge      *system_up_time;
    struct cmt_gauge      *threads;
    int                    operational;
};

struct we_wmi_service_counters {
    struct wmi_query_spec *info;
    struct cmt_gauge *information;
    struct cmt_gauge *state;
    struct cmt_gauge *start_mode;
    struct cmt_gauge *status;
    int operational;
};

struct we_wmi_memory_counters {
    struct wmi_query_spec *info;
    struct cmt_gauge      *available_bytes;
    struct cmt_gauge      *cache_bytes;
    struct cmt_gauge      *cache_bytes_peak;
    struct cmt_gauge      *cache_faults_total;
    struct cmt_gauge      *commit_limit;
    struct cmt_gauge      *committed_bytes;
    struct cmt_gauge      *demand_zero_faults_total;
    struct cmt_gauge      *free_and_zero_page_list_bytes;
    struct cmt_gauge      *free_system_page_table_entries;
    struct cmt_gauge      *modified_page_list_bytes;
    struct cmt_gauge      *page_faults_total;
    struct cmt_gauge      *swap_page_reads_total;
    struct cmt_gauge      *swap_pages_read_total;
    struct cmt_gauge      *swap_pages_written_total;
    struct cmt_gauge      *swap_page_operations_total;
    struct cmt_gauge      *swap_page_writes_total;
    struct cmt_gauge      *pool_nonpaged_allocs_total;
    struct cmt_gauge      *pool_nonpaged_bytes;
    struct cmt_gauge      *pool_paged_allocs_total;
    struct cmt_gauge      *pool_paged_bytes;
    struct cmt_gauge      *pool_paged_resident_bytes;
    struct cmt_gauge      *standby_cache_core_bytes;
    struct cmt_gauge      *standby_cache_normal_priority_bytes;
    struct cmt_gauge      *standby_cache_reserve_bytes;
    struct cmt_gauge      *system_cache_resident_bytes;
    struct cmt_gauge      *system_code_resident_bytes;
    struct cmt_gauge      *system_code_total_bytes;
    struct cmt_gauge      *system_driver_resident_bytes;
    struct cmt_gauge      *system_driver_total_bytes;
    struct cmt_gauge      *transition_faults_total;
    struct cmt_gauge      *transition_pages_repurposed_total;
    struct cmt_gauge      *write_copies_total;
    int                    operational;
};

struct we_wmi_paging_file_counters {
    struct wmi_query_spec *info;
    struct cmt_gauge      *allocated_base_size_megabytes;
    struct cmt_gauge      *current_usage_megabytes;
    struct cmt_gauge      *peak_usage_megabytes;
    int                    operational;
};

struct we_wmi_process_counters {
    struct wmi_query_spec *info;
    struct cmt_gauge      *start_time;
    struct cmt_gauge      *handles;
    struct cmt_gauge      *cpu_time_total;
    struct cmt_gauge      *io_bytes_total;
    struct cmt_gauge      *io_operations_total;
    struct cmt_gauge      *page_faults_total;
    struct cmt_gauge      *page_file_bytes;
    struct cmt_gauge      *pool_bytes;
    struct cmt_gauge      *priority_base;
    struct cmt_gauge      *thread_count;
    struct cmt_gauge      *private_bytes;
    struct cmt_gauge      *virtual_bytes;
    struct cmt_gauge      *working_set_private_bytes;
    struct cmt_gauge      *working_set_peak_bytes;
    struct cmt_gauge      *working_set_bytes;
    int                    operational;
};

struct we_os_counters {
    struct cmt_gauge *info;
    struct cmt_gauge *users;
    struct cmt_gauge *physical_memory_free_bytes;
    struct cmt_gauge *time;
    struct cmt_gauge *tz;
    struct cmt_gauge *virtual_memory_free_bytes;
    struct cmt_gauge *processes_limit;
    struct cmt_gauge *process_memory_limit_bytes;
    struct cmt_gauge *processes;
    struct cmt_gauge *virtual_memory_bytes;
    struct cmt_gauge *visible_memory_bytes;
    int operational;
};

struct we_cs_counters {
    struct cmt_gauge *logical_processors;
    struct cmt_gauge *physical_memory_bytes;
    struct cmt_gauge *hostname;
    int operational;
};

struct flb_we {
    /* configuration */
    int scrape_interval;

    int coll_fd;                                      /* collector fd     */
    struct cmt *cmt;                                  /* cmetrics context */
    struct flb_input_instance *ins;                   /* input instance   */
    struct mk_list *collectors;
    char *raw_allowing_disk;
    char *raw_denying_disk;
    char *raw_allowing_nic;
    char *raw_where_clause;
    char *raw_service_include;
    char *raw_service_exclude;
    char *raw_allowing_process;
    char *raw_denying_process;
    char *service_include_buffer;
    int   service_include_buffer_size;
    char *service_exclude_buffer;
    int   service_exclude_buffer_size;

    struct flb_regex *allowing_disk_regex;
    struct flb_regex *denying_disk_regex;
    struct flb_regex *allowing_nic_regex;
    struct flb_regex *allowing_process_regex;
    struct flb_regex *denying_process_regex;

    struct we_perflib_context perflib_context;
    /* WMI locator and service contexts */
    IWbemLocator *locator;
    IWbemServices *service;

    float windows_version;

    struct flb_callback *callback;                    /* metric callback */
    struct mk_list *metrics;                          /* enabled metrics */

    /* Individual intervals for metrics */
    int cpu_scrape_interval;
    int net_scrape_interval;
    int logical_disk_scrape_interval;
    int cs_scrape_interval;
    int os_scrape_interval;
    int wmi_thermalzone_scrape_interval;
    int wmi_cpu_info_scrape_interval;
    int wmi_logon_scrape_interval;
    int wmi_system_scrape_interval;
    int wmi_service_scrape_interval;
    int wmi_memory_scrape_interval;
    int wmi_paging_file_scrape_interval;
    int wmi_process_scrape_interval;

    int coll_cpu_fd;                                    /* collector fd (cpu)    */
    int coll_net_fd;                                    /* collector fd (net)  */
    int coll_logical_disk_fd;                           /* collector fd (logical_disk) */
    int coll_cs_fd;                                     /* collector fd (cs) */
    int coll_os_fd;                                     /* collector fd (os)    */
    int coll_wmi_thermalzone_fd;                        /* collector fd (wmi_thermalzone) */
    int coll_wmi_cpu_info_fd;                           /* collector fd (wmi_cpu_info) */
    int coll_wmi_logon_fd;                              /* collector fd (wmi_logon)    */
    int coll_wmi_system_fd;                             /* collector fd (wmi_system)    */
    int coll_wmi_service_fd;                            /* collector fd (wmi_service) */
    int coll_wmi_memory_fd;                             /* collector fd (wmi_memory)    */
    int coll_wmi_paging_file_fd;                        /* collector fd (wmi_paging_file) */
    int coll_wmi_process_fd;                            /* collector fd (wmi_process) */

    /*
     * Metrics Contexts
     * ----------------
     */

    struct we_cpu_counters cpu;
    struct we_net_counters net;
    struct we_logical_disk_counters logical_disk;
    struct we_cs_counters cs;
    struct we_os_counters *os;
    struct we_wmi_thermal_counters *wmi_thermals;
    struct we_wmi_cpu_info_counters *wmi_cpu_info;
    struct we_wmi_logon_counters *wmi_logon;
    struct we_wmi_system_counters *wmi_system;
    struct we_wmi_service_counters *wmi_service;
    struct we_wmi_memory_counters *wmi_memory;
    struct we_wmi_paging_file_counters *wmi_paging_file;
    struct we_wmi_process_counters *wmi_process;
};

typedef int (*collector_cb)(struct flb_we *);

#endif