diff options
author | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-28 16:27:03 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-28 16:27:03 +0300 |
commit | 20d7f1d7e051c6b021a3f5d088985a74c3370b29 (patch) | |
tree | 5c5dc1c1b401e055096b8ec216a6bd97eb76a520 /src/stat.c | |
parent | 29e4b3da0990aca9db232dc3ce0a57722ccf1cac (diff) | |
download | tagr-20d7f1d7e051c6b021a3f5d088985a74c3370b29.tar.gz tagr-20d7f1d7e051c6b021a3f5d088985a74c3370b29.tar.bz2 |
Store timestamps. Implement zero-unknown option.
* src/graph.c (draw_graph): Use timestamps from queue entries.
Implement zero_unknown_option.
* src/output.c: Store timestamps in traffic_history entries.
* src/readconfig.c (cb_monitor, cb_server): Fix checks for
empty ID.
(tagr_kw): New keyword cut-out-fraction.
(readconfig): Reset cut_out_fraction if it is < 1.0.
* src/report.c: Print timestamps.
* src/stat.c (cut_out_fraction): New variable.
(ovf_t, overflow): Remove (spurious now) arguments.
(interpolate, overflow, update_stats): Don't interpolate if
time interval between this sample and the lastly taken one
is greater than step * cut_out_fraction.
* src/tagr.h (TAGR_CUT_OUT): New define.
Diffstat (limited to 'src/stat.c')
-rw-r--r-- | src/stat.c | 64 |
1 files changed, 39 insertions, 25 deletions
@@ -24,14 +24,15 @@ #include <glob.h> #define obstack_chunk_alloc malloc #define obstack_chunk_free free #include <obstack.h> #include <tagr.h> -typedef int (*ovf_t) (struct traffic_history *th, struct traffic_record *tr, - time_t now); +double cut_out_fraction = TAGR_CUT_OUT; + +typedef int (*ovf_t) (struct traffic_history *th, struct traffic_record *tr); void interpolate (queue_t *q, time_t step, time_t now, time_t last_time, struct traffic_history *last_rates, time_t interval, double inrate, double outrate, @@ -40,101 +41,104 @@ interpolate (queue_t *q, { time_t next; struct traffic_history th; if (now - last_time <= step) { + th.time = now; th.inrate = inrate; th.outrate = outrate; verbose (3, _("insert %lu %g %g"), next, th.inrate, th.outrate); queue_put (q, &th); if (ovf) - ovf (&th, tr, now); + ovf (&th, tr); return; } for (next = last_time + step; next <= now; next += step) { + th.time = next; th.inrate = (inrate - last_rates->inrate) * (next - last_time) / interval + last_rates->inrate; th.outrate = (outrate - last_rates->outrate) * (next - last_time) / interval + last_rates->outrate; verbose (3, _("insert %lu %g %g"), next, th.inrate, th.outrate); queue_put (q, &th); if (ovf) - ovf (&th, tr, now); + ovf (&th, tr); } } int overflow (struct traffic_history *th, struct traffic_record *tr, - time_t now, ovf_t ovf, struct avg_acc *avg, queue_t *q, - int maxcount, int step) { - if (now - avg->time >= step) + time_t interval = th->time - avg->time; + if (interval >= step) { struct traffic_history *lastp = queue_get_tail (q); - if (lastp) + if (lastp && interval < step * cut_out_fraction) interpolate (q, step, - now, + th->time, avg->time, lastp, - now - avg->time, + interval, avg->inrate, avg->outrate, ovf, tr); else { struct traffic_history tmp; + tmp.time = avg->time; tmp.inrate = avg->inrate; tmp.outrate = avg->outrate; - verbose (3, _("insert %lu %g %g"), now, tmp.inrate, tmp.outrate); + verbose (3, _("insert %lu %g %g"), + tmp.time, tmp.inrate, tmp.outrate); queue_put (q, &tmp); } avg->inrate = avg->outrate = 0; avg->count = 0; - avg->time = now; + avg->time = th->time; } avg->inrate = (avg->count * avg->inrate + th->inrate) / (avg->count + 1); avg->outrate = (avg->count * avg->outrate + th->outrate) / (avg->count + 1); avg->count++; } int -ovf_monthly (struct traffic_history *th, struct traffic_record *tr, time_t now) +ovf_monthly (struct traffic_history *th, struct traffic_record *tr) { verbose (2, _("begin overflow_monthly %lu %g %g"), - now, th->inrate, th->outrate); - overflow (th, tr, now, NULL, &tr->year_avg, &tr->year_hist, - YEAR_COUNT, YEAR_SAMPLE); + th->time, th->inrate, th->outrate); + overflow (th, tr, NULL, &tr->year_avg, &tr->year_hist, + YEAR_SAMPLE); verbose (2, _("end overflow_monthly")); } int -ovf_weekly (struct traffic_history *th, struct traffic_record *tr, time_t now) +ovf_weekly (struct traffic_history *th, struct traffic_record *tr) { verbose (2, _("begin overflow_weekly %lu %g %g"), - now, th->inrate, th->outrate); - overflow (th, tr, now, ovf_monthly, &tr->month_avg, &tr->month_hist, - MONTH_COUNT, MONTH_SAMPLE); + th->time, th->inrate, th->outrate); + overflow (th, tr, ovf_monthly, &tr->month_avg, &tr->month_hist, + MONTH_SAMPLE); verbose (2, _("end overflow_daily")); } int -ovf_daily (struct traffic_history *th, struct traffic_record *tr, time_t now) +ovf_daily (struct traffic_history *th, struct traffic_record *tr) { verbose (2, _("begin overflow_daily %lu %g %g"), - now, th->inrate, th->outrate); - overflow (th, tr, now, ovf_weekly, &tr->week_avg, &tr->week_hist, - WEEK_COUNT, WEEK_SAMPLE); + th->time, th->inrate, th->outrate); + overflow (th, tr, ovf_weekly, &tr->week_avg, &tr->week_hist, + WEEK_SAMPLE); verbose (2, _("end overflow_daily")); } void update_stats (struct monitor *mon, struct traffic_sample *sample, struct traffic_record *tr) @@ -147,15 +151,21 @@ update_stats (struct monitor *mon, struct traffic_sample *sample, interval = sample->time - tr->last.time; if (interval == 0) { logmsg (L_ERR, _("ignoring zero interval")); return; } + else if (interval < 0) + { + logmsg (L_ERR, _("ignoring negative interval")); + return; + } + inrate = (double) sample->in / interval; outrate = (double) sample->out / interval; - if (lastp) + if (lastp && interval < DAY_SAMPLE * cut_out_fraction) { interpolate (&tr->day_hist, DAY_SAMPLE, sample->time, tr->last.time, &tr->last_rates, @@ -164,19 +174,21 @@ update_stats (struct monitor *mon, struct traffic_sample *sample, ovf_daily, tr); } else { struct traffic_history th; interval = sample->time - tr->last.time; + th.time = sample->time; th.inrate = inrate; th.outrate = outrate; queue_put (&tr->day_hist, &th); } tr->last.time = sample->time; tr->last.in = sample->in; tr->last.out = sample->out; + tr->last_rates.time = sample->time; tr->last_rates.inrate = inrate; tr->last_rates.outrate = outrate; } @@ -235,20 +247,22 @@ _convert (queue_t *q, ovf_t ovf, ovf, tr); } else { struct traffic_history th; interval = hp->time - tr->last.time; + th.time = hp->time; th.inrate = inrate; th.outrate = outrate; queue_put (q, &th); } tr->last.time = hp->time; tr->last.in = hp->in; tr->last.out = hp->out; + tr->last_rates.time = hp->time; tr->last_rates.inrate = inrate; tr->last_rates.outrate = outrate; } } static void |