Skip to content

Commit 87b98c3

Browse files
committed
in_windows_exporter_metrics: Fix calculations and names for paging files
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent 4120d07 commit 87b98c3

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

plugins/in_windows_exporter_metrics/we.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ struct we_wmi_memory_counters {
203203

204204
struct we_wmi_paging_file_counters {
205205
struct wmi_query_spec *info;
206-
struct cmt_gauge *allocated_base_size_megabytes;
207-
struct cmt_gauge *current_usage_megabytes;
206+
struct cmt_gauge *limit_megabytes;
208207
struct cmt_gauge *peak_usage_megabytes;
208+
struct cmt_gauge *free_megabytes;
209209
int operational;
210210
};
211211

plugins/in_windows_exporter_metrics/we_wmi_paging_file.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,29 @@ int we_wmi_paging_file_init(struct flb_we *ctx)
4545
}
4646
ctx->wmi_paging_file->operational = FLB_FALSE;
4747

48-
g = cmt_gauge_create(ctx->cmt, "windows", "paging_file", "allocated_base_size_megabytes",
49-
"The value indicates the actual amount of disk space allocated "\
50-
"for use with this page file (AllocatedBaseSize)",
51-
0, NULL);
48+
g = cmt_gauge_create(ctx->cmt, "windows", "paging_file", "limit_megabytes",
49+
"Number of bytes that can be stored in the operating system paging files. " \
50+
"0 (zero) indicates that there are no paging files",
51+
1, (char *[]) {"file"});
5252

5353
if (!g) {
5454
return -1;
5555
}
56-
ctx->wmi_paging_file->allocated_base_size_megabytes = g;
56+
ctx->wmi_paging_file->limit_megabytes = g;
5757

58-
g = cmt_gauge_create(ctx->cmt, "windows", "paging_file", "current_usage_megabytes",
59-
"The value indicates how much of the total reserved page file " \
60-
"is currently in use (CurrentUsage)",
61-
0, NULL);
58+
g = cmt_gauge_create(ctx->cmt, "windows", "paging_file", "free_megabytes",
59+
"Number of bytes that can be mapped into the operating system paging files " \
60+
"without causing any other pages to be swapped out",
61+
1, (char *[]) {"file"});
6262

6363
if (!g) {
6464
return -1;
6565
}
66-
ctx->wmi_paging_file->current_usage_megabytes = g;
66+
ctx->wmi_paging_file->free_megabytes = g;
6767

6868
g = cmt_gauge_create(ctx->cmt, "windows", "paging_file", "peak_usage_megabytes",
6969
"The value indicates the highest use page file (PeakUsage)",
70-
0, NULL);
70+
1, (char *[]) {"file"});
7171

7272
if (!g) {
7373
return -1;
@@ -112,6 +112,8 @@ int we_wmi_paging_file_update(struct flb_we *ctx)
112112
IWbemClassObject *class_obj = NULL;
113113
ULONG ret = 0;
114114
double val = 0;
115+
double limit_val = 0;
116+
char *paging_file = NULL;
115117

116118
if (!ctx->wmi_paging_file->operational) {
117119
flb_plg_error(ctx->ins, "paging_file collector not yet in operational state");
@@ -136,16 +138,27 @@ int we_wmi_paging_file_update(struct flb_we *ctx)
136138
break;
137139
}
138140

139-
val = we_wmi_get_property_value(ctx, "AllocatedBaseSize", class_obj);
140-
cmt_gauge_set(ctx->wmi_paging_file->allocated_base_size_megabytes, timestamp, val, 0, NULL);
141+
paging_file = we_wmi_get_property_str_value(ctx, "Name", class_obj);
142+
if (!paging_file) {
143+
continue;
144+
}
145+
146+
limit_val = we_wmi_get_property_value(ctx, "AllocatedBaseSize", class_obj);
147+
cmt_gauge_set(ctx->wmi_paging_file->limit_megabytes,
148+
timestamp, limit_val, 1, (char *[]){ paging_file });
141149

150+
/* Calculate Free megabytes */
142151
val = we_wmi_get_property_value(ctx, "CurrentUsage", class_obj);
143-
cmt_gauge_set(ctx->wmi_paging_file->current_usage_megabytes, timestamp, val, 0, NULL);
152+
val = limit_val - val;
153+
cmt_gauge_set(ctx->wmi_paging_file->free_megabytes,
154+
timestamp, val, 1, (char *[]){ paging_file });
144155

145156
val = we_wmi_get_property_value(ctx, "PeakUsage", class_obj);
146-
cmt_gauge_set(ctx->wmi_paging_file->peak_usage_megabytes, timestamp, val, 0, NULL);
157+
cmt_gauge_set(ctx->wmi_paging_file->peak_usage_megabytes,
158+
timestamp, val, 1, (char *[]){ paging_file });
147159

148160
class_obj->lpVtbl->Release(class_obj);
161+
flb_free(paging_file);
149162
}
150163

151164
enumerator->lpVtbl->Release(enumerator);

0 commit comments

Comments
 (0)