blob: 187861851ba054bc1a261b20d549f2769aaca660 [file] [log] [blame]
kurtis.heimerl8fd86a52012-12-16 06:23:29 +00001/**@file Module for performance-reporting mechanisms. */
2/*
3* Copyright 2012 Range Networks, Inc.
4*
5* This software is distributed under the terms of the GNU Affero Public License.
6* See the COPYING file in the main directory for details.
7*
8* This use of this software may be subject to additional restrictions.
9* See the LEGAL file in the main directory for details.
10
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU Affero General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU Affero General Public License for more details.
20
21 You should have received a copy of the GNU Affero General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24*/
25
26#ifndef REPORTING_H
27#define REPORTING_H
28
29#include <sqlite3util.h>
30#include <ostream>
31
32
33/**
34 Collect performance statistics into a database.
35 Parameters are counters or max/min trackers, all integer.
36*/
37class ReportingTable {
38
39 private:
40
41 sqlite3* mDB; ///< database connection
42 int mFacility; ///< rsyslogd facility
43
44
45
46 public:
47
48 /**
49 Open the database connection;
50 create the table if it does not exist yet.
51 */
52 ReportingTable(const char* filename);
53
54 /** Create a new parameter. */
55 bool create(const char* paramName);
56
57 /** Create an indexed parameter set. */
58 bool create(const char* baseBame, unsigned minIndex, unsigned maxIndex);
59
60 /** Increment a counter. */
61 bool incr(const char* paramName);
62
63 /** Increment an indexed counter. */
64 bool incr(const char* baseName, unsigned index);
65
66 /** Take a max of a parameter. */
67 bool max(const char* paramName, unsigned newVal);
68
69 /** Take a max of an indexed parameter. */
70 bool max(const char* paramName, unsigned index, unsigned newVal);
71
72 /** Clear a value. */
73 bool clear(const char* paramName);
74
75 /** Clear an indexed value. */
76 bool clear(const char* paramName, unsigned index);
77
78 /** Dump the database to a stream. */
79 void dump(std::ostream&) const;
80
81};
82
83#endif
84
85
86// vim: ts=4 sw=4