source: nscp/include/PDHCollectors.h @ cea178b

0.4.00.4.10.4.2stable
Last change on this file since cea178b was cea178b, checked in by Michael Medin <michael@…>, 8 years ago

MAJOR CHANGES
2004-04-19 MickeM

+ Added SSL support
+ Added alot of new options
+ Added documentation

  • Renamed and restructured NSCLientCompat to CheckSystem
  • *ALOT* of fixes all over : We are now starting to get to something that is "stable" : This means that soon you might actually be able to use this.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1#pragma once
2
3#include <PDHCounter.h>
4
5namespace PDHCollectors {
6        class StaticPDHCounterListener : public PDH::PDHCounterListener {
7                __int64 value_;
8        public:
9                virtual void collect(const PDH::PDHCounter &counter) {
10                        setValue(counter.getInt64Value());
11                }
12                void attach(const PDH::PDHCounter &counter){}
13                void detach(const PDH::PDHCounter &counter){}
14                void setValue(__int64 value) {
15                        value_ = value;
16                }
17                __int64 getValue() const {
18                        return value_;
19                }
20        };
21
22
23        class RoundINTPDHBufferListener : public PDH::PDHCounterListener {
24                unsigned int length;
25                int *buffer;
26                unsigned int current;
27        public:
28                RoundINTPDHBufferListener() : buffer(NULL), length(0), current(0) {}
29                RoundINTPDHBufferListener(int length_) : length(length_), current(0) {
30                        buffer = new int[length];
31                        for (unsigned int i=0; i<length;i++)
32                                buffer[i] = 0;
33                }
34                virtual ~RoundINTPDHBufferListener() {
35                        delete [] buffer;
36                }
37               
38                /**
39                 * Resize the buffer to a new length
40                 *
41                 * @todo Make this copy the old buffer if there is one.
42                 *
43                 * @param newLength The new length
44                 */
45                void resize(int newLength) {
46                        delete [] buffer;
47
48                        current = 0;
49                        length = newLength;
50
51                        buffer = new int[length];
52                        for (unsigned int i=0; i<length;i++)
53                                buffer[i] = 0;
54                               
55                }
56                virtual void collect(const PDH::PDHCounter &counter) {
57                        pushValue(static_cast<int>(counter.getInt64Value()));
58                }
59                void attach(const PDH::PDHCounter &counter){}
60                void detach(const PDH::PDHCounter &counter){}
61                void pushValue(int value) {
62                        if (buffer == NULL)
63                                return;
64                        if (current >= length)
65                                return;
66                        buffer[current++] = value;
67                        if (current >= length)
68                                current = 0;
69                }
70                int getAvrage(unsigned int backItems) const {
71                        if ((backItems == 0) || (backItems >= length))
72                                return -1;
73                        double ret = 0;
74                        if (current >= backItems) {
75                                // Handle "whole" list.
76                                for (unsigned int i=current-backItems; i<current;i++)
77                                        ret += buffer[i];
78                        } else {
79                                // Handle split list.
80                                for (unsigned int i=0; i<current;i++)
81                                        ret += buffer[i];
82                                for (unsigned int i=length-backItems+current; i<length;i++)
83                                        ret += buffer[i];
84                        }
85                        return static_cast<int>(ret/backItems);
86                }
87                inline unsigned int getLength() const {
88                        return length;
89                }
90        };
91
92}
Note: See TracBrowser for help on using the repository browser.