Skip to content

Commit 70494d7

Browse files
cosmo0920edsiper
authored andcommitted
in_windows_exporter_metrics: Handle DST more precisely with dynamic timezone verison of functions
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent d385121 commit 70494d7

File tree

1 file changed

+7
-5
lines changed
  • plugins/in_windows_exporter_metrics

1 file changed

+7
-5
lines changed

plugins/in_windows_exporter_metrics/we_os.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int we_os_update(struct flb_we *ctx)
170170
DWORD caption_len = sizeof(caption), build_len = sizeof(build_number);
171171
uint64_t timestamp = 0;
172172
char label_caption[90];
173-
TIME_ZONE_INFORMATION tzi;
173+
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
174174
DWORD tztype = 0;
175175
char *displaytz;
176176

@@ -223,21 +223,23 @@ int we_os_update(struct flb_we *ctx)
223223

224224
cmt_gauge_set(ctx->os->time, timestamp, (double)timestamp/1000000000L, 0, NULL);
225225

226-
tztype = GetTimeZoneInformation(&tzi);
226+
_tzset();
227+
228+
tztype = GetDynamicTimeZoneInformation(&dtzi);
227229
switch (tztype) {
228230
case TIME_ZONE_ID_STANDARD:
229-
displaytz = we_convert_wstr(tzi.StandardName, CP_UTF8);
231+
displaytz = we_convert_wstr(dtzi.StandardName, CP_UTF8);
230232
cmt_gauge_set(ctx->os->tz, timestamp, 1.0, 1, (char *[]) {displaytz});
231233
flb_free(displaytz);
232234
break;
233235
case TIME_ZONE_ID_DAYLIGHT:
234-
displaytz = we_convert_wstr(tzi.DaylightName, CP_UTF8);
236+
displaytz = we_convert_wstr(dtzi.DaylightName, CP_UTF8);
235237
cmt_gauge_set(ctx->os->tz, timestamp, 1.0, 1, (char *[]) {displaytz});
236238
flb_free(displaytz);
237239
break;
238240
case TIME_ZONE_ID_UNKNOWN:
239241
/* The current timezone does not use daylight saving time. */
240-
displaytz = we_convert_wstr(tzi.StandardName, CP_UTF8);
242+
displaytz = we_convert_wstr(dtzi.StandardName, CP_UTF8);
241243
cmt_gauge_set(ctx->os->tz, timestamp, 1.0, 1, (char *[]) {displaytz});
242244
flb_free(displaytz);
243245
break;

0 commit comments

Comments
 (0)