/src/ntopng/include/StatsManager.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2013-26 - ntop.org |
4 | | * |
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 3 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 Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef _STATS_MANAGER_H_ |
23 | | #define _STATS_MANAGER_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | struct statsManagerRetrieval { |
28 | | vector<string> rows; |
29 | | int num_vals; |
30 | | |
31 | 0 | statsManagerRetrieval() : num_vals(0) {} |
32 | | }; |
33 | | |
34 | | class StatsManager : protected SQLiteStoreManager { |
35 | | public: |
36 | | StatsManager(NetworkInterface* iface); |
37 | 2 | ~StatsManager() {}; |
38 | | int insertMinuteSampling(time_t epoch, const char* sampling); |
39 | | int insertHourSampling(time_t epoch, const char* sampling); |
40 | | int insertDaySampling(time_t epoch, const char* sampling); |
41 | | int getMinuteSampling(time_t epoch, string* sampling); |
42 | | int openStore(const char* cache_name); |
43 | | int retrieveMinuteStatsInterval(time_t epoch_start, time_t epoch_end, |
44 | | struct statsManagerRetrieval* retvals); |
45 | | int retrieveHourStatsInterval(time_t epoch_start, time_t epoch_end, |
46 | | struct statsManagerRetrieval* retvals); |
47 | | int retrieveDayStatsInterval(time_t epoch_start, time_t epoch_end, |
48 | | struct statsManagerRetrieval* retvals); |
49 | | int deleteMinuteStatsOlderThan(unsigned num_days); |
50 | | int deleteHourStatsOlderThan(unsigned num_days); |
51 | | int deleteDayStatsOlderThan(unsigned num_days); |
52 | | |
53 | | private: |
54 | | const char *MINUTE_CACHE_NAME, *HOUR_CACHE_NAME, |
55 | | *DAY_CACHE_NAME; // see constructor for initialization |
56 | | /* |
57 | | * map has O(log(n)) access time, but we suppose the number |
58 | | * of caches is not huge |
59 | | */ |
60 | | std::map<string, bool> caches; |
61 | | |
62 | | int insertSampling(const char* sampling, const char* cache_name, |
63 | | long int key); |
64 | | int getSampling(string* sampling, const char* cache_name, time_t key_low, |
65 | | time_t key_high); |
66 | | int deleteStatsOlderThan(const char* cache_name, const time_t key); |
67 | | int retrieveStatsInterval(struct statsManagerRetrieval* retvals, |
68 | | const char* cache_name, const time_t key_start, |
69 | | const time_t key_end); |
70 | | }; |
71 | | |
72 | | #endif /* _STATS_MANAGER_H_ */ |