diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-24 11:02:35 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-24 11:02:35 +0300 |
commit | c36ee7102c3095f70e8db52aa55046c1393ff4cd (patch) | |
tree | e21b479c6e1d9c4b1c2fc8e6f0eed515b0588fe7 /src/report.c | |
parent | 0d24087bca70de572cda0e35b91678816c5d9b40 (diff) | |
download | tagr-c36ee7102c3095f70e8db52aa55046c1393ff4cd.tar.gz tagr-c36ee7102c3095f70e8db52aa55046c1393ff4cd.tar.bz2 |
Fix statistics gathering algorithm. Start implementing drawing functions.
* src/output.c: New file.
* src/Makefile.am (tagr_SOURCES): Add output.c
* src/graph.c (draw_graph): New function.
* src/main.c (mkfilename): Allow for suffix=NULL
* src/report.c (tr_init): Set queue sizes to exactly the number
of the corresponding samples.
(update_output): New function.
(rebuild): Implement
* src/stat.c (interpolate): Avoid interpolation if time span is
less than the step.
Use queue_put to store the data and always call the overflow
procedure, if supplied.
(overflow): Fix condition.
(compute_avg): New function.
(ovf_monthly, ovf_weekly, ovf_daily): Add verbose diagnostics.
(_convert): Additional argument: overflow function.
(convert_yearly, convert_monthly, convert_weekly): Compute
the average.
Add verbose diagnostics.
(convert_daily): Add verbose diagnostics.
* src/tagr.h (update_output, draw_graph): New protos.
Diffstat (limited to 'src/report.c')
-rw-r--r-- | src/report.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/report.c b/src/report.c index 08989ec..3a7fc1c 100644 --- a/src/report.c +++ b/src/report.c @@ -72,16 +72,16 @@ void tr_init (struct traffic_record *tr) { tr->day_hist.queue = tr->history; - tr->day_hist.size = DAY_COUNT + 2; + tr->day_hist.size = DAY_COUNT; tr->week_hist.queue = tr->day_hist.queue + tr->day_hist.size; - tr->week_hist.size = WEEK_COUNT + 2; + tr->week_hist.size = WEEK_COUNT; tr->month_hist.queue = tr->week_hist.queue + tr->week_hist.size; - tr->month_hist.size = MONTH_COUNT + 2; + tr->month_hist.size = MONTH_COUNT; tr->year_hist.queue = tr->month_hist.queue + tr->month_hist.size; - tr->year_hist.size = YEAR_COUNT + 2; + tr->year_hist.size = YEAR_COUNT; } static void @@ -234,8 +234,51 @@ report (Stat *stat, time_t timestamp) logmsg (L_WARNING, "%s not found in config", stat->name); } +int +update_router (datum key, time_t timestamp) +{ + char id[MAX_NAME_LENGTH+1]; + struct traffic_record *tr = NULL; + SD *sd; + + if (key.dsize > MAX_NAME_LENGTH) + { + logmsg (L_ERR, _("tag name too long (%u)"), key.dsize); + return 1; + } + memcpy (id, key.dptr, key.dsize); + id[key.dsize] = 0; + sd = find_router_id (id); + if (!sd) + { + logmsg (L_ERR, _("%s: no such router"), id); + return 1; + } + _read_db (key, &tr); + if (tr) + { + update_output (sd, tr, timestamp); + free (tr); + } + + return 0; +} + void rebuild () { - die (EX_SOFTWARE, "Rebuild is not yet implemented"); + datum key; + datum content; + time_t now = time (NULL); + + open_db (); + key = gdbm_firstkey (dbf); + while (key.dptr) + { + datum nextkey = gdbm_nextkey ( dbf, key ); + update_router (key, now); + free (key.dptr); + key = nextkey; + } + close_db (); } |