1 /* 2 ** Zabbix 3 ** Copyright (C) 2001-2021 Zabbix SIA 4 ** 5 ** This program is free software; you can redistribute it and/or modify 6 ** it under the terms of the GNU General Public License as published by 7 ** the Free Software Foundation; either version 2 of the License, or 8 ** (at your option) any later version. 9 ** 10 ** This program is distributed in the hope that it will be useful, 11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 ** GNU General Public License for more details. 14 ** 15 ** You should have received a copy of the GNU General Public License 16 ** along with this program; if not, write to the Free Software 17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 **/ 19 20 #ifndef ZABBIX_PERFMON_H 21 #define ZABBIX_PERFMON_H 22 23 #ifndef _WINDOWS 24 # error "This module is only available for Windows OS" 25 #endif 26 27 /* this struct must be only modified along with mapping builtin_counter_ref[] in perfmon.c */ 28 typedef enum 29 { 30 PCI_SYSTEM = 0, 31 PCI_PROCESSOR, 32 PCI_PROCESSOR_INFORMATION, 33 PCI_PROCESSOR_TIME, 34 PCI_PROCESSOR_QUEUE_LENGTH, 35 PCI_SYSTEM_UP_TIME, 36 PCI_TERMINAL_SERVICES, 37 PCI_TOTAL_SESSIONS, 38 PCI_MAX_INDEX = PCI_TOTAL_SESSIONS 39 } 40 zbx_builtin_counter_ref_t; 41 42 typedef enum 43 { 44 PERF_COUNTER_NOTSUPPORTED = 0, 45 PERF_COUNTER_INITIALIZED, 46 PERF_COUNTER_GET_SECOND_VALUE, /* waiting for the second raw value (needed for some, e.g. rate, counters) */ 47 PERF_COUNTER_ACTIVE 48 } 49 zbx_perf_counter_status_t; 50 51 typedef enum 52 { 53 PERF_COUNTER_LANG_DEFAULT = 0, 54 PERF_COUNTER_LANG_EN 55 } 56 zbx_perf_counter_lang_t; 57 58 typedef struct perf_counter_id 59 { 60 struct perf_counter_id *next; 61 unsigned long pdhIndex; 62 wchar_t name[PDH_MAX_COUNTER_NAME]; 63 } 64 zbx_perf_counter_id_t; 65 66 typedef struct perf_counter_data 67 { 68 struct perf_counter_data *next; 69 char *name; 70 char *counterpath; 71 int interval; 72 zbx_perf_counter_lang_t lang; 73 zbx_perf_counter_status_t status; 74 HCOUNTER handle; 75 PDH_RAW_COUNTER rawValues[2]; /* rate counters need two raw values */ 76 int olderRawValue; /* index of the older of both values */ 77 double *value_array; /* a circular buffer of values */ 78 int value_current; /* index of the last stored value */ 79 int value_count; /* number of values in the array */ 80 double sum; /* sum of last value_count values */ 81 } 82 zbx_perf_counter_data_t; 83 84 PDH_STATUS zbx_PdhMakeCounterPath(const char *function, PDH_COUNTER_PATH_ELEMENTS *cpe, char *counterpath); 85 PDH_STATUS zbx_PdhOpenQuery(const char *function, PDH_HQUERY query); 86 PDH_STATUS zbx_PdhAddCounter(const char *function, zbx_perf_counter_data_t *counter, PDH_HQUERY query, 87 const char *counterpath, zbx_perf_counter_lang_t lang, PDH_HCOUNTER *handle); 88 PDH_STATUS zbx_PdhCollectQueryData(const char *function, const char *counterpath, PDH_HQUERY query); 89 PDH_STATUS zbx_PdhGetRawCounterValue(const char *function, const char *counterpath, PDH_HCOUNTER handle, PPDH_RAW_COUNTER value); 90 91 PDH_STATUS calculate_counter_value(const char *function, const char *counterpath, zbx_perf_counter_lang_t lang, double *value); 92 wchar_t *get_counter_name(DWORD pdhIndex); 93 int check_counter_path(char *counterPath, int convert_from_numeric); 94 int init_builtin_counter_indexes(void); 95 DWORD get_builtin_counter_index(zbx_builtin_counter_ref_t counter_ref); 96 97 #endif /* ZABBIX_PERFMON_H */ 98