4 Copyright (C) 2011-2012 Augusto Bott
7 Copyright (C) 2006-2009 Jonathan Zarate
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
22 //#define DEBUG_CSTATS
27 //#define _dprintf(args...) cprintf(args)
28 //#define _dprintf(args...) printf(args)
30 //#define _dprintf(args...) do { } while (0)
34 #define M (1024 * 1024)
35 #define G (1024 * 1024 * 1024)
38 #define SHOUR (60 * 60)
39 #define SDAY (60 * 60 * 24)
40 #define Y2K 946684800UL
44 #define MAX_NSPEED ((24 * SHOUR) / INTERVAL)
46 #define MAX_NMONTHLY 25
47 #define MAX_ROLLOVER (225 * M)
56 #define ID_V0 0x30305352
57 #define ID_V1 0x31305352
58 #define ID_V2 0x32305352
59 #define CURRENT_ID ID_V2
63 const char history_fn
[] = "/var/lib/misc/cstats-history";
64 const char uncomp_fn
[] = "/var/tmp/cstats-uncomp";
65 const char source_fn
[] = "/var/lib/misc/cstats-source";
75 uint64_t counter
[MAX_COUNTER
];
78 typedef struct _Node
{
79 char ipaddr
[INET_ADDRSTRLEN
];
83 data_t daily
[MAX_NDAILY
];
85 data_t monthly
[MAX_NMONTHLY
];
89 uint64_t speed
[MAX_NSPEED
][MAX_COUNTER
];
90 uint64_t last
[MAX_COUNTER
];
94 TREE_ENTRY(_Node
) linkage
;
97 typedef TREE_HEAD(_Tree
, _Node
) Tree
;
99 TREE_DEFINE(_Node
, linkage
);
101 int Node_compare(Node
*lhs
, Node
*rhs
);
102 Node
*Node_new(char *ipaddr
);