Source
PDH_STATUS zbx_PdhGetRawCounterValue(const char *function, const char *counterpath, PDH_HCOUNTER handle, PPDH_RAW_COUNTER value)
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
static ZBX_THREAD_LOCAL zbx_perf_counter_id_t *PerfCounterList = NULL;
/* This struct contains mapping between built-in English object names and PDH indexes. */
/* If you change it then you also need to add enum values to zbx_builtin_object_ref_t. */
static struct builtin_object_ref
{
unsigned long pdhIndex;
wchar_t eng_name[PDH_MAX_COUNTER_NAME];
DWORD minSupported_dwMajorVersion;
DWORD minSupported_dwMinorVersion;
}
builtin_object_map[] =
{
{ 0, L"System", 0, 0 },
{ 0, L"Processor", 0, 0 },
{ 0, L"Processor Information", 6, 1 },
{ 0, L"Terminal Services", 0, 0 }
};
/* this enum must be only modified along with builtin_object_map[] */
typedef enum
{
POI_SYSTEM = 0,
POI_PROCESSOR,
POI_PROCESSOR_INFORMATION,
POI_TERMINAL_SERVICES,
POI_MAX_INDEX = POI_TERMINAL_SERVICES
}
zbx_builtin_object_ref_t;
/* This struct contains mapping between built-in English counter names and PDH indexes. */
/* If you change it then you also need to add enum values to zbx_builtin_counter_ref_t. */
static struct builtin_counter_ref
{
unsigned long pdhIndex;
zbx_builtin_object_ref_t object;
wchar_t eng_name[PDH_MAX_COUNTER_NAME];
DWORD minSupported_dwMajorVersion;
DWORD minSupported_dwMinorVersion;
}
builtin_counter_map[] =
{
{ 0, POI_SYSTEM, L"Processor Queue Length", 0, 0},
{ 0, POI_SYSTEM, L"System Up Time", 0, 0},
{ 0, POI_PROCESSOR, L"% Processor Time", 0, 0},
{ 0, POI_PROCESSOR_INFORMATION, L"% Processor Time", 6, 1},
{ 0, POI_TERMINAL_SERVICES, L"Total Sessions", 0, 0}
};
PDH_STATUS zbx_PdhMakeCounterPath(const char *function, PDH_COUNTER_PATH_ELEMENTS *cpe, char *counterpath)
{
DWORD dwSize = PDH_MAX_COUNTER_PATH;
wchar_t *wcounterPath = NULL;
PDH_STATUS pdh_status;
wcounterPath = zbx_malloc(wcounterPath, sizeof(wchar_t) * PDH_MAX_COUNTER_PATH);
if (ERROR_SUCCESS != (pdh_status = PdhMakeCounterPath(cpe, wcounterPath, &dwSize, 0)))
{
char *object, *counter;
object = zbx_unicode_to_utf8(cpe->szObjectName);
counter = zbx_unicode_to_utf8(cpe->szCounterName);
zabbix_log(LOG_LEVEL_ERR, "%s(): cannot make counterpath for \"\\%s\\%s\": %s",