| 1 | /************************************************************************** |
|---|
| 2 | * Copyright (C) 2004-2007 by Michael Medin <michael@medin.name> * |
|---|
| 3 | * * |
|---|
| 4 | * This code is part of NSClient++ - http://trac.nakednuns.org/nscp * |
|---|
| 5 | * * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify * |
|---|
| 7 | * it under the terms of the GNU General Public License as published by * |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
|---|
| 9 | * (at your option) any later version. * |
|---|
| 10 | * * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, * |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
|---|
| 14 | * GNU General Public License for more details. * |
|---|
| 15 | * * |
|---|
| 16 | * You should have received a copy of the GNU General Public License * |
|---|
| 17 | * along with this program; if not, write to the * |
|---|
| 18 | * Free Software Foundation, Inc., * |
|---|
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | #pragma once |
|---|
| 22 | |
|---|
| 23 | #include "PDHCollectors.h" |
|---|
| 24 | #include <thread.h> |
|---|
| 25 | #include <Mutex.h> |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * @ingroup NSClientCompat |
|---|
| 29 | * PDH collector thread (gathers performance data and allows for clients to retrieve it) |
|---|
| 30 | * |
|---|
| 31 | * @version 1.0 |
|---|
| 32 | * first version |
|---|
| 33 | * |
|---|
| 34 | * @date 02-13-2005 |
|---|
| 35 | * |
|---|
| 36 | * @author mickem |
|---|
| 37 | * |
|---|
| 38 | * @par license |
|---|
| 39 | * This code is absolutely free to use and modify. The code is provided "as is" with |
|---|
| 40 | * no expressed or implied warranty. The author accepts no liability if it causes |
|---|
| 41 | * any damage to your computer, causes your pet to fall ill, increases baldness |
|---|
| 42 | * or makes your car start emitting strange noises when you start it up. |
|---|
| 43 | * This code has no bugs, just undocumented features! |
|---|
| 44 | * |
|---|
| 45 | */ |
|---|
| 46 | class PDHCollector { |
|---|
| 47 | private: |
|---|
| 48 | MutexHandler mutexHandler; |
|---|
| 49 | HANDLE hStopEvent_; |
|---|
| 50 | int checkIntervall_; |
|---|
| 51 | |
|---|
| 52 | PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large> memCmtLim; |
|---|
| 53 | PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large> memCmt; |
|---|
| 54 | PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large> upTime; |
|---|
| 55 | PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large> cpu; |
|---|
| 56 | |
|---|
| 57 | public: |
|---|
| 58 | PDHCollector(); |
|---|
| 59 | virtual ~PDHCollector(); |
|---|
| 60 | DWORD threadProc(LPVOID lpParameter); |
|---|
| 61 | void exitThread(void); |
|---|
| 62 | |
|---|
| 63 | // Retrieve values |
|---|
| 64 | int getCPUAvrage(std::wstring time); |
|---|
| 65 | long long getUptime(); |
|---|
| 66 | unsigned long long getMemCommitLimit(); |
|---|
| 67 | unsigned long long getMemCommit(); |
|---|
| 68 | bool loadCounter(PDH::PDHQuery &pdh); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | private: |
|---|
| 72 | // bool isRunning(void); |
|---|
| 73 | // void startRunning(void); |
|---|
| 74 | // void stopRunning(void); |
|---|
| 75 | |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | typedef Thread<PDHCollector> PDHCollectorThread; |
|---|