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
@@ -29,4 +29,5 @@ -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); @@ -45,2 +46,3 @@ interpolate (queue_t *q, { + th.time = now; th.inrate = inrate; @@ -50,3 +52,3 @@ interpolate (queue_t *q, if (ovf) - ovf (&th, tr, now); + ovf (&th, tr); return; @@ -56,2 +58,3 @@ interpolate (queue_t *q, { + th.time = next; th.inrate = (inrate - last_rates->inrate) * (next - last_time) @@ -63,3 +66,3 @@ interpolate (queue_t *q, if (ovf) - ovf (&th, tr, now); + ovf (&th, tr); } @@ -70,3 +73,2 @@ overflow (struct traffic_history *th, struct traffic_record *tr, - time_t now, ovf_t ovf, @@ -74,15 +76,15 @@ overflow (struct traffic_history *th, 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, @@ -92,5 +94,7 @@ overflow (struct traffic_history *th, 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); @@ -100,3 +104,3 @@ overflow (struct traffic_history *th, avg->count = 0; - avg->time = now; + avg->time = th->time; } @@ -108,8 +112,8 @@ overflow (struct traffic_history *th, 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")); @@ -118,8 +122,8 @@ ovf_monthly (struct traffic_history *th, struct traffic_record *tr, time_t now) 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")); @@ -128,8 +132,8 @@ ovf_weekly (struct traffic_history *th, struct traffic_record *tr, time_t now) 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")); @@ -152,5 +156,11 @@ update_stats (struct monitor *mon, struct traffic_sample *sample, } + 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) { @@ -169,2 +179,3 @@ update_stats (struct monitor *mon, struct traffic_sample *sample, interval = sample->time - tr->last.time; + th.time = sample->time; th.inrate = inrate; @@ -176,2 +187,3 @@ update_stats (struct monitor *mon, struct traffic_sample *sample, tr->last.out = sample->out; + tr->last_rates.time = sample->time; tr->last_rates.inrate = inrate; @@ -240,2 +252,3 @@ _convert (queue_t *q, ovf_t ovf, interval = hp->time - tr->last.time; + th.time = hp->time; th.inrate = inrate; @@ -248,2 +261,3 @@ _convert (queue_t *q, ovf_t ovf, tr->last.out = hp->out; + tr->last_rates.time = hp->time; tr->last_rates.inrate = inrate; |