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 #define PCI_SYSTEM 2 28 #define PCI_PROCESSOR 238 29 #define PCI_PROCESSOR_TIME 6 30 #define PCI_PROCESSOR_QUEUE_LENGTH 44 31 #define PCI_SYSTEM_UP_TIME 674 32 #define PCI_TERMINAL_SERVICES 2176 33 #define PCI_TOTAL_SESSIONS 2178 34 35 typedef enum 36 { 37 PERF_COUNTER_NOTSUPPORTED = 0, 38 PERF_COUNTER_INITIALIZED, 39 PERF_COUNTER_GET_SECOND_VALUE, /* waiting for the second raw value (needed for some, e.g. rate, counters) */ 40 PERF_COUNTER_ACTIVE, 41 }; 42 43 typedef struct perf_counter_id 44 { 45 struct perf_counter_id *next; 46 unsigned long pdhIndex; 47 wchar_t name[PDH_MAX_COUNTER_NAME]; 48 } 49 PERF_COUNTER_ID; 50 51 typedef struct perf_counter_data 52 { 53 struct perf_counter_data *next; 54 char *name; 55 char *counterpath; 56 int interval; 57 int status; 58 HCOUNTER handle; 59 PDH_RAW_COUNTER rawValues[2]; /* rate counters need two raw values */ 60 int olderRawValue; /* index of the older of both values */ 61 double *value_array; /* a circular buffer of values */ 62 int value_current; /* index of the last stored value */ 63 int value_count; /* number of values in the array */ 64 double sum; /* sum of last value_count values */ 65 } 66 PERF_COUNTER_DATA; 67 68 PDH_STATUS zbx_PdhMakeCounterPath(const char *function, PDH_COUNTER_PATH_ELEMENTS *cpe, char *counterpath); 69 PDH_STATUS zbx_PdhOpenQuery(const char *function, PDH_HQUERY query); 70 PDH_STATUS zbx_PdhAddCounter(const char *function, PERF_COUNTER_DATA *counter, PDH_HQUERY query, 71 const char *counterpath, PDH_HCOUNTER *handle); 72 PDH_STATUS zbx_PdhCollectQueryData(const char *function, const char *counterpath, PDH_HQUERY query); 73 PDH_STATUS zbx_PdhGetRawCounterValue(const char *function, const char *counterpath, PDH_HCOUNTER handle, PPDH_RAW_COUNTER value); 74 75 PDH_STATUS calculate_counter_value(const char *function, const char *counterpath, double *value); 76 wchar_t *get_counter_name(DWORD pdhIndex); 77 int check_counter_path(char *counterPath); 78 79 #endif /* ZABBIX_PERFMON_H */ 80