diff options
-rw-r--r-- | src/graph.c | 51 | ||||
-rw-r--r-- | src/grid.c | 3 | ||||
-rw-r--r-- | src/readconfig.c | 18 | ||||
-rw-r--r-- | src/tagr.h | 20 |
4 files changed, 72 insertions, 20 deletions
diff --git a/src/graph.c b/src/graph.c index 80b2a97..89f02a1 100644 --- a/src/graph.c +++ b/src/graph.c @@ -56,4 +56,14 @@ int graph_v_margin[2] = { 14, 35 }; -/* FIXME: I18N?? */ -char *rate_unit = "Bytes per Second"; +struct monitor default_monitor = { + NULL, + NULL, + NULL, + "Bytes per Second", /* rate_unit, FIXME: I18N?? */ + 0, /* max_rate */ + 0, /* max_adjust */ + 1.0, /* scale */ + 0.1, /* ystep */ + 0, /* ystep_absolute */ + 0 /* swap */ +}; @@ -72,2 +82,20 @@ draw_vtext (gdImagePtr graph, int color, const char *text) +static double +find_max (queue_t *dataq) +{ + int i, n = queue_count (dataq); + double mval = 0; + struct traffic_history *th; + + for (i = 0; i < n; i++) + { + th = queue_get_ptr (dataq, i); + if (mval < th->inrate) + mval = th->inrate; + if (mval < th->outrate) + mval = th->outrate; + } + return mval; +} + int @@ -91,3 +119,15 @@ draw_graph (FILE *fp, grid_t grid; - double ymax = mon->max_rate; + double ymax; + + if (mon->max_adjust) + { + double amax = find_max (dataq); + if (amax > mon->max_rate) + { + unsigned long n = (amax - mon->max_rate + mon->max_adjust - 1) / + mon->max_adjust; + mon->max_rate += n * mon->max_adjust; + } + } + ymax = mon->max_rate; @@ -97,3 +137,3 @@ draw_graph (FILE *fp, #define ytr(y) \ - (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \ + (unsigned long) ((ymax >= (y) ? (ymax - (y)) : 0) * \ yscale + graph_h_margin[1]) @@ -215,4 +255,3 @@ draw_graph (FILE *fp, - draw_vtext (graph, i_grid, - mon->rate_unit ? mon->rate_unit : rate_unit); + draw_vtext (graph, i_grid, mon->rate_unit); @@ -97,3 +97,6 @@ ygrid_create (grid_t grid, void *cdata) struct ygrid_data *gr = xmalloc (sizeof (*gr)); + if (mon->ystep_absolute) gr->step = mon->ystep; + else + gr->step = mon->ystep * mon->max_rate; return gr; diff --git a/src/readconfig.c b/src/readconfig.c index 1c22cb1..a60f19d 100644 --- a/src/readconfig.c +++ b/src/readconfig.c @@ -100,5 +100,6 @@ cb_monitor (enum grecs_callback_command cmd, mon = xzalloc (sizeof (*mon)); + *mon = default_monitor; mon->id = strdup (value->v.string); - mon->scale = 1.0; - mon->ystep = 100.; + mon->name = NULL; + mon->dir = NULL; *pdata = mon; @@ -108,3 +109,7 @@ cb_monitor (enum grecs_callback_command cmd, mon = *pdata; - if (mon->max_rate == 0) + if (strcmp (mon->id, "default") == 0) + default_monitor = *mon; + else + { + if (mon->max_rate == 0 && mon->max_adjust == 0) { @@ -123,2 +128,3 @@ cb_monitor (enum grecs_callback_command cmd, mon_count++; + } free (mon); @@ -176,2 +182,4 @@ static struct grecs_keyword monitor_kw[] = { grecs_type_ulong, NULL, offsetof(struct monitor, max_rate) }, + { "max-adjust", NULL, N_("Adjust maximum by this value when needed"), + grecs_type_ulong, NULL, offsetof(struct monitor, max_adjust) }, { "rate-units", NULL, N_("Name of rate units"), @@ -184,2 +192,4 @@ static struct grecs_keyword monitor_kw[] = { cb_double}, + { "y-step-absolute", NULL, N_("y-step is an absolute value"), + grecs_type_bool, NULL, offsetof(struct monitor, ystep_absolute) }, { "swap", NULL, N_("Swap in and out rates"), @@ -490,4 +500,2 @@ static struct grecs_keyword tagr_kw[] = { - { "rate-units", NULL, N_("Name of rate units"), - grecs_type_string, &rate_unit }, { "number-suffixes", N_("suffixes"), @@ -45,10 +45,12 @@ struct monitor { - char *id; - char *name; - char *dir; - char *rate_unit; - unsigned long max_rate; - double scale; - double ystep; - int swap; + char *id; /* Monitor ID */ + char *name; /* Full name */ + char *dir; /* Output directory */ + char *rate_unit; /* Rate units */ + unsigned long max_rate; /* Max. rate value */ + unsigned long max_adjust; /* Adjustment for max. rate */ + double scale; /* Y (rate) scale */ + double ystep; /* Step of Y grid, in fractions of max_rate */ + int ystep_absolute; /* When true, ystep is an absolute value */ + int swap; /* Swap input and output rates */ }; @@ -77,4 +79,4 @@ extern int html_input_line; extern int verbose_level; -extern char *rate_unit; +extern struct monitor default_monitor; extern int percent_option; |