Skip to content

Commit e31b08d

Browse files
committed
Port disk plugin to Windows.
1 parent fad7e91 commit e31b08d

File tree

5 files changed

+75
-6
lines changed

5 files changed

+75
-6
lines changed

Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ disk_la_CFLAGS = $(AM_CFLAGS)
823823
disk_la_CPPFLAGS = $(AM_CPPFLAGS)
824824
disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
825825
disk_la_LIBADD = libignorelist.la
826+
disk_la_DEPENDENCIES = libignorelist.la
826827
if BUILD_WITH_LIBKSTAT
827828
disk_la_LIBADD += -lkstat
828829
endif
@@ -847,6 +848,12 @@ endif
847848
if BUILD_WITH_PERFSTAT
848849
disk_la_LIBADD += -lperfstat
849850
endif
851+
if BUILD_WIN32
852+
disk_la_SOURCES += src/utils_wmi.c src/utils_wmi.h
853+
disk_la_LDFLAGS += -L.
854+
disk_la_LIBADD += -loleaut32 -lole32 -luuid libcollectd.la
855+
disk_la_DEPENDENCIES += libuuid.dll
856+
endif
850857
endif
851858

852859
if BUILD_PLUGIN_WMI

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ build_windows ()
151151
--disable-all-plugins \
152152
--host="mingw32" \
153153
--enable-logfile \
154+
--enable-disk \
154155
--enable-eventlog \
155156
--enable-match_regex \
156157
--enable-network \

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,7 @@ if test "x$ac_system" = "xLinux"; then
62476247
fi
62486248
62496249
if test "x$ac_system" = "xWindows"; then
6250+
plugin_disk="yes"
62506251
plugin_eventlog="yes"
62516252
plugin_wmi="yes"
62526253
fi

src/disk.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
#include "common.h"
2727
#include "plugin.h"
28+
#ifndef BUILD_WIN32
2829
#include "utils_ignorelist.h"
30+
#endif
2931

3032
#if HAVE_MACH_MACH_TYPES_H
3133
#include <mach/mach_types.h>
@@ -135,6 +137,11 @@ static int numdisk;
135137
static int pnumdisk;
136138
/* #endif HAVE_PERFSTAT */
137139

140+
#elif KERNEL_WIN32
141+
#include "utils_wmi.h"
142+
static wmi_connection_t *wmi;
143+
/* #endif KERNEL_WIN32 */
144+
138145
#else
139146
#error "No applicable input method."
140147
#endif
@@ -253,7 +260,10 @@ static int disk_init(void) {
253260
continue;
254261
ksp[numdisk++] = ksp_chain;
255262
}
256-
#endif /* HAVE_LIBKSTAT */
263+
/* #endif HAVE_LIBKSTAT */
264+
#elif KERNEL_WIN32
265+
wmi = wmi_connect();
266+
#endif /* KERNEL_WIN32 */
257267

258268
return 0;
259269
} /* int disk_init */
@@ -264,7 +274,10 @@ static int disk_shutdown(void) {
264274
if (handle_udev != NULL)
265275
udev_unref(handle_udev);
266276
#endif /* HAVE_UDEV_H */
267-
#endif /* KERNEL_LINUX */
277+
/* #endif KERNEL_LINUX */
278+
#elif KERNEL_WIN32
279+
wmi_release(wmi);
280+
#endif /* KERNEL_WIN32 */
268281
return 0;
269282
} /* int disk_shutdown */
270283

@@ -1013,7 +1026,52 @@ static int disk_read(void) {
10131026
1000000.0;
10141027
disk_submit(stat_disk[i].name, "disk_time", read_time, write_time);
10151028
}
1016-
#endif /* defined(HAVE_PERFSTAT) */
1029+
/* #emdof defined(HAVE_PERFSTAT) */
1030+
#elif KERNEL_WIN32
1031+
const char *statement = "select * from Win32_PerfRawData_PerfDisk_PhysicalDisk where Name != '_Total'";
1032+
wmi_result_list_t *results;
1033+
results = wmi_query(wmi, statement);
1034+
1035+
if (results->count == 0) {
1036+
WARNING("disk plugin: no results for query %s.", statement);
1037+
wmi_result_list_release(results);
1038+
return 0;
1039+
}
1040+
1041+
wmi_result_t *result;
1042+
while ((result = wmi_get_next_result(results))) {
1043+
VARIANT read_value_v;
1044+
VARIANT write_value_v;
1045+
VARIANT plugin_instance_v;
1046+
char *plugin_instance_s = NULL;
1047+
1048+
if (wmi_result_get_value(result, "DiskReadBytesPersec", &read_value_v) != 0) {
1049+
VariantClear(&read_value_v);
1050+
ERROR("disk plugin: failed to read field 'DiskReadBytesPersec'");
1051+
continue;
1052+
}
1053+
if (wmi_result_get_value(result, "DiskWriteBytesPersec", &write_value_v) != 0) {
1054+
VariantClear(&read_value_v);
1055+
VariantClear(&write_value_v);
1056+
ERROR("disk plugin: failed to read field 'DiskWriteBytesPersec'");
1057+
continue;
1058+
}
1059+
if (wmi_result_get_value(result, "Name", &plugin_instance_v) != 0) {
1060+
ERROR("disk plugin: failed to read field 'Name'");
1061+
}
1062+
plugin_instance_s = variant_get_string(&plugin_instance_v);
1063+
if (plugin_instance_s == NULL) {
1064+
ERROR("disk plugin: failed to convert plugin_instance to string");
1065+
}
1066+
disk_submit(plugin_instance_s, "disk_octets", variant_get_int64(&read_value_v), variant_get_int64(&write_value_v));
1067+
free(plugin_instance_s);
1068+
VariantClear(&read_value_v);
1069+
VariantClear(&write_value_v);
1070+
VariantClear(&plugin_instance_v);
1071+
wmi_result_release(result);
1072+
}
1073+
wmi_result_list_release(results);
1074+
#endif /* KERNEL_WIN32 */
10171075

10181076
return 0;
10191077
} /* int disk_read */

src/utils_ignorelist.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@
4848
* return;
4949
**/
5050

51-
#if HAVE_CONFIG_H
52-
#include "config.h"
53-
#endif
51+
//#if HAVE_CONFIG_H
52+
//#include "config.h"
53+
//#endif
54+
55+
#include "collectd.h"
5456

5557
#include "common.h"
5658
#include "plugin.h"

0 commit comments

Comments
 (0)