diff --git a/metricbeat/module/windows/perfmon/defs_pdh_windows.go b/metricbeat/module/windows/perfmon/defs_pdh_windows.go new file mode 100644 index 000000000000..030b31ee400d --- /dev/null +++ b/metricbeat/module/windows/perfmon/defs_pdh_windows.go @@ -0,0 +1,220 @@ +// go run mkpdh_defs.go +// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT + +// +build ignore + +package perfmon + +/* +#include +#include +#cgo LDFLAGS: -lpdh +*/ +import "C" + +type PdhErrno uintptr + +// PDH Error Codes +const ( + PDH_CSTATUS_VALID_DATA PdhErrno = C.PDH_CSTATUS_VALID_DATA + PDH_CSTATUS_NEW_DATA PdhErrno = C.PDH_CSTATUS_NEW_DATA + PDH_CSTATUS_NO_MACHINE PdhErrno = C.PDH_CSTATUS_NO_MACHINE + PDH_CSTATUS_NO_INSTANCE PdhErrno = C.PDH_CSTATUS_NO_INSTANCE + PDH_MORE_DATA PdhErrno = C.PDH_MORE_DATA + PDH_CSTATUS_ITEM_NOT_VALIDATED PdhErrno = C.PDH_CSTATUS_ITEM_NOT_VALIDATED + PDH_RETRY PdhErrno = C.PDH_RETRY + PDH_NO_DATA PdhErrno = C.PDH_NO_DATA + PDH_CALC_NEGATIVE_DENOMINATOR PdhErrno = C.PDH_CALC_NEGATIVE_DENOMINATOR + PDH_CALC_NEGATIVE_TIMEBASE PdhErrno = C.PDH_CALC_NEGATIVE_TIMEBASE + PDH_CALC_NEGATIVE_VALUE PdhErrno = C.PDH_CALC_NEGATIVE_VALUE + PDH_DIALOG_CANCELLED PdhErrno = C.PDH_DIALOG_CANCELLED + PDH_END_OF_LOG_FILE PdhErrno = C.PDH_END_OF_LOG_FILE + PDH_ASYNC_QUERY_TIMEOUT PdhErrno = C.PDH_ASYNC_QUERY_TIMEOUT + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE PdhErrno = C.PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE + PDH_CSTATUS_NO_OBJECT PdhErrno = C.PDH_CSTATUS_NO_OBJECT + PDH_CSTATUS_NO_COUNTER PdhErrno = C.PDH_CSTATUS_NO_COUNTER + PDH_CSTATUS_INVALID_DATA PdhErrno = C.PDH_CSTATUS_INVALID_DATA + PDH_MEMORY_ALLOCATION_FAILURE PdhErrno = C.PDH_MEMORY_ALLOCATION_FAILURE + PDH_INVALID_HANDLE PdhErrno = C.PDH_INVALID_HANDLE + PDH_INVALID_ARGUMENT PdhErrno = C.PDH_INVALID_ARGUMENT + PDH_FUNCTION_NOT_FOUND PdhErrno = C.PDH_FUNCTION_NOT_FOUND + PDH_CSTATUS_NO_COUNTERNAME PdhErrno = C.PDH_CSTATUS_NO_COUNTERNAME + PDH_CSTATUS_BAD_COUNTERNAME PdhErrno = C.PDH_CSTATUS_BAD_COUNTERNAME + PDH_INVALID_BUFFER PdhErrno = C.PDH_INVALID_BUFFER + PDH_INSUFFICIENT_BUFFER PdhErrno = C.PDH_INSUFFICIENT_BUFFER + PDH_CANNOT_CONNECT_MACHINE PdhErrno = C.PDH_CANNOT_CONNECT_MACHINE + PDH_INVALID_PATH PdhErrno = C.PDH_INVALID_PATH + PDH_INVALID_INSTANCE PdhErrno = C.PDH_INVALID_INSTANCE + PDH_INVALID_DATA PdhErrno = C.PDH_INVALID_DATA + PDH_NO_DIALOG_DATA PdhErrno = C.PDH_NO_DIALOG_DATA + PDH_CANNOT_READ_NAME_STRINGS PdhErrno = C.PDH_CANNOT_READ_NAME_STRINGS + PDH_LOG_FILE_CREATE_ERROR PdhErrno = C.PDH_LOG_FILE_CREATE_ERROR + PDH_LOG_FILE_OPEN_ERROR PdhErrno = C.PDH_LOG_FILE_OPEN_ERROR + PDH_LOG_TYPE_NOT_FOUND PdhErrno = C.PDH_LOG_TYPE_NOT_FOUND + PDH_NO_MORE_DATA PdhErrno = C.PDH_NO_MORE_DATA + PDH_ENTRY_NOT_IN_LOG_FILE PdhErrno = C.PDH_ENTRY_NOT_IN_LOG_FILE + PDH_DATA_SOURCE_IS_LOG_FILE PdhErrno = C.PDH_DATA_SOURCE_IS_LOG_FILE + PDH_DATA_SOURCE_IS_REAL_TIME PdhErrno = C.PDH_DATA_SOURCE_IS_REAL_TIME + PDH_UNABLE_READ_LOG_HEADER PdhErrno = C.PDH_UNABLE_READ_LOG_HEADER + PDH_FILE_NOT_FOUND PdhErrno = C.PDH_FILE_NOT_FOUND + PDH_FILE_ALREADY_EXISTS PdhErrno = C.PDH_FILE_ALREADY_EXISTS + PDH_NOT_IMPLEMENTED PdhErrno = C.PDH_NOT_IMPLEMENTED + PDH_STRING_NOT_FOUND PdhErrno = C.PDH_STRING_NOT_FOUND + PDH_UNABLE_MAP_NAME_FILES PdhErrno = C.PDH_UNABLE_MAP_NAME_FILES + PDH_UNKNOWN_LOG_FORMAT PdhErrno = C.PDH_UNKNOWN_LOG_FORMAT + PDH_UNKNOWN_LOGSVC_COMMAND PdhErrno = C.PDH_UNKNOWN_LOGSVC_COMMAND + PDH_LOGSVC_QUERY_NOT_FOUND PdhErrno = C.PDH_LOGSVC_QUERY_NOT_FOUND + PDH_LOGSVC_NOT_OPENED PdhErrno = C.PDH_LOGSVC_NOT_OPENED + PDH_WBEM_ERROR PdhErrno = C.PDH_WBEM_ERROR + PDH_ACCESS_DENIED PdhErrno = C.PDH_ACCESS_DENIED + PDH_LOG_FILE_TOO_SMALL PdhErrno = C.PDH_LOG_FILE_TOO_SMALL + PDH_INVALID_DATASOURCE PdhErrno = C.PDH_INVALID_DATASOURCE + PDH_INVALID_SQLDB PdhErrno = C.PDH_INVALID_SQLDB + PDH_NO_COUNTERS PdhErrno = C.PDH_NO_COUNTERS + PDH_SQL_ALLOC_FAILED PdhErrno = C.PDH_SQL_ALLOC_FAILED + PDH_SQL_ALLOCCON_FAILED PdhErrno = C.PDH_SQL_ALLOCCON_FAILED + PDH_SQL_EXEC_DIRECT_FAILED PdhErrno = C.PDH_SQL_EXEC_DIRECT_FAILED + PDH_SQL_FETCH_FAILED PdhErrno = C.PDH_SQL_FETCH_FAILED + PDH_SQL_ROWCOUNT_FAILED PdhErrno = C.PDH_SQL_ROWCOUNT_FAILED + PDH_SQL_MORE_RESULTS_FAILED PdhErrno = C.PDH_SQL_MORE_RESULTS_FAILED + PDH_SQL_CONNECT_FAILED PdhErrno = C.PDH_SQL_CONNECT_FAILED + PDH_SQL_BIND_FAILED PdhErrno = C.PDH_SQL_BIND_FAILED + PDH_CANNOT_CONNECT_WMI_SERVER PdhErrno = C.PDH_CANNOT_CONNECT_WMI_SERVER + PDH_PLA_COLLECTION_ALREADY_RUNNING PdhErrno = C.PDH_PLA_COLLECTION_ALREADY_RUNNING + PDH_PLA_ERROR_SCHEDULE_OVERLAP PdhErrno = C.PDH_PLA_ERROR_SCHEDULE_OVERLAP + PDH_PLA_COLLECTION_NOT_FOUND PdhErrno = C.PDH_PLA_COLLECTION_NOT_FOUND + PDH_PLA_ERROR_SCHEDULE_ELAPSED PdhErrno = C.PDH_PLA_ERROR_SCHEDULE_ELAPSED + PDH_PLA_ERROR_NOSTART PdhErrno = C.PDH_PLA_ERROR_NOSTART + PDH_PLA_ERROR_ALREADY_EXISTS PdhErrno = C.PDH_PLA_ERROR_ALREADY_EXISTS + PDH_PLA_ERROR_TYPE_MISMATCH PdhErrno = C.PDH_PLA_ERROR_TYPE_MISMATCH + PDH_PLA_ERROR_FILEPATH PdhErrno = C.PDH_PLA_ERROR_FILEPATH + PDH_PLA_SERVICE_ERROR PdhErrno = C.PDH_PLA_SERVICE_ERROR + PDH_PLA_VALIDATION_ERROR PdhErrno = C.PDH_PLA_VALIDATION_ERROR + PDH_PLA_VALIDATION_WARNING PdhErrno = C.PDH_PLA_VALIDATION_WARNING + PDH_PLA_ERROR_NAME_TOO_LONG PdhErrno = C.PDH_PLA_ERROR_NAME_TOO_LONG + PDH_INVALID_SQL_LOG_FORMAT PdhErrno = C.PDH_INVALID_SQL_LOG_FORMAT + PDH_COUNTER_ALREADY_IN_QUERY PdhErrno = C.PDH_COUNTER_ALREADY_IN_QUERY + PDH_BINARY_LOG_CORRUPT PdhErrno = C.PDH_BINARY_LOG_CORRUPT + PDH_LOG_SAMPLE_TOO_SMALL PdhErrno = C.PDH_LOG_SAMPLE_TOO_SMALL + PDH_OS_LATER_VERSION PdhErrno = C.PDH_OS_LATER_VERSION + PDH_OS_EARLIER_VERSION PdhErrno = C.PDH_OS_EARLIER_VERSION + PDH_INCORRECT_APPEND_TIME PdhErrno = C.PDH_INCORRECT_APPEND_TIME + PDH_UNMATCHED_APPEND_COUNTER PdhErrno = C.PDH_UNMATCHED_APPEND_COUNTER + PDH_SQL_ALTER_DETAIL_FAILED PdhErrno = C.PDH_SQL_ALTER_DETAIL_FAILED + PDH_QUERY_PERF_DATA_TIMEOUT PdhErrno = C.PDH_QUERY_PERF_DATA_TIMEOUT +) + +var pdhErrors = map[PdhErrno]struct{}{ + PDH_CSTATUS_VALID_DATA: struct{}{}, + PDH_CSTATUS_NEW_DATA: struct{}{}, + PDH_CSTATUS_NO_MACHINE: struct{}{}, + PDH_CSTATUS_NO_INSTANCE: struct{}{}, + PDH_MORE_DATA: struct{}{}, + PDH_CSTATUS_ITEM_NOT_VALIDATED: struct{}{}, + PDH_RETRY: struct{}{}, + PDH_NO_DATA: struct{}{}, + PDH_CALC_NEGATIVE_DENOMINATOR: struct{}{}, + PDH_CALC_NEGATIVE_TIMEBASE: struct{}{}, + PDH_CALC_NEGATIVE_VALUE: struct{}{}, + PDH_DIALOG_CANCELLED: struct{}{}, + PDH_END_OF_LOG_FILE: struct{}{}, + PDH_ASYNC_QUERY_TIMEOUT: struct{}{}, + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE: struct{}{}, + PDH_CSTATUS_NO_OBJECT: struct{}{}, + PDH_CSTATUS_NO_COUNTER: struct{}{}, + PDH_CSTATUS_INVALID_DATA: struct{}{}, + PDH_MEMORY_ALLOCATION_FAILURE: struct{}{}, + PDH_INVALID_HANDLE: struct{}{}, + PDH_INVALID_ARGUMENT: struct{}{}, + PDH_FUNCTION_NOT_FOUND: struct{}{}, + PDH_CSTATUS_NO_COUNTERNAME: struct{}{}, + PDH_CSTATUS_BAD_COUNTERNAME: struct{}{}, + PDH_INVALID_BUFFER: struct{}{}, + PDH_INSUFFICIENT_BUFFER: struct{}{}, + PDH_CANNOT_CONNECT_MACHINE: struct{}{}, + PDH_INVALID_PATH: struct{}{}, + PDH_INVALID_INSTANCE: struct{}{}, + PDH_INVALID_DATA: struct{}{}, + PDH_NO_DIALOG_DATA: struct{}{}, + PDH_CANNOT_READ_NAME_STRINGS: struct{}{}, + PDH_LOG_FILE_CREATE_ERROR: struct{}{}, + PDH_LOG_FILE_OPEN_ERROR: struct{}{}, + PDH_LOG_TYPE_NOT_FOUND: struct{}{}, + PDH_NO_MORE_DATA: struct{}{}, + PDH_ENTRY_NOT_IN_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_REAL_TIME: struct{}{}, + PDH_UNABLE_READ_LOG_HEADER: struct{}{}, + PDH_FILE_NOT_FOUND: struct{}{}, + PDH_FILE_ALREADY_EXISTS: struct{}{}, + PDH_NOT_IMPLEMENTED: struct{}{}, + PDH_STRING_NOT_FOUND: struct{}{}, + PDH_UNABLE_MAP_NAME_FILES: struct{}{}, + PDH_UNKNOWN_LOG_FORMAT: struct{}{}, + PDH_UNKNOWN_LOGSVC_COMMAND: struct{}{}, + PDH_LOGSVC_QUERY_NOT_FOUND: struct{}{}, + PDH_LOGSVC_NOT_OPENED: struct{}{}, + PDH_WBEM_ERROR: struct{}{}, + PDH_ACCESS_DENIED: struct{}{}, + PDH_LOG_FILE_TOO_SMALL: struct{}{}, + PDH_INVALID_DATASOURCE: struct{}{}, + PDH_INVALID_SQLDB: struct{}{}, + PDH_NO_COUNTERS: struct{}{}, + PDH_SQL_ALLOC_FAILED: struct{}{}, + PDH_SQL_ALLOCCON_FAILED: struct{}{}, + PDH_SQL_EXEC_DIRECT_FAILED: struct{}{}, + PDH_SQL_FETCH_FAILED: struct{}{}, + PDH_SQL_ROWCOUNT_FAILED: struct{}{}, + PDH_SQL_MORE_RESULTS_FAILED: struct{}{}, + PDH_SQL_CONNECT_FAILED: struct{}{}, + PDH_SQL_BIND_FAILED: struct{}{}, + PDH_CANNOT_CONNECT_WMI_SERVER: struct{}{}, + PDH_PLA_COLLECTION_ALREADY_RUNNING: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_OVERLAP: struct{}{}, + PDH_PLA_COLLECTION_NOT_FOUND: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_ELAPSED: struct{}{}, + PDH_PLA_ERROR_NOSTART: struct{}{}, + PDH_PLA_ERROR_ALREADY_EXISTS: struct{}{}, + PDH_PLA_ERROR_TYPE_MISMATCH: struct{}{}, + PDH_PLA_ERROR_FILEPATH: struct{}{}, + PDH_PLA_SERVICE_ERROR: struct{}{}, + PDH_PLA_VALIDATION_ERROR: struct{}{}, + PDH_PLA_VALIDATION_WARNING: struct{}{}, + PDH_PLA_ERROR_NAME_TOO_LONG: struct{}{}, + PDH_INVALID_SQL_LOG_FORMAT: struct{}{}, + PDH_COUNTER_ALREADY_IN_QUERY: struct{}{}, + PDH_BINARY_LOG_CORRUPT: struct{}{}, + PDH_LOG_SAMPLE_TOO_SMALL: struct{}{}, + PDH_OS_LATER_VERSION: struct{}{}, + PDH_OS_EARLIER_VERSION: struct{}{}, + PDH_INCORRECT_APPEND_TIME: struct{}{}, + PDH_UNMATCHED_APPEND_COUNTER: struct{}{}, + PDH_SQL_ALTER_DETAIL_FAILED: struct{}{}, + PDH_QUERY_PERF_DATA_TIMEOUT: struct{}{}, +} + +type PdhCounterFormat uint32 + +// PDH Counter Formats +const ( + // PdhFmtDouble returns data as a double-precision floating point real. + PdhFmtDouble PdhCounterFormat = C.PDH_FMT_DOUBLE + // PdhFmtLarge returns data as a 64-bit integer. + PdhFmtLarge = C.PDH_FMT_LARGE + // PdhFmtLong returns data as a long integer. + PdhFmtLong = C.PDH_FMT_LONG + + // Use bitwise operators to combine these values with the counter type to scale the value. + + // Do not apply the counter's default scaling factor. + PdhFmtNoScale = C.PDH_FMT_NOSCALE + // Counter values greater than 100 (for example, counter values measuring + // the processor load on multiprocessor computers) will not be reset to 100. + // The default behavior is that counter values are capped at a value of 100. + PdhFmtNoCap100 = C.PDH_FMT_NOCAP100 + // Multiply the actual value by 1,000. + PdhFmtMultiply1000 = C.PDH_FMT_1000 +) + +// PdhCounterValue is the structure that receives the counter value. +type PdhCounterValue C.PDH_FMT_COUNTERVALUE diff --git a/metricbeat/module/windows/perfmon/defs_pdh_windows_386.go b/metricbeat/module/windows/perfmon/defs_pdh_windows_386.go new file mode 100644 index 000000000000..2bb3dde3c890 --- /dev/null +++ b/metricbeat/module/windows/perfmon/defs_pdh_windows_386.go @@ -0,0 +1,207 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo.exe -godefs defs_pdh_windows.go + +package perfmon + +type PdhErrno uintptr + +const ( + PDH_CSTATUS_VALID_DATA PdhErrno = 0x0 + PDH_CSTATUS_NEW_DATA PdhErrno = 0x1 + PDH_CSTATUS_NO_MACHINE PdhErrno = 0x800007d0 + PDH_CSTATUS_NO_INSTANCE PdhErrno = 0x800007d1 + PDH_MORE_DATA PdhErrno = 0x800007d2 + PDH_CSTATUS_ITEM_NOT_VALIDATED PdhErrno = 0x800007d3 + PDH_RETRY PdhErrno = 0x800007d4 + PDH_NO_DATA PdhErrno = 0x800007d5 + PDH_CALC_NEGATIVE_DENOMINATOR PdhErrno = 0x800007d6 + PDH_CALC_NEGATIVE_TIMEBASE PdhErrno = 0x800007d7 + PDH_CALC_NEGATIVE_VALUE PdhErrno = 0x800007d8 + PDH_DIALOG_CANCELLED PdhErrno = 0x800007d9 + PDH_END_OF_LOG_FILE PdhErrno = 0x800007da + PDH_ASYNC_QUERY_TIMEOUT PdhErrno = 0x800007db + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE PdhErrno = 0x800007dc + PDH_CSTATUS_NO_OBJECT PdhErrno = 0xc0000bb8 + PDH_CSTATUS_NO_COUNTER PdhErrno = 0xc0000bb9 + PDH_CSTATUS_INVALID_DATA PdhErrno = 0xc0000bba + PDH_MEMORY_ALLOCATION_FAILURE PdhErrno = 0xc0000bbb + PDH_INVALID_HANDLE PdhErrno = 0xc0000bbc + PDH_INVALID_ARGUMENT PdhErrno = 0xc0000bbd + PDH_FUNCTION_NOT_FOUND PdhErrno = 0xc0000bbe + PDH_CSTATUS_NO_COUNTERNAME PdhErrno = 0xc0000bbf + PDH_CSTATUS_BAD_COUNTERNAME PdhErrno = 0xc0000bc0 + PDH_INVALID_BUFFER PdhErrno = 0xc0000bc1 + PDH_INSUFFICIENT_BUFFER PdhErrno = 0xc0000bc2 + PDH_CANNOT_CONNECT_MACHINE PdhErrno = 0xc0000bc3 + PDH_INVALID_PATH PdhErrno = 0xc0000bc4 + PDH_INVALID_INSTANCE PdhErrno = 0xc0000bc5 + PDH_INVALID_DATA PdhErrno = 0xc0000bc6 + PDH_NO_DIALOG_DATA PdhErrno = 0xc0000bc7 + PDH_CANNOT_READ_NAME_STRINGS PdhErrno = 0xc0000bc8 + PDH_LOG_FILE_CREATE_ERROR PdhErrno = 0xc0000bc9 + PDH_LOG_FILE_OPEN_ERROR PdhErrno = 0xc0000bca + PDH_LOG_TYPE_NOT_FOUND PdhErrno = 0xc0000bcb + PDH_NO_MORE_DATA PdhErrno = 0xc0000bcc + PDH_ENTRY_NOT_IN_LOG_FILE PdhErrno = 0xc0000bcd + PDH_DATA_SOURCE_IS_LOG_FILE PdhErrno = 0xc0000bce + PDH_DATA_SOURCE_IS_REAL_TIME PdhErrno = 0xc0000bcf + PDH_UNABLE_READ_LOG_HEADER PdhErrno = 0xc0000bd0 + PDH_FILE_NOT_FOUND PdhErrno = 0xc0000bd1 + PDH_FILE_ALREADY_EXISTS PdhErrno = 0xc0000bd2 + PDH_NOT_IMPLEMENTED PdhErrno = 0xc0000bd3 + PDH_STRING_NOT_FOUND PdhErrno = 0xc0000bd4 + PDH_UNABLE_MAP_NAME_FILES PdhErrno = 0x80000bd5 + PDH_UNKNOWN_LOG_FORMAT PdhErrno = 0xc0000bd6 + PDH_UNKNOWN_LOGSVC_COMMAND PdhErrno = 0xc0000bd7 + PDH_LOGSVC_QUERY_NOT_FOUND PdhErrno = 0xc0000bd8 + PDH_LOGSVC_NOT_OPENED PdhErrno = 0xc0000bd9 + PDH_WBEM_ERROR PdhErrno = 0xc0000bda + PDH_ACCESS_DENIED PdhErrno = 0xc0000bdb + PDH_LOG_FILE_TOO_SMALL PdhErrno = 0xc0000bdc + PDH_INVALID_DATASOURCE PdhErrno = 0xc0000bdd + PDH_INVALID_SQLDB PdhErrno = 0xc0000bde + PDH_NO_COUNTERS PdhErrno = 0xc0000bdf + PDH_SQL_ALLOC_FAILED PdhErrno = 0xc0000be0 + PDH_SQL_ALLOCCON_FAILED PdhErrno = 0xc0000be1 + PDH_SQL_EXEC_DIRECT_FAILED PdhErrno = 0xc0000be2 + PDH_SQL_FETCH_FAILED PdhErrno = 0xc0000be3 + PDH_SQL_ROWCOUNT_FAILED PdhErrno = 0xc0000be4 + PDH_SQL_MORE_RESULTS_FAILED PdhErrno = 0xc0000be5 + PDH_SQL_CONNECT_FAILED PdhErrno = 0xc0000be6 + PDH_SQL_BIND_FAILED PdhErrno = 0xc0000be7 + PDH_CANNOT_CONNECT_WMI_SERVER PdhErrno = 0xc0000be8 + PDH_PLA_COLLECTION_ALREADY_RUNNING PdhErrno = 0xc0000be9 + PDH_PLA_ERROR_SCHEDULE_OVERLAP PdhErrno = 0xc0000bea + PDH_PLA_COLLECTION_NOT_FOUND PdhErrno = 0xc0000beb + PDH_PLA_ERROR_SCHEDULE_ELAPSED PdhErrno = 0xc0000bec + PDH_PLA_ERROR_NOSTART PdhErrno = 0xc0000bed + PDH_PLA_ERROR_ALREADY_EXISTS PdhErrno = 0xc0000bee + PDH_PLA_ERROR_TYPE_MISMATCH PdhErrno = 0xc0000bef + PDH_PLA_ERROR_FILEPATH PdhErrno = 0xc0000bf0 + PDH_PLA_SERVICE_ERROR PdhErrno = 0xc0000bf1 + PDH_PLA_VALIDATION_ERROR PdhErrno = 0xc0000bf2 + PDH_PLA_VALIDATION_WARNING PdhErrno = 0x80000bf3 + PDH_PLA_ERROR_NAME_TOO_LONG PdhErrno = 0xc0000bf4 + PDH_INVALID_SQL_LOG_FORMAT PdhErrno = 0xc0000bf5 + PDH_COUNTER_ALREADY_IN_QUERY PdhErrno = 0xc0000bf6 + PDH_BINARY_LOG_CORRUPT PdhErrno = 0xc0000bf7 + PDH_LOG_SAMPLE_TOO_SMALL PdhErrno = 0xc0000bf8 + PDH_OS_LATER_VERSION PdhErrno = 0xc0000bf9 + PDH_OS_EARLIER_VERSION PdhErrno = 0xc0000bfa + PDH_INCORRECT_APPEND_TIME PdhErrno = 0xc0000bfb + PDH_UNMATCHED_APPEND_COUNTER PdhErrno = 0xc0000bfc + PDH_SQL_ALTER_DETAIL_FAILED PdhErrno = 0xc0000bfd + PDH_QUERY_PERF_DATA_TIMEOUT PdhErrno = 0xc0000bfe +) + +var pdhErrors = map[PdhErrno]struct{}{ + PDH_CSTATUS_VALID_DATA: struct{}{}, + PDH_CSTATUS_NEW_DATA: struct{}{}, + PDH_CSTATUS_NO_MACHINE: struct{}{}, + PDH_CSTATUS_NO_INSTANCE: struct{}{}, + PDH_MORE_DATA: struct{}{}, + PDH_CSTATUS_ITEM_NOT_VALIDATED: struct{}{}, + PDH_RETRY: struct{}{}, + PDH_NO_DATA: struct{}{}, + PDH_CALC_NEGATIVE_DENOMINATOR: struct{}{}, + PDH_CALC_NEGATIVE_TIMEBASE: struct{}{}, + PDH_CALC_NEGATIVE_VALUE: struct{}{}, + PDH_DIALOG_CANCELLED: struct{}{}, + PDH_END_OF_LOG_FILE: struct{}{}, + PDH_ASYNC_QUERY_TIMEOUT: struct{}{}, + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE: struct{}{}, + PDH_CSTATUS_NO_OBJECT: struct{}{}, + PDH_CSTATUS_NO_COUNTER: struct{}{}, + PDH_CSTATUS_INVALID_DATA: struct{}{}, + PDH_MEMORY_ALLOCATION_FAILURE: struct{}{}, + PDH_INVALID_HANDLE: struct{}{}, + PDH_INVALID_ARGUMENT: struct{}{}, + PDH_FUNCTION_NOT_FOUND: struct{}{}, + PDH_CSTATUS_NO_COUNTERNAME: struct{}{}, + PDH_CSTATUS_BAD_COUNTERNAME: struct{}{}, + PDH_INVALID_BUFFER: struct{}{}, + PDH_INSUFFICIENT_BUFFER: struct{}{}, + PDH_CANNOT_CONNECT_MACHINE: struct{}{}, + PDH_INVALID_PATH: struct{}{}, + PDH_INVALID_INSTANCE: struct{}{}, + PDH_INVALID_DATA: struct{}{}, + PDH_NO_DIALOG_DATA: struct{}{}, + PDH_CANNOT_READ_NAME_STRINGS: struct{}{}, + PDH_LOG_FILE_CREATE_ERROR: struct{}{}, + PDH_LOG_FILE_OPEN_ERROR: struct{}{}, + PDH_LOG_TYPE_NOT_FOUND: struct{}{}, + PDH_NO_MORE_DATA: struct{}{}, + PDH_ENTRY_NOT_IN_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_REAL_TIME: struct{}{}, + PDH_UNABLE_READ_LOG_HEADER: struct{}{}, + PDH_FILE_NOT_FOUND: struct{}{}, + PDH_FILE_ALREADY_EXISTS: struct{}{}, + PDH_NOT_IMPLEMENTED: struct{}{}, + PDH_STRING_NOT_FOUND: struct{}{}, + PDH_UNABLE_MAP_NAME_FILES: struct{}{}, + PDH_UNKNOWN_LOG_FORMAT: struct{}{}, + PDH_UNKNOWN_LOGSVC_COMMAND: struct{}{}, + PDH_LOGSVC_QUERY_NOT_FOUND: struct{}{}, + PDH_LOGSVC_NOT_OPENED: struct{}{}, + PDH_WBEM_ERROR: struct{}{}, + PDH_ACCESS_DENIED: struct{}{}, + PDH_LOG_FILE_TOO_SMALL: struct{}{}, + PDH_INVALID_DATASOURCE: struct{}{}, + PDH_INVALID_SQLDB: struct{}{}, + PDH_NO_COUNTERS: struct{}{}, + PDH_SQL_ALLOC_FAILED: struct{}{}, + PDH_SQL_ALLOCCON_FAILED: struct{}{}, + PDH_SQL_EXEC_DIRECT_FAILED: struct{}{}, + PDH_SQL_FETCH_FAILED: struct{}{}, + PDH_SQL_ROWCOUNT_FAILED: struct{}{}, + PDH_SQL_MORE_RESULTS_FAILED: struct{}{}, + PDH_SQL_CONNECT_FAILED: struct{}{}, + PDH_SQL_BIND_FAILED: struct{}{}, + PDH_CANNOT_CONNECT_WMI_SERVER: struct{}{}, + PDH_PLA_COLLECTION_ALREADY_RUNNING: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_OVERLAP: struct{}{}, + PDH_PLA_COLLECTION_NOT_FOUND: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_ELAPSED: struct{}{}, + PDH_PLA_ERROR_NOSTART: struct{}{}, + PDH_PLA_ERROR_ALREADY_EXISTS: struct{}{}, + PDH_PLA_ERROR_TYPE_MISMATCH: struct{}{}, + PDH_PLA_ERROR_FILEPATH: struct{}{}, + PDH_PLA_SERVICE_ERROR: struct{}{}, + PDH_PLA_VALIDATION_ERROR: struct{}{}, + PDH_PLA_VALIDATION_WARNING: struct{}{}, + PDH_PLA_ERROR_NAME_TOO_LONG: struct{}{}, + PDH_INVALID_SQL_LOG_FORMAT: struct{}{}, + PDH_COUNTER_ALREADY_IN_QUERY: struct{}{}, + PDH_BINARY_LOG_CORRUPT: struct{}{}, + PDH_LOG_SAMPLE_TOO_SMALL: struct{}{}, + PDH_OS_LATER_VERSION: struct{}{}, + PDH_OS_EARLIER_VERSION: struct{}{}, + PDH_INCORRECT_APPEND_TIME: struct{}{}, + PDH_UNMATCHED_APPEND_COUNTER: struct{}{}, + PDH_SQL_ALTER_DETAIL_FAILED: struct{}{}, + PDH_QUERY_PERF_DATA_TIMEOUT: struct{}{}, +} + +type PdhCounterFormat uint32 + +const ( + PdhFmtDouble PdhCounterFormat = 0x200 + + PdhFmtLarge = 0x400 + + PdhFmtLong = 0x100 + + PdhFmtNoScale = 0x1000 + + PdhFmtNoCap100 = 0x8000 + + PdhFmtMultiply1000 = 0x2000 +) + +type PdhCounterValue struct { + CStatus uint32 + Pad_cgo_0 [4]byte + LongValue int32 + Pad_cgo_1 [4]byte +} diff --git a/metricbeat/module/windows/perfmon/defs_pdh_windows_amd64.go b/metricbeat/module/windows/perfmon/defs_pdh_windows_amd64.go new file mode 100644 index 000000000000..2bb3dde3c890 --- /dev/null +++ b/metricbeat/module/windows/perfmon/defs_pdh_windows_amd64.go @@ -0,0 +1,207 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo.exe -godefs defs_pdh_windows.go + +package perfmon + +type PdhErrno uintptr + +const ( + PDH_CSTATUS_VALID_DATA PdhErrno = 0x0 + PDH_CSTATUS_NEW_DATA PdhErrno = 0x1 + PDH_CSTATUS_NO_MACHINE PdhErrno = 0x800007d0 + PDH_CSTATUS_NO_INSTANCE PdhErrno = 0x800007d1 + PDH_MORE_DATA PdhErrno = 0x800007d2 + PDH_CSTATUS_ITEM_NOT_VALIDATED PdhErrno = 0x800007d3 + PDH_RETRY PdhErrno = 0x800007d4 + PDH_NO_DATA PdhErrno = 0x800007d5 + PDH_CALC_NEGATIVE_DENOMINATOR PdhErrno = 0x800007d6 + PDH_CALC_NEGATIVE_TIMEBASE PdhErrno = 0x800007d7 + PDH_CALC_NEGATIVE_VALUE PdhErrno = 0x800007d8 + PDH_DIALOG_CANCELLED PdhErrno = 0x800007d9 + PDH_END_OF_LOG_FILE PdhErrno = 0x800007da + PDH_ASYNC_QUERY_TIMEOUT PdhErrno = 0x800007db + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE PdhErrno = 0x800007dc + PDH_CSTATUS_NO_OBJECT PdhErrno = 0xc0000bb8 + PDH_CSTATUS_NO_COUNTER PdhErrno = 0xc0000bb9 + PDH_CSTATUS_INVALID_DATA PdhErrno = 0xc0000bba + PDH_MEMORY_ALLOCATION_FAILURE PdhErrno = 0xc0000bbb + PDH_INVALID_HANDLE PdhErrno = 0xc0000bbc + PDH_INVALID_ARGUMENT PdhErrno = 0xc0000bbd + PDH_FUNCTION_NOT_FOUND PdhErrno = 0xc0000bbe + PDH_CSTATUS_NO_COUNTERNAME PdhErrno = 0xc0000bbf + PDH_CSTATUS_BAD_COUNTERNAME PdhErrno = 0xc0000bc0 + PDH_INVALID_BUFFER PdhErrno = 0xc0000bc1 + PDH_INSUFFICIENT_BUFFER PdhErrno = 0xc0000bc2 + PDH_CANNOT_CONNECT_MACHINE PdhErrno = 0xc0000bc3 + PDH_INVALID_PATH PdhErrno = 0xc0000bc4 + PDH_INVALID_INSTANCE PdhErrno = 0xc0000bc5 + PDH_INVALID_DATA PdhErrno = 0xc0000bc6 + PDH_NO_DIALOG_DATA PdhErrno = 0xc0000bc7 + PDH_CANNOT_READ_NAME_STRINGS PdhErrno = 0xc0000bc8 + PDH_LOG_FILE_CREATE_ERROR PdhErrno = 0xc0000bc9 + PDH_LOG_FILE_OPEN_ERROR PdhErrno = 0xc0000bca + PDH_LOG_TYPE_NOT_FOUND PdhErrno = 0xc0000bcb + PDH_NO_MORE_DATA PdhErrno = 0xc0000bcc + PDH_ENTRY_NOT_IN_LOG_FILE PdhErrno = 0xc0000bcd + PDH_DATA_SOURCE_IS_LOG_FILE PdhErrno = 0xc0000bce + PDH_DATA_SOURCE_IS_REAL_TIME PdhErrno = 0xc0000bcf + PDH_UNABLE_READ_LOG_HEADER PdhErrno = 0xc0000bd0 + PDH_FILE_NOT_FOUND PdhErrno = 0xc0000bd1 + PDH_FILE_ALREADY_EXISTS PdhErrno = 0xc0000bd2 + PDH_NOT_IMPLEMENTED PdhErrno = 0xc0000bd3 + PDH_STRING_NOT_FOUND PdhErrno = 0xc0000bd4 + PDH_UNABLE_MAP_NAME_FILES PdhErrno = 0x80000bd5 + PDH_UNKNOWN_LOG_FORMAT PdhErrno = 0xc0000bd6 + PDH_UNKNOWN_LOGSVC_COMMAND PdhErrno = 0xc0000bd7 + PDH_LOGSVC_QUERY_NOT_FOUND PdhErrno = 0xc0000bd8 + PDH_LOGSVC_NOT_OPENED PdhErrno = 0xc0000bd9 + PDH_WBEM_ERROR PdhErrno = 0xc0000bda + PDH_ACCESS_DENIED PdhErrno = 0xc0000bdb + PDH_LOG_FILE_TOO_SMALL PdhErrno = 0xc0000bdc + PDH_INVALID_DATASOURCE PdhErrno = 0xc0000bdd + PDH_INVALID_SQLDB PdhErrno = 0xc0000bde + PDH_NO_COUNTERS PdhErrno = 0xc0000bdf + PDH_SQL_ALLOC_FAILED PdhErrno = 0xc0000be0 + PDH_SQL_ALLOCCON_FAILED PdhErrno = 0xc0000be1 + PDH_SQL_EXEC_DIRECT_FAILED PdhErrno = 0xc0000be2 + PDH_SQL_FETCH_FAILED PdhErrno = 0xc0000be3 + PDH_SQL_ROWCOUNT_FAILED PdhErrno = 0xc0000be4 + PDH_SQL_MORE_RESULTS_FAILED PdhErrno = 0xc0000be5 + PDH_SQL_CONNECT_FAILED PdhErrno = 0xc0000be6 + PDH_SQL_BIND_FAILED PdhErrno = 0xc0000be7 + PDH_CANNOT_CONNECT_WMI_SERVER PdhErrno = 0xc0000be8 + PDH_PLA_COLLECTION_ALREADY_RUNNING PdhErrno = 0xc0000be9 + PDH_PLA_ERROR_SCHEDULE_OVERLAP PdhErrno = 0xc0000bea + PDH_PLA_COLLECTION_NOT_FOUND PdhErrno = 0xc0000beb + PDH_PLA_ERROR_SCHEDULE_ELAPSED PdhErrno = 0xc0000bec + PDH_PLA_ERROR_NOSTART PdhErrno = 0xc0000bed + PDH_PLA_ERROR_ALREADY_EXISTS PdhErrno = 0xc0000bee + PDH_PLA_ERROR_TYPE_MISMATCH PdhErrno = 0xc0000bef + PDH_PLA_ERROR_FILEPATH PdhErrno = 0xc0000bf0 + PDH_PLA_SERVICE_ERROR PdhErrno = 0xc0000bf1 + PDH_PLA_VALIDATION_ERROR PdhErrno = 0xc0000bf2 + PDH_PLA_VALIDATION_WARNING PdhErrno = 0x80000bf3 + PDH_PLA_ERROR_NAME_TOO_LONG PdhErrno = 0xc0000bf4 + PDH_INVALID_SQL_LOG_FORMAT PdhErrno = 0xc0000bf5 + PDH_COUNTER_ALREADY_IN_QUERY PdhErrno = 0xc0000bf6 + PDH_BINARY_LOG_CORRUPT PdhErrno = 0xc0000bf7 + PDH_LOG_SAMPLE_TOO_SMALL PdhErrno = 0xc0000bf8 + PDH_OS_LATER_VERSION PdhErrno = 0xc0000bf9 + PDH_OS_EARLIER_VERSION PdhErrno = 0xc0000bfa + PDH_INCORRECT_APPEND_TIME PdhErrno = 0xc0000bfb + PDH_UNMATCHED_APPEND_COUNTER PdhErrno = 0xc0000bfc + PDH_SQL_ALTER_DETAIL_FAILED PdhErrno = 0xc0000bfd + PDH_QUERY_PERF_DATA_TIMEOUT PdhErrno = 0xc0000bfe +) + +var pdhErrors = map[PdhErrno]struct{}{ + PDH_CSTATUS_VALID_DATA: struct{}{}, + PDH_CSTATUS_NEW_DATA: struct{}{}, + PDH_CSTATUS_NO_MACHINE: struct{}{}, + PDH_CSTATUS_NO_INSTANCE: struct{}{}, + PDH_MORE_DATA: struct{}{}, + PDH_CSTATUS_ITEM_NOT_VALIDATED: struct{}{}, + PDH_RETRY: struct{}{}, + PDH_NO_DATA: struct{}{}, + PDH_CALC_NEGATIVE_DENOMINATOR: struct{}{}, + PDH_CALC_NEGATIVE_TIMEBASE: struct{}{}, + PDH_CALC_NEGATIVE_VALUE: struct{}{}, + PDH_DIALOG_CANCELLED: struct{}{}, + PDH_END_OF_LOG_FILE: struct{}{}, + PDH_ASYNC_QUERY_TIMEOUT: struct{}{}, + PDH_CANNOT_SET_DEFAULT_REALTIME_DATASOURCE: struct{}{}, + PDH_CSTATUS_NO_OBJECT: struct{}{}, + PDH_CSTATUS_NO_COUNTER: struct{}{}, + PDH_CSTATUS_INVALID_DATA: struct{}{}, + PDH_MEMORY_ALLOCATION_FAILURE: struct{}{}, + PDH_INVALID_HANDLE: struct{}{}, + PDH_INVALID_ARGUMENT: struct{}{}, + PDH_FUNCTION_NOT_FOUND: struct{}{}, + PDH_CSTATUS_NO_COUNTERNAME: struct{}{}, + PDH_CSTATUS_BAD_COUNTERNAME: struct{}{}, + PDH_INVALID_BUFFER: struct{}{}, + PDH_INSUFFICIENT_BUFFER: struct{}{}, + PDH_CANNOT_CONNECT_MACHINE: struct{}{}, + PDH_INVALID_PATH: struct{}{}, + PDH_INVALID_INSTANCE: struct{}{}, + PDH_INVALID_DATA: struct{}{}, + PDH_NO_DIALOG_DATA: struct{}{}, + PDH_CANNOT_READ_NAME_STRINGS: struct{}{}, + PDH_LOG_FILE_CREATE_ERROR: struct{}{}, + PDH_LOG_FILE_OPEN_ERROR: struct{}{}, + PDH_LOG_TYPE_NOT_FOUND: struct{}{}, + PDH_NO_MORE_DATA: struct{}{}, + PDH_ENTRY_NOT_IN_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_LOG_FILE: struct{}{}, + PDH_DATA_SOURCE_IS_REAL_TIME: struct{}{}, + PDH_UNABLE_READ_LOG_HEADER: struct{}{}, + PDH_FILE_NOT_FOUND: struct{}{}, + PDH_FILE_ALREADY_EXISTS: struct{}{}, + PDH_NOT_IMPLEMENTED: struct{}{}, + PDH_STRING_NOT_FOUND: struct{}{}, + PDH_UNABLE_MAP_NAME_FILES: struct{}{}, + PDH_UNKNOWN_LOG_FORMAT: struct{}{}, + PDH_UNKNOWN_LOGSVC_COMMAND: struct{}{}, + PDH_LOGSVC_QUERY_NOT_FOUND: struct{}{}, + PDH_LOGSVC_NOT_OPENED: struct{}{}, + PDH_WBEM_ERROR: struct{}{}, + PDH_ACCESS_DENIED: struct{}{}, + PDH_LOG_FILE_TOO_SMALL: struct{}{}, + PDH_INVALID_DATASOURCE: struct{}{}, + PDH_INVALID_SQLDB: struct{}{}, + PDH_NO_COUNTERS: struct{}{}, + PDH_SQL_ALLOC_FAILED: struct{}{}, + PDH_SQL_ALLOCCON_FAILED: struct{}{}, + PDH_SQL_EXEC_DIRECT_FAILED: struct{}{}, + PDH_SQL_FETCH_FAILED: struct{}{}, + PDH_SQL_ROWCOUNT_FAILED: struct{}{}, + PDH_SQL_MORE_RESULTS_FAILED: struct{}{}, + PDH_SQL_CONNECT_FAILED: struct{}{}, + PDH_SQL_BIND_FAILED: struct{}{}, + PDH_CANNOT_CONNECT_WMI_SERVER: struct{}{}, + PDH_PLA_COLLECTION_ALREADY_RUNNING: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_OVERLAP: struct{}{}, + PDH_PLA_COLLECTION_NOT_FOUND: struct{}{}, + PDH_PLA_ERROR_SCHEDULE_ELAPSED: struct{}{}, + PDH_PLA_ERROR_NOSTART: struct{}{}, + PDH_PLA_ERROR_ALREADY_EXISTS: struct{}{}, + PDH_PLA_ERROR_TYPE_MISMATCH: struct{}{}, + PDH_PLA_ERROR_FILEPATH: struct{}{}, + PDH_PLA_SERVICE_ERROR: struct{}{}, + PDH_PLA_VALIDATION_ERROR: struct{}{}, + PDH_PLA_VALIDATION_WARNING: struct{}{}, + PDH_PLA_ERROR_NAME_TOO_LONG: struct{}{}, + PDH_INVALID_SQL_LOG_FORMAT: struct{}{}, + PDH_COUNTER_ALREADY_IN_QUERY: struct{}{}, + PDH_BINARY_LOG_CORRUPT: struct{}{}, + PDH_LOG_SAMPLE_TOO_SMALL: struct{}{}, + PDH_OS_LATER_VERSION: struct{}{}, + PDH_OS_EARLIER_VERSION: struct{}{}, + PDH_INCORRECT_APPEND_TIME: struct{}{}, + PDH_UNMATCHED_APPEND_COUNTER: struct{}{}, + PDH_SQL_ALTER_DETAIL_FAILED: struct{}{}, + PDH_QUERY_PERF_DATA_TIMEOUT: struct{}{}, +} + +type PdhCounterFormat uint32 + +const ( + PdhFmtDouble PdhCounterFormat = 0x200 + + PdhFmtLarge = 0x400 + + PdhFmtLong = 0x100 + + PdhFmtNoScale = 0x1000 + + PdhFmtNoCap100 = 0x8000 + + PdhFmtMultiply1000 = 0x2000 +) + +type PdhCounterValue struct { + CStatus uint32 + Pad_cgo_0 [4]byte + LongValue int32 + Pad_cgo_1 [4]byte +} diff --git a/metricbeat/module/windows/perfmon/defs_windows.go b/metricbeat/module/windows/perfmon/defs_windows.go deleted file mode 100644 index b28ef1189229..000000000000 --- a/metricbeat/module/windows/perfmon/defs_windows.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build ignore - -package perfmon - -/* -#include -#include -#include -#include -#include -#cgo LDFLAGS: -lpdh -*/ -import "C" - -const ( - ERROR_SUCCESS = C.ERROR_SUCCESS - PDH_STATUS_VALID_DATA = C.PDH_CSTATUS_VALID_DATA - PDH_STATUS_NEW_DATA = C.PDH_CSTATUS_NEW_DATA - PDH_NO_DATA = C.PDH_NO_DATA - PDH_STATUS_NO_OBJECT = C.PDH_CSTATUS_NO_OBJECT - PDH_STATUS_NO_COUNTER = C.PDH_CSTATUS_NO_COUNTER - PDH_STATUS_INVALID_DATA = C.PDH_CSTATUS_INVALID_DATA - PDH_INVALID_HANDLE = C.PDH_INVALID_HANDLE - PDH_INVALID_DATA = C.PDH_INVALID_DATA - PDH_NO_MORE_DATA = C.PDH_NO_MORE_DATA - PDH_CALC_NEGATIVE_DENOMINATOR = C.PDH_CALC_NEGATIVE_DENOMINATOR - PdhFmtDouble = C.PDH_FMT_DOUBLE - PdhFmtLarge = C.PDH_FMT_LARGE - PdhFmtLong = C.PDH_FMT_LONG -) - -type PdhCounterValue C.PDH_FMT_COUNTERVALUE diff --git a/metricbeat/module/windows/perfmon/defs_windows_386.go b/metricbeat/module/windows/perfmon/defs_windows_386.go deleted file mode 100644 index fe0160fd57e3..000000000000 --- a/metricbeat/module/windows/perfmon/defs_windows_386.go +++ /dev/null @@ -1,28 +0,0 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo.exe -godefs defs_windows.go - -package perfmon - -const ( - ERROR_SUCCESS = 0x0 - PDH_STATUS_VALID_DATA = 0x0 - PDH_STATUS_NEW_DATA = 0x1 - PDH_NO_DATA = 0x800007d5 - PDH_STATUS_NO_OBJECT = 0xc0000bb8 - PDH_STATUS_NO_COUNTER = 0xc0000bb9 - PDH_STATUS_INVALID_DATA = 0xc0000bba - PDH_INVALID_HANDLE = 0xc0000bbc - PDH_INVALID_DATA = 0xc0000bc6 - PDH_NO_MORE_DATA = 0xc0000bcc - PDH_CALC_NEGATIVE_DENOMINATOR = 0x800007d6 - PdhFmtDouble = 0x200 - PdhFmtLarge = 0x400 - PdhFmtLong = 0x100 -) - -type PdhCounterValue struct { - CStatus uint32 - Pad_cgo_0 [4]byte - LongValue int32 - Pad_cgo_1 [4]byte -} diff --git a/metricbeat/module/windows/perfmon/defs_windows_amd64.go b/metricbeat/module/windows/perfmon/defs_windows_amd64.go deleted file mode 100644 index fe0160fd57e3..000000000000 --- a/metricbeat/module/windows/perfmon/defs_windows_amd64.go +++ /dev/null @@ -1,28 +0,0 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo.exe -godefs defs_windows.go - -package perfmon - -const ( - ERROR_SUCCESS = 0x0 - PDH_STATUS_VALID_DATA = 0x0 - PDH_STATUS_NEW_DATA = 0x1 - PDH_NO_DATA = 0x800007d5 - PDH_STATUS_NO_OBJECT = 0xc0000bb8 - PDH_STATUS_NO_COUNTER = 0xc0000bb9 - PDH_STATUS_INVALID_DATA = 0xc0000bba - PDH_INVALID_HANDLE = 0xc0000bbc - PDH_INVALID_DATA = 0xc0000bc6 - PDH_NO_MORE_DATA = 0xc0000bcc - PDH_CALC_NEGATIVE_DENOMINATOR = 0x800007d6 - PdhFmtDouble = 0x200 - PdhFmtLarge = 0x400 - PdhFmtLong = 0x100 -) - -type PdhCounterValue struct { - CStatus uint32 - Pad_cgo_0 [4]byte - LongValue int32 - Pad_cgo_1 [4]byte -} diff --git a/metricbeat/module/windows/perfmon/doc.go b/metricbeat/module/windows/perfmon/doc.go index 691a80270595..b6daada8e57e 100644 --- a/metricbeat/module/windows/perfmon/doc.go +++ b/metricbeat/module/windows/perfmon/doc.go @@ -1,9 +1,9 @@ -/* -Package perfmon collect windows performance counters. -*/ +// Package perfmon implements a Metricbeat metricset for reading Windows +// performance counters. package perfmon -//go:generate go run run.go -cmd "go tool cgo -godefs defs_windows.go" -goarch amd64 -output defs_windows_amd64.go -//go:generate go run run.go -cmd "go tool cgo -godefs defs_windows.go" -goarch 386 -output defs_windows_386.go -//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output syscall_windows.go pdh_windows.go -//go:generate gofmt -w defs_windows_amd64.go defs_windows_386.go syscall_windows.go +//go:generate go run mkpdh_defs.go +//go:generate go run run.go -cmd "go tool cgo -godefs defs_pdh_windows.go" -goarch amd64 -output defs_pdh_windows_amd64.go +//go:generate go run run.go -cmd "go tool cgo -godefs defs_pdh_windows.go" -goarch 386 -output defs_pdh_windows_386.go +//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zpdh_windows.go pdh_windows.go +//go:generate gofmt -w defs_pdh_windows_amd64.go defs_pdh_windows_386.go zpdh_windows.go diff --git a/metricbeat/module/windows/perfmon/mkpdh_defs.go b/metricbeat/module/windows/perfmon/mkpdh_defs.go new file mode 100644 index 000000000000..c0c1f1092f55 --- /dev/null +++ b/metricbeat/module/windows/perfmon/mkpdh_defs.go @@ -0,0 +1,151 @@ +// +build ignore + +package main + +import ( + "bufio" + "bytes" + "flag" + "fmt" + "os" + "os/exec" + "regexp" + "text/template" +) + +var ( + output = flag.String("output", "defs_pdh_windows.go", "output file") +) + +const includes = ` +#include +` + +type TemplateParams struct { + Errors []string +} + +const fileTemplate = ` +// go run mkpdh_defs.go +// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT + +// +build ignore + +package perfmon + +/* +#include +#include +#cgo LDFLAGS: -lpdh +*/ +import "C" + +type PdhErrno uintptr + +// PDH Error Codes +const ( +{{- range $i, $errorCode := .Errors }} + {{ $errorCode }} PdhErrno = C.{{ $errorCode }} +{{- end }} +) + +var pdhErrors = map[PdhErrno]struct{}{ +{{- range $i, $errorCode := .Errors }} + {{ $errorCode }}: struct{}{}, +{{- end }} +} + +type PdhCounterFormat uint32 + +// PDH Counter Formats +const ( + // PdhFmtDouble returns data as a double-precision floating point real. + PdhFmtDouble PdhCounterFormat = C.PDH_FMT_DOUBLE + // PdhFmtLarge returns data as a 64-bit integer. + PdhFmtLarge = C.PDH_FMT_LARGE + // PdhFmtLong returns data as a long integer. + PdhFmtLong = C.PDH_FMT_LONG + + // Use bitwise operators to combine these values with the counter type to scale the value. + + // Do not apply the counter's default scaling factor. + PdhFmtNoScale = C.PDH_FMT_NOSCALE + // Counter values greater than 100 (for example, counter values measuring + // the processor load on multiprocessor computers) will not be reset to 100. + // The default behavior is that counter values are capped at a value of 100. + PdhFmtNoCap100 = C.PDH_FMT_NOCAP100 + // Multiply the actual value by 1,000. + PdhFmtMultiply1000 = C.PDH_FMT_1000 +) + +// PdhCounterValue is the structure that receives the counter value. +type PdhCounterValue C.PDH_FMT_COUNTERVALUE +` + +var ( + tmpl = template.Must(template.New("defs_pdh_windows").Parse(fileTemplate)) + + pdhErrorRegex = regexp.MustCompile(`^#define (PDH_[\w_]+)`) +) + +func main() { + errors, err := getErrorDefines() + if err != nil { + fmt.Fprintln(os.Stderr, "error:", err) + os.Exit(1) + } + + t := TemplateParams{ + Errors: errors, + } + + if err := writeOutput(t); err != nil { + fmt.Fprintln(os.Stderr, "error:", err) + os.Exit(1) + } + + if err := gofmtOutput(); err != nil { + fmt.Fprintln(os.Stderr, "error:", err) + os.Exit(1) + } +} + +func getErrorDefines() ([]string, error) { + cmd := exec.Command("gcc", "-E", "-dD", "-") + cmd.Stdin = bytes.NewBuffer([]byte(includes)) + out, err := cmd.Output() + if err != nil { + return nil, err + } + + var errors []string + s := bufio.NewScanner(bytes.NewBuffer(out)) + for s.Scan() { + line := s.Text() + matches := pdhErrorRegex.FindStringSubmatch(line) + if len(matches) > 1 { + errors = append(errors, matches[1]) + } + } + + return errors, nil +} + +func writeOutput(p TemplateParams) error { + // Create output file. + f, err := os.Create(*output) + if err != nil { + return err + } + defer f.Close() + + if err := tmpl.Execute(f, p); err != nil { + return err + } + return nil +} + +func gofmtOutput() error { + _, err := exec.Command("gofmt", "-w", *output).Output() + return err +} diff --git a/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go b/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go index 85b9b703f255..87b26b1b5e8b 100644 --- a/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go +++ b/metricbeat/module/windows/perfmon/pdh_integration_windows_test.go @@ -5,22 +5,64 @@ package perfmon import ( "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) +const processorTimeCounter = `\Processor Information(_Total)\% Processor Time` + +func TestQuery(t *testing.T) { + q, err := NewQuery("") + if err != nil { + t.Fatal(err) + } + defer q.Close() + + err = q.AddCounter(processorTimeCounter) + if err != nil { + t.Fatal(err) + } + + for i := 0; i < 2; i++ { + err = q.Execute() + if err != nil { + t.Fatal(err) + } + } + + values, err := q.Values() + if err != nil { + t.Fatal(err) + } + + assert.Len(t, values, 1) + + value, found := values[processorTimeCounter] + if !found { + t.Fatal(processorTimeCounter, "not found") + } + + assert.NoError(t, value.Err) +} + func TestExistingCounter(t *testing.T) { config := make([]CounterConfig, 1) config[0].Name = "process" config[0].Group = make([]CounterConfigGroup, 1) config[0].Group[0].Alias = "processor_time" - config[0].Group[0].Query = "\\Processor Information(_Total)\\% Processor Time" - handle, err := GetHandle(config) - - assert.Zero(t, err) + config[0].Group[0].Query = processorTimeCounter + handle, err := NewPerfmonReader(config) + if err != nil { + t.Fatal(err) + } + defer handle.query.Close() - err = CloseQuery(handle.query) + values, err := handle.Read() + if err != nil { + t.Fatal(err) + } - assert.Zero(t, err) + t.Log(values) } func TestNonExistingCounter(t *testing.T) { @@ -29,14 +71,14 @@ func TestNonExistingCounter(t *testing.T) { config[0].Group = make([]CounterConfigGroup, 1) config[0].Group[0].Alias = "processor_performance" config[0].Group[0].Query = "\\Processor Information(_Total)\\not existing counter" - handle, err := GetHandle(config) - - assert.Equal(t, 3221228473, int(err)) + handle, err := NewPerfmonReader(config) + if assert.Error(t, err) { + assert.EqualValues(t, PDH_CSTATUS_NO_COUNTER, errors.Cause(err)) + } if handle != nil { - err = CloseQuery(handle.query) - - assert.Zero(t, err) + err = handle.query.Close() + assert.NoError(t, err) } } @@ -46,13 +88,13 @@ func TestNonExistingObject(t *testing.T) { config[0].Group = make([]CounterConfigGroup, 1) config[0].Group[0].Alias = "processor_performance" config[0].Group[0].Query = "\\non existing object\\% Processor Performance" - handle, err := GetHandle(config) - - assert.Equal(t, 3221228472, int(err)) + handle, err := NewPerfmonReader(config) + if assert.Error(t, err) { + assert.EqualValues(t, PDH_CSTATUS_NO_OBJECT, errors.Cause(err)) + } if handle != nil { - err = CloseQuery(handle.query) - - assert.Zero(t, err) + err = handle.query.Close() + assert.NoError(t, err) } } diff --git a/metricbeat/module/windows/perfmon/pdh_windows.go b/metricbeat/module/windows/perfmon/pdh_windows.go index 032c758800bd..4118af6fff78 100644 --- a/metricbeat/module/windows/perfmon/pdh_windows.go +++ b/metricbeat/module/windows/perfmon/pdh_windows.go @@ -1,132 +1,235 @@ +// +build windows + package perfmon import ( "strconv" + "syscall" + "unicode/utf16" "unsafe" - "time" - "github.com/elastic/beats/libbeat/common" + "github.com/joeshaw/multierror" + "github.com/pkg/errors" + "golang.org/x/sys/windows" ) // Windows API calls -//sys _PdhOpenQuery(dataSource uintptr, userData uintptr, query *uintptr) (err uint32) = pdh.PdhOpenQuery -//sys _PdhAddCounter(query uintptr, counterPath string, userData uintptr, counter *uintptr) (err uint32) = pdh.PdhAddEnglishCounterW -//sys _PdhCollectQueryData(query uintptr) (err uint32) = pdh.PdhCollectQueryData -//sys _PdhGetFormattedCounterValue(counter uintptr, format uint32, counterType int, value *PdhCounterValue) (err uint32) = pdh.PdhGetFormattedCounterValue -//sys _PdhCloseQuery(query uintptr) (err uint32) = pdh.PdhCloseQuery +//sys _PdhOpenQuery(dataSource *uint16, userData uintptr, query *PdhQueryHandle) (errcode error) [failretval!=0] = pdh.PdhOpenQueryW +//sys _PdhAddCounter(query PdhQueryHandle, counterPath string, userData uintptr, counter *PdhCounterHandle) (errcode error) [failretval!=0] = pdh.PdhAddEnglishCounterW +//sys _PdhCollectQueryData(query PdhQueryHandle) (errcode error) [failretval!=0] = pdh.PdhCollectQueryData +//sys _PdhGetFormattedCounterValue(counter PdhCounterHandle, format PdhCounterFormat, counterType *uint32, value *PdhCounterValue) (errcode error) [failretval!=0] = pdh.PdhGetFormattedCounterValue +//sys _PdhCloseQuery(query PdhQueryHandle) (errcode error) [failretval!=0] = pdh.PdhCloseQuery + +type PdhQueryHandle uintptr + +var InvalidQueryHandle = ^PdhQueryHandle(0) + +type PdhCounterHandle uintptr + +var InvalidCounterHandle = ^PdhCounterHandle(0) + +func PdhOpenQuery(dataSource string, userData uintptr) (PdhQueryHandle, error) { + var dataSourcePtr *uint16 + if dataSource != "" { + var err error + dataSourcePtr, err = syscall.UTF16PtrFromString(dataSource) + if err != nil { + return InvalidQueryHandle, err + } + } + + var handle PdhQueryHandle + if err := _PdhOpenQuery(dataSourcePtr, userData, &handle); err != nil { + return InvalidQueryHandle, PdhErrno(err.(syscall.Errno)) + } -type Handle struct { - status error - query uintptr - counterType int - counters []CounterGroup + return handle, nil } -type CounterGroup struct { - GroupName string - Counters []Counter +func PdhAddCounter(query PdhQueryHandle, counterPath string, userData uintptr) (PdhCounterHandle, error) { + var handle PdhCounterHandle + if err := _PdhAddCounter(query, counterPath, userData, &handle); err != nil { + return InvalidCounterHandle, PdhErrno(err.(syscall.Errno)) + } + + return handle, nil } -type Counter struct { - counterName string - counter uintptr - counterPath string - displayValue PdhCounterValue +func PdhCollectQueryData(query PdhQueryHandle) error { + if err := _PdhCollectQueryData(query); err != nil { + return PdhErrno(err.(syscall.Errno)) + } + + return nil } -type PdhError uint32 +func PdhGetFormattedCounterValue(counter PdhCounterHandle, format PdhCounterFormat) (uint32, *PdhCounterValue, error) { + var counterType uint32 + var value PdhCounterValue + if err := _PdhGetFormattedCounterValue(counter, format, &counterType, &value); err != nil { + return 0, nil, PdhErrno(err.(syscall.Errno)) + } -var errorMapping = map[PdhError]string{ - PDH_INVALID_DATA: `PDH_INVALID_DATA`, - PDH_INVALID_HANDLE: `PDH_INVALID_HANDLE`, - PDH_NO_DATA: `PDH_NO_DATA`, - PDH_NO_MORE_DATA: `PDH_NO_MORE_DATA`, - PDH_STATUS_INVALID_DATA: `PDH_STATUS_INVALID_DATA`, - PDH_STATUS_NEW_DATA: `PDH_STATUS_NEW_DATA`, - PDH_STATUS_NO_COUNTER: `PDH_STATUS_NO_COUNTER`, - PDH_STATUS_NO_OBJECT: `PDH_STATUS_NO_OBJECT`, + return counterType, &value, nil } -func GetHandle(config []CounterConfig) (*Handle, PdhError) { - q := &Handle{} - err := _PdhOpenQuery(0, 0, &q.query) - if err != ERROR_SUCCESS { - return nil, PdhError(err) +func PdhCloseQuery(query PdhQueryHandle) error { + if err := _PdhCloseQuery(query); err != nil { + return PdhErrno(err.(syscall.Errno)) } - counterGroups := make([]CounterGroup, len(config)) - q.counters = counterGroups + return nil +} - for i, v := range config { - counterGroups[i] = CounterGroup{GroupName: v.Name, Counters: make([]Counter, len(v.Group))} - for j, v1 := range v.Group { - counterGroups[i].Counters[j] = Counter{counterName: v1.Alias, counterPath: v1.Query} - err := _PdhAddCounter(q.query, counterGroups[i].Counters[j].counterPath, 0, &counterGroups[i].Counters[j].counter) - if err != ERROR_SUCCESS { - return nil, PdhError(err) - } - } +type Query struct { + handle PdhQueryHandle + counters map[string]PdhCounterHandle +} + +func NewQuery(dataSource string) (*Query, error) { + h, err := PdhOpenQuery(dataSource, 0) + if err != nil { + return nil, err } - return q, 0 + return &Query{ + handle: h, + counters: map[string]PdhCounterHandle{}, + }, nil } -func (q *Handle) ReadData(firstFetch bool) (common.MapStr, PdhError) { +func (q *Query) AddCounter(counterPath string) error { + if _, found := q.counters[counterPath]; found { + return errors.New("counter already added") + } + + h, err := PdhAddCounter(q.handle, counterPath, 0) + if err != nil { + return errors.Wrapf(err, `failed to add counter (path="%v")`, counterPath) + } - err := _PdhCollectQueryData(q.query) + q.counters[counterPath] = h + return nil +} - if firstFetch { - // Most counters require two sample values in order to compute a displayable value. So wait and then collect the second value - time.Sleep(2000) - err = _PdhCollectQueryData(q.query) +func (q *Query) Execute() error { + return PdhCollectQueryData(q.handle) +} + +type Value struct { + Num float64 + Err error +} + +func (q *Query) Values() (map[string]Value, error) { + rtn := make(map[string]Value, len(q.counters)) + for path, handle := range q.counters { + _, value, err := PdhGetFormattedCounterValue(handle, PdhFmtDouble|PdhFmtNoCap100) + if err != nil { + rtn[path] = Value{Err: err} + continue + } + + rtn[path] = Value{Num: *(*float64)(unsafe.Pointer(&value.LongValue))} } - if err != ERROR_SUCCESS { - return nil, PdhError(err) + return rtn, nil +} + +// Closes the query and all of its counters. +func (q *Query) Close() error { + return PdhCloseQuery(q.handle) +} + +type PerfmonReader struct { + query *Query // PDH Query + pathToKey map[string]string // Mapping of counter path to key used in output. + executed bool // Indicates if the query has been executed. +} + +func NewPerfmonReader(config []CounterConfig) (*PerfmonReader, error) { + query, err := NewQuery("") + if err != nil { + return nil, err } - result := common.MapStr{} + r := &PerfmonReader{ + query: query, + pathToKey: map[string]string{}, + } - for _, v := range q.counters { - groupVal := make(map[string]interface{}) - for _, v1 := range v.Counters { - err := _PdhGetFormattedCounterValue(v1.counter, PdhFmtDouble, q.counterType, &v1.displayValue) - if err != ERROR_SUCCESS { - switch err { - case PDH_CALC_NEGATIVE_DENOMINATOR: - { - //Sometimes counters return negative values. We can ignore this error. See here for a good explanation https://www.netiq.com/support/kb/doc.php?id=7010545 - groupVal[v1.counterName] = 0 - continue - } - default: - { - return nil, PdhError(err) - } - } + for _, group := range config { + for _, collector := range group.Group { + if err := query.AddCounter(collector.Query); err != nil { + query.Close() + return nil, err } - doubleValue := (*float64)(unsafe.Pointer(&v1.displayValue.LongValue)) - groupVal[v1.counterName] = *doubleValue + r.pathToKey[collector.Query] = group.Name + "." + collector.Alias } - result[v.GroupName] = groupVal } - return result, 0 + + return r, nil } -func CloseQuery(q uintptr) PdhError { - err := _PdhCloseQuery(q) - if err != ERROR_SUCCESS { - return PdhError(err) +func (r *PerfmonReader) Read() (common.MapStr, error) { + if err := r.query.Execute(); err != nil { + return nil, err } - return 0 + // Get the values. + values, err := r.query.Values() + if err != nil { + return nil, errors.Wrap(err, "failed formatting counter values") + } + + // Write the values into the map. + result := common.MapStr{} + var errs multierror.Errors + + for counterPath, value := range values { + key := r.pathToKey[counterPath] + result.Put(key, value.Num) + + if value.Err != nil { + switch value.Err { + case PDH_CALC_NEGATIVE_DENOMINATOR: + case PDH_INVALID_DATA: + if r.executed { + errs = append(errs, errors.Wrapf(value.Err, "key=%v", key)) + } + default: + errs = append(errs, errors.Wrapf(value.Err, "key=%v", key)) + } + } + } + + if !r.executed { + r.executed = true + } + + return result, errs.Err() } -func (e PdhError) Error() string { - if val, ok := errorMapping[e]; ok { - return val +func (e PdhErrno) Error() string { + // If the value is not one of the known PDH errors then assume its a + // general windows error. + if _, found := pdhErrors[e]; !found { + return syscall.Errno(e).Error() + } + + // Use FormatMessage to convert the PDH errno to a string. + // Example: https://msdn.microsoft.com/en-us/library/windows/desktop/aa373046(v=vs.85).aspx + var flags uint32 = windows.FORMAT_MESSAGE_FROM_HMODULE | windows.FORMAT_MESSAGE_ARGUMENT_ARRAY | windows.FORMAT_MESSAGE_IGNORE_INSERTS + b := make([]uint16, 300) + n, err := windows.FormatMessage(flags, modpdh.Handle(), uint32(e), 0, b, nil) + if err != nil { + return "pdh error #" + strconv.Itoa(int(e)) + } + + // Trim terminating \r and \n + for ; n > 0 && (b[n-1] == '\n' || b[n-1] == '\r'); n-- { } - return strconv.FormatUint(uint64(e), 10) + return string(utf16.Decode(b[:n])) } diff --git a/metricbeat/module/windows/perfmon/pdh_windows_test.go b/metricbeat/module/windows/perfmon/pdh_windows_test.go new file mode 100644 index 000000000000..667c7b0561c5 --- /dev/null +++ b/metricbeat/module/windows/perfmon/pdh_windows_test.go @@ -0,0 +1,14 @@ +package perfmon + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// TestPdhErrno checks that PdhError provides the correct message for known +// PDH errors and also falls back to Windows error messages for non-PDH errors. +func TestPdhErrno_Error(t *testing.T) { + assert.Contains(t, PdhErrno(PDH_CSTATUS_BAD_COUNTERNAME).Error(), "Unable to parse the counter path.") + assert.Contains(t, PdhErrno(15).Error(), "The system cannot find the drive specified.") +} diff --git a/metricbeat/module/windows/perfmon/perfmon.go b/metricbeat/module/windows/perfmon/perfmon.go index 6404434ca187..b77f1262b08f 100644 --- a/metricbeat/module/windows/perfmon/perfmon.go +++ b/metricbeat/module/windows/perfmon/perfmon.go @@ -3,11 +3,10 @@ package perfmon import ( - "errors" - "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/logp" "github.com/elastic/beats/metricbeat/mb" + "github.com/pkg/errors" ) type CounterConfig struct { @@ -20,28 +19,18 @@ type CounterConfigGroup struct { Query string `config:"query" validate:"required"` } -// init registers the MetricSet with the central registry. -// The New method will be called after the setup of the module and before starting to fetch data func init() { if err := mb.Registry.AddMetricSet("windows", "perfmon", New); err != nil { panic(err) } } -// MetricSet type defines all fields of the MetricSet -// As a minimum it must inherit the mb.BaseMetricSet fields, but can be extended with -// additional entries. These variables can be used to persist data or configuration between -// multiple fetch calls. type MetricSet struct { mb.BaseMetricSet - counters []CounterConfig - handle *Handle - firstFetch bool + reader *PerfmonReader } -// New create a new instance of the MetricSet -// Part of new is also setting up the configuration by processing additional -// configuration entries if needed. +// New create a new instance of the MetricSet. func New(base mb.BaseMetricSet) (mb.MetricSet, error) { logp.Warn("BETA: The perfmon metricset is beta") @@ -53,32 +42,21 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return nil, err } - query, err := GetHandle(config.CounterConfig) - - if err != ERROR_SUCCESS { - return nil, errors.New("initialization fails with error: " + err.Error()) + reader, err := NewPerfmonReader(config.CounterConfig) + if err != nil { + return nil, errors.Wrap(err, "initialization failed") } return &MetricSet{ BaseMetricSet: base, - counters: config.CounterConfig, - handle: query, - firstFetch: true, + reader: reader, }, nil } -// Fetch methods implements the data gathering and data conversion to the right format -// It returns the event which is then forward to the output. In case of an error, a -// descriptive error must be returned. func (m *MetricSet) Fetch() (common.MapStr, error) { - - data, err := m.handle.ReadData(m.firstFetch) - if err != ERROR_SUCCESS { - return nil, errors.New("fetching fails wir error: " + err.Error()) - } - - if m.firstFetch { - m.firstFetch = false + data, err := m.reader.Read() + if err != nil { + return nil, errors.Wrap(err, "failed reading counters") } return data, nil diff --git a/metricbeat/module/windows/perfmon/syscall_windows.go b/metricbeat/module/windows/perfmon/syscall_windows.go deleted file mode 100644 index 3549735c24c5..000000000000 --- a/metricbeat/module/windows/perfmon/syscall_windows.go +++ /dev/null @@ -1,59 +0,0 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT - -package perfmon - -import ( - "syscall" - "unsafe" -) - -var _ unsafe.Pointer - -var ( - modpdh = syscall.NewLazyDLL("pdh.dll") - - procPdhOpenQuery = modpdh.NewProc("PdhOpenQuery") - procPdhAddEnglishCounterW = modpdh.NewProc("PdhAddEnglishCounterW") - procPdhCollectQueryData = modpdh.NewProc("PdhCollectQueryData") - procPdhGetFormattedCounterValue = modpdh.NewProc("PdhGetFormattedCounterValue") - procPdhCloseQuery = modpdh.NewProc("PdhCloseQuery") -) - -func _PdhOpenQuery(dataSource uintptr, userData uintptr, query *uintptr) (err uint32) { - r0, _, _ := syscall.Syscall(procPdhOpenQuery.Addr(), 3, uintptr(dataSource), uintptr(userData), uintptr(unsafe.Pointer(query))) - err = uint32(r0) - return -} - -func _PdhAddCounter(query uintptr, counterPath string, userData uintptr, counter *uintptr) (err uint32) { - var _p0 *uint16 - _p0, _p1 := syscall.UTF16PtrFromString(counterPath) - if _p1 != nil { - return - } - return __PdhAddCounter(query, _p0, userData, counter) -} - -func __PdhAddCounter(query uintptr, counterPath *uint16, userData uintptr, counter *uintptr) (err uint32) { - r0, _, _ := syscall.Syscall6(procPdhAddEnglishCounterW.Addr(), 4, uintptr(query), uintptr(unsafe.Pointer(counterPath)), uintptr(userData), uintptr(unsafe.Pointer(counter)), 0, 0) - err = uint32(r0) - return -} - -func _PdhCollectQueryData(query uintptr) (err uint32) { - r0, _, _ := syscall.Syscall(procPdhCollectQueryData.Addr(), 1, uintptr(query), 0, 0) - err = uint32(r0) - return -} - -func _PdhGetFormattedCounterValue(counter uintptr, format uint32, counterType int, value *PdhCounterValue) (err uint32) { - r0, _, _ := syscall.Syscall6(procPdhGetFormattedCounterValue.Addr(), 4, uintptr(counter), uintptr(format), uintptr(counterType), uintptr(unsafe.Pointer(value)), 0, 0) - err = uint32(r0) - return -} - -func _PdhCloseQuery(query uintptr) (err uint32) { - r0, _, _ := syscall.Syscall(procPdhCloseQuery.Addr(), 1, uintptr(query), 0, 0) - err = uint32(r0) - return -} diff --git a/metricbeat/module/windows/perfmon/zpdh_windows.go b/metricbeat/module/windows/perfmon/zpdh_windows.go new file mode 100644 index 000000000000..987cbf385c67 --- /dev/null +++ b/metricbeat/module/windows/perfmon/zpdh_windows.go @@ -0,0 +1,71 @@ +// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT + +package perfmon + +import ( + "syscall" + "unsafe" + + "golang.org/x/sys/windows" +) + +var _ unsafe.Pointer + +var ( + modpdh = windows.NewLazySystemDLL("pdh.dll") + + procPdhOpenQueryW = modpdh.NewProc("PdhOpenQueryW") + procPdhAddEnglishCounterW = modpdh.NewProc("PdhAddEnglishCounterW") + procPdhCollectQueryData = modpdh.NewProc("PdhCollectQueryData") + procPdhGetFormattedCounterValue = modpdh.NewProc("PdhGetFormattedCounterValue") + procPdhCloseQuery = modpdh.NewProc("PdhCloseQuery") +) + +func _PdhOpenQuery(dataSource *uint16, userData uintptr, query *PdhQueryHandle) (errcode error) { + r0, _, _ := syscall.Syscall(procPdhOpenQueryW.Addr(), 3, uintptr(unsafe.Pointer(dataSource)), uintptr(userData), uintptr(unsafe.Pointer(query))) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func _PdhAddCounter(query PdhQueryHandle, counterPath string, userData uintptr, counter *PdhCounterHandle) (errcode error) { + var _p0 *uint16 + _p0, errcode = syscall.UTF16PtrFromString(counterPath) + if errcode != nil { + return + } + return __PdhAddCounter(query, _p0, userData, counter) +} + +func __PdhAddCounter(query PdhQueryHandle, counterPath *uint16, userData uintptr, counter *PdhCounterHandle) (errcode error) { + r0, _, _ := syscall.Syscall6(procPdhAddEnglishCounterW.Addr(), 4, uintptr(query), uintptr(unsafe.Pointer(counterPath)), uintptr(userData), uintptr(unsafe.Pointer(counter)), 0, 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func _PdhCollectQueryData(query PdhQueryHandle) (errcode error) { + r0, _, _ := syscall.Syscall(procPdhCollectQueryData.Addr(), 1, uintptr(query), 0, 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func _PdhGetFormattedCounterValue(counter PdhCounterHandle, format PdhCounterFormat, counterType *uint32, value *PdhCounterValue) (errcode error) { + r0, _, _ := syscall.Syscall6(procPdhGetFormattedCounterValue.Addr(), 4, uintptr(counter), uintptr(format), uintptr(unsafe.Pointer(counterType)), uintptr(unsafe.Pointer(value)), 0, 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +} + +func _PdhCloseQuery(query PdhQueryHandle) (errcode error) { + r0, _, _ := syscall.Syscall(procPdhCloseQuery.Addr(), 1, uintptr(query), 0, 0) + if r0 != 0 { + errcode = syscall.Errno(r0) + } + return +}