revert recent changes to rstats and cstats
[tomato.git] / release / src / router / cstats / cstats.h
blobfab0adae51aa9a074d0ecd7e626c1a46504938b0
1 /*
3 cstats
4 Copyright (C) 2011-2012 Augusto Bott
6 based on rstats
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
23 //#define DEBUG_NOISY
24 //#define DEBUG_STIME
26 //#ifdef DEBUG_NOISY
27 //#define _dprintf(args...) cprintf(args)
28 //#define _dprintf(args...) printf(args)
29 //#else
30 //#define _dprintf(args...) do { } while (0)
31 //#endif
33 #define K 1024
34 #define M (1024 * 1024)
35 #define G (1024 * 1024 * 1024)
37 #define SMIN 60
38 #define SHOUR (60 * 60)
39 #define SDAY (60 * 60 * 24)
40 #define Y2K 946684800UL
42 #define INTERVAL 120
44 #define MAX_NSPEED ((24 * SHOUR) / INTERVAL)
45 #define MAX_NDAILY 62
46 #define MAX_NMONTHLY 25
47 #define MAX_ROLLOVER (225 * M)
49 #define MAX_COUNTER 2
50 #define RX 0
51 #define TX 1
53 #define DAILY 0
54 #define MONTHLY 1
56 #define ID_V0 0x30305352
57 #define ID_V1 0x31305352
58 #define ID_V2 0x32305352
59 #define CURRENT_ID ID_V2
61 #define HI_BACK 5
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";
67 typedef struct {
68 int mode;
69 int kn;
70 FILE *stream;
71 } node_print_mode_t;
73 typedef struct {
74 uint32_t xtime;
75 uint64_t counter[MAX_COUNTER];
76 } data_t;
78 typedef struct _Node {
79 char ipaddr[INET_ADDRSTRLEN];
81 uint32_t id;
83 data_t daily[MAX_NDAILY];
84 int dailyp;
85 data_t monthly[MAX_NMONTHLY];
86 int monthlyp;
88 long utime;
89 uint64_t speed[MAX_NSPEED][MAX_COUNTER];
90 uint64_t last[MAX_COUNTER];
91 int tail;
92 char sync;
94 TREE_ENTRY(_Node) linkage;
95 } Node;
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);