"Fossies" - the Fresh Open Source Software Archive 
Member "netxms-3.8.166/src/server/core/winperf.cpp" (23 Feb 2021, 3299 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "winperf.cpp" see the
Fossies "Dox" file reference documentation.
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2020 Victor Kirhenshtein
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: winperf.cpp
20 **
21 **/
22
23 #include "nxcore.h"
24
25 /**
26 * Create new empty performance object
27 */
28 WinPerfObject::WinPerfObject(const TCHAR *name)
29 {
30 m_name = _tcsdup(name);
31 m_instances = new StringList;
32 m_counters = new StringList;
33 }
34
35 /**
36 * Destructor
37 */
38 WinPerfObject::~WinPerfObject()
39 {
40 free(m_name);
41 delete m_instances;
42 delete m_counters;
43 }
44
45 /**
46 * Fill information from agent
47 */
48 bool WinPerfObject::readDataFromAgent(AgentConnection *conn)
49 {
50 TCHAR param[256];
51 _sntprintf(param, 256, _T("PDH.ObjectCounters(\"%s\")"), m_name);
52
53 StringList *data;
54 if (conn->getList(param, &data) != ERR_SUCCESS)
55 return false;
56 for(int i = 0; i < data->size(); i++)
57 m_counters->add(data->get(i));
58 delete data;
59
60 _sntprintf(param, 256, _T("PDH.ObjectInstances(\"%s\")"), m_name);
61 if (conn->getList(param, &data) != ERR_SUCCESS)
62 return false;
63 for(int i = 0; i < data->size(); i++)
64 m_instances->add(data->get(i));
65 delete data;
66
67 return true;
68 }
69
70 /**
71 * Fill NXCP message with object's data
72 *
73 * @return next available variable ID
74 */
75 UINT32 WinPerfObject::fillMessage(NXCPMessage *msg, UINT32 baseId)
76 {
77 msg->setField(baseId, m_name);
78 msg->setField(baseId + 1, (UINT32)m_counters->size());
79 msg->setField(baseId + 2, (UINT32)m_instances->size());
80
81 UINT32 varId = baseId + 3;
82 for(int i = 0; i < m_counters->size(); i++)
83 msg->setField(varId++, m_counters->get(i));
84 for(int i = 0; i < m_instances->size(); i++)
85 msg->setField(varId++, m_instances->get(i));
86 return varId;
87 }
88
89 /**
90 * Get windows performance objects from node
91 */
92 ObjectArray<WinPerfObject> *WinPerfObject::getWinPerfObjectsFromNode(Node *node, AgentConnection *conn)
93 {
94 ObjectArray<WinPerfObject> *objects;
95 StringList *data;
96 if (conn->getList(_T("PDH.Objects"), &data) == ERR_SUCCESS)
97 {
98 objects = new ObjectArray<WinPerfObject>(data->size(), 16, Ownership::True);
99 for(int i = 0; i < data->size(); i++)
100 objects->add(new WinPerfObject(data->get(i)));
101 delete data;
102
103 for(int i = 0; i < objects->size(); i++)
104 {
105 if (!objects->get(i)->readDataFromAgent(conn))
106 {
107 DbgPrintf(5, _T("WinPerfObject::getWinPerfObjectsFromNode(%s [%d]): cannot read data for object %s"), node->getName(), node->getId(), objects->get(i)->getName());
108 objects->remove(i);
109 i--;
110 }
111 }
112 if (objects->size() == 0)
113 delete_and_null(objects);
114 }
115 else
116 {
117 DbgPrintf(5, _T("WinPerfObject::getWinPerfObjectsFromNode(%s [%d]): cannot read PDH.Objects list"), node->getName(), node->getId());
118 objects = NULL;
119 }
120 return objects;
121 }