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 | |
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.
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | src/graph.c | 46 | ||||
-rw-r--r-- | src/output.c | 3 | ||||
-rw-r--r-- | src/readconfig.c | 16 | ||||
-rw-r--r-- | src/report.c | 23 | ||||
-rw-r--r-- | src/stat.c | 64 | ||||
-rw-r--r-- | src/tagr.h | 8 |
7 files changed, 113 insertions, 52 deletions
@@ -11,5 +11,6 @@ S: +OK bye -* Zero-unknown option and interrupted data feeds +* Drawing interrupted data feeds -Decide what to do if a data feed gets interrupted. +What to do if zero-inknown is set to `false'? Currently, linear +interpolation is performed. diff --git a/src/graph.c b/src/graph.c index 8088773..1197a7d 100644 --- a/src/graph.c +++ b/src/graph.c @@ -92,2 +92,3 @@ draw_graph (FILE *fp, unsigned long ymax = mon->max_rate; + time_t start; @@ -144,3 +145,3 @@ draw_graph (FILE *fp, /* Incoming traffic */ - for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) + for (i = n - 1, start = 0; i > 0; i--) { @@ -149,9 +150,22 @@ draw_graph (FILE *fp, scale_sample (mon, queue_get_ptr (dataq, i), &th); + if (start == 0) + start = th.time; scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); + if (start - tnext.time > xmax) + break; + if (zero_unknown_option + && th.time - tnext.time > xstep * cut_out_fraction) + { + gdImageLine (graph, xtr (start - tnext.time), ytr (0), + xtr (start - tnext.time), ytr (tnext.inrate), i_in); + th.inrate = tnext.inrate = 0; + th.outrate = tnext.outrate = 0; + } + if (fill_incoming_option) gdImageLine (graph, - xtr (x), ytr (0), - xtr (x), ytr (tnext.inrate), i_in); - gdImageLine (graph, xtr (x), ytr (th.inrate), - xtr (x + xstep), ytr (tnext.inrate), i_in); + xtr (start - th.time), ytr (0), + xtr (start - th.time), ytr (tnext.inrate), i_in); + gdImageLine (graph, xtr (start - th.time), ytr (th.inrate), + xtr (start - tnext.time), ytr (tnext.inrate), i_in); } @@ -160,3 +174,3 @@ draw_graph (FILE *fp, gdImageSetBrush (graph, brush_out); - for (i = n - 1, x = 0; i > 0 && x < xmax; i--, x += xstep) + for (i = n - 1, start = 0; i > 0; i--) { @@ -165,6 +179,20 @@ draw_graph (FILE *fp, scale_sample (mon, queue_get_ptr (dataq, i), &th); + if (start == 0) + start = th.time; scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); + if (start - tnext.time > xmax) + break; - gdImageLine (graph, xtr (x), ytr (th.outrate), - xtr (x + xstep), ytr (tnext.outrate), gdBrushed); + if (zero_unknown_option + && th.time - tnext.time > xstep * cut_out_fraction) + { + gdImageLine (graph, xtr (start - tnext.time), ytr (0), + xtr (start - tnext.time), ytr (tnext.inrate), + gdBrushed); + th.inrate = tnext.inrate = 0; + th.outrate = tnext.outrate = 0; + } + + gdImageLine (graph, xtr (start - th.time), ytr (th.outrate), + xtr (start - tnext.time), ytr (tnext.outrate), gdBrushed); } @@ -175,3 +203,3 @@ draw_graph (FILE *fp, xtr (xmax), ytr (ymax), i_grid); - + diff --git a/src/output.c b/src/output.c index e376ad4..4b6e206 100644 --- a/src/output.c +++ b/src/output.c @@ -43,2 +43,3 @@ scale_sample (struct monitor *mon, } + out->time = in->time; out->inrate *= mon->scale; @@ -232,3 +233,3 @@ format_timestamp (FILE *fp, union value v, const char *fmt, int prec) - fprintftime(fp, fmt, tm, 0, 0); + fprintftime (fp, fmt, tm, 0, 0); } diff --git a/src/readconfig.c b/src/readconfig.c index 9eff4c7..e75cae4 100644 --- a/src/readconfig.c +++ b/src/readconfig.c @@ -91,6 +91,8 @@ cb_monitor (enum grecs_callback_command cmd, case grecs_callback_section_begin: - if (!value || value->type != GCONF_TYPE_STRING) + if (!value + || value->type != GCONF_TYPE_STRING + || value->v.string == NULL) { grecs_error (locus, 0, _("tag must be a string")); - return 0; + return 1; } @@ -401,6 +403,7 @@ cb_server (enum grecs_callback_command cmd, case grecs_callback_section_begin: - if (!value || value->type != GCONF_TYPE_STRING) + if (!value || value->type != GCONF_TYPE_STRING + || !value->v.string) { grecs_error (locus, 0, _("tag must be a string")); - return 0; + return 1; } @@ -484,2 +487,5 @@ static struct grecs_keyword tagr_kw[] = { grecs_type_bool, &zero_unknown_option }, + { "cut-out-fraction", N_("arg: double"), NULL, /* FIXME */ + grecs_type_string, &cut_out_fraction, 0, + cb_double }, { "fill-incoming", NULL, N_("Fill incoming graph"), @@ -549,2 +555,4 @@ readconfig () mon_base = obstack_finish (&mon_stack); + if (cut_out_fraction < 1.0) + cut_out_fraction = TAGR_CUT_OUT; return rc; diff --git a/src/report.c b/src/report.c index 398881b..71a735f 100644 --- a/src/report.c +++ b/src/report.c @@ -32,2 +32,3 @@ #include <report.h> +#include <fprintftime.h> #include <gdbm.h> @@ -146,2 +147,10 @@ write_db (struct monitor *mon, struct traffic_record *tr) static void +print_time (FILE *fp, time_t time) +{ + fprintf (fp, "%lu [", (unsigned long) time); + fprintftime (fp, "%Y-%m-%d %H:%M:%S %z", localtime (&time), 0, 0); + fprintf (fp, "]"); +} + +static void print_queue (const char *title, queue_t *q) @@ -157,3 +166,5 @@ print_queue (const char *title, queue_t *q) struct traffic_history *th = queue_get_ptr (q, i); - printf("%d %g %g\n", count - i, th->inrate, th->outrate); + printf ("%d ", count - i); + print_time (stdout, th->time); + printf (" %g %g\n", th->inrate, th->outrate); } @@ -174,11 +185,9 @@ print_tr (datum key, struct traffic_record *tr) { - char buf[512]; - struct tm *tm; int i, count; - tm = localtime (&tr->last.time); printf ("ID: %*.*s\n", key.dsize, key.dsize, key.dptr); - strftime (buf, sizeof buf, "%c", tm); - printf (_("Last sample: %lu (%s) %lu %lu\n"), - tr->last.time, buf, tr->last.in, tr->last.out); + + printf (_("Last sample: ")); + print_time (stdout, tr->last.time); + printf (" %lu %lu\n", tr->last.in, tr->last.out); @@ -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; @@ -27,2 +27,3 @@ #define TAGR_DBMODE 0600 +#define TAGR_CUT_OUT 1.5 @@ -50,2 +51,3 @@ extern unsigned update_interval; extern int single_process_option; +extern double cut_out_fraction; @@ -78,5 +80,2 @@ extern size_t number_suffix_count; -void assign_string (char **pstr, const char *s); -void assign_string_n (char **pstr, const char *s, size_t length); - int readconfig (void); @@ -84,3 +83,3 @@ void config_help (void); void define_symbol (char *s); -void decode_buffer (); + struct monitor *find_monitor (const char *name); @@ -168,2 +167,3 @@ struct traffic_history { + time_t time; double inrate; |