summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/graph.c51
-rw-r--r--src/grid.c5
-rw-r--r--src/readconfig.c42
-rw-r--r--src/tagr.h20
4 files changed, 85 insertions, 33 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 };
56 56
57/* FIXME: I18N?? */ 57struct monitor default_monitor = {
58char *rate_unit = "Bytes per Second"; 58 NULL,
59 NULL,
60 NULL,
61 "Bytes per Second", /* rate_unit, FIXME: I18N?? */
62 0, /* max_rate */
63 0, /* max_adjust */
64 1.0, /* scale */
65 0.1, /* ystep */
66 0, /* ystep_absolute */
67 0 /* swap */
68};
59 69
@@ -72,2 +82,20 @@ draw_vtext (gdImagePtr graph, int color, const char *text)
72 82
83static double
84find_max (queue_t *dataq)
85{
86 int i, n = queue_count (dataq);
87 double mval = 0;
88 struct traffic_history *th;
89
90 for (i = 0; i < n; i++)
91 {
92 th = queue_get_ptr (dataq, i);
93 if (mval < th->inrate)
94 mval = th->inrate;
95 if (mval < th->outrate)
96 mval = th->outrate;
97 }
98 return mval;
99}
100
73int 101int
@@ -91,3 +119,15 @@ draw_graph (FILE *fp,
91 grid_t grid; 119 grid_t grid;
92 double ymax = mon->max_rate; 120 double ymax;
121
122 if (mon->max_adjust)
123 {
124 double amax = find_max (dataq);
125 if (amax > mon->max_rate)
126 {
127 unsigned long n = (amax - mon->max_rate + mon->max_adjust - 1) /
128 mon->max_adjust;
129 mon->max_rate += n * mon->max_adjust;
130 }
131 }
132 ymax = mon->max_rate;
93 133
@@ -97,3 +137,3 @@ draw_graph (FILE *fp,
97 #define ytr(y) \ 137 #define ytr(y) \
98 (unsigned long) ((ymax >= (y) ? (ymax - (y)) : ymax) * \ 138 (unsigned long) ((ymax >= (y) ? (ymax - (y)) : 0) * \
99 yscale + graph_h_margin[1]) 139 yscale + graph_h_margin[1])
@@ -215,4 +255,3 @@ draw_graph (FILE *fp,
215 255
216 draw_vtext (graph, i_grid, 256 draw_vtext (graph, i_grid, mon->rate_unit);
217 mon->rate_unit ? mon->rate_unit : rate_unit);
218 257
diff --git a/src/grid.c b/src/grid.c
index 08e1c08..4ecb576 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -97,3 +97,6 @@ ygrid_create (grid_t grid, void *cdata)
97 struct ygrid_data *gr = xmalloc (sizeof (*gr)); 97 struct ygrid_data *gr = xmalloc (sizeof (*gr));
98 gr->step = mon->ystep; 98 if (mon->ystep_absolute)
99 gr->step = mon->ystep;
100 else
101 gr->step = mon->ystep * mon->max_rate;
99 return gr; 102 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,
100 mon = xzalloc (sizeof (*mon)); 100 mon = xzalloc (sizeof (*mon));
101 *mon = default_monitor;
101 mon->id = strdup (value->v.string); 102 mon->id = strdup (value->v.string);
102 mon->scale = 1.0; 103 mon->name = NULL;
103 mon->ystep = 100.; 104 mon->dir = NULL;
104 *pdata = mon; 105 *pdata = mon;
@@ -108,17 +109,22 @@ cb_monitor (enum grecs_callback_command cmd,
108 mon = *pdata; 109 mon = *pdata;
109 if (mon->max_rate == 0) 110 if (strcmp (mon->id, "default") == 0)
111 default_monitor = *mon;
112 else
110 { 113 {
111 grecs_error (locus, 0, _("maximum speed not set")); 114 if (mon->max_rate == 0 && mon->max_adjust == 0)
112 free (mon); 115 {
113 return 0; 116 grecs_error (locus, 0, _("maximum speed not set"));
117 free (mon);
118 return 0;
119 }
120 if (!mon->name)
121 mon->name = strdup (mon->id);
122 if (!mon->dir)
123 mon->dir = strdup (mon->id);
124 if (mon_count == 0)
125 obstack_init (&mon_stack);
126
127 obstack_grow (&mon_stack, mon, sizeof *mon);
128 mon_count++;
114 } 129 }
115 if (!mon->name)
116 mon->name = strdup (mon->id);
117 if (!mon->dir)
118 mon->dir = strdup (mon->id);
119 if (mon_count == 0)
120 obstack_init (&mon_stack);
121
122 obstack_grow (&mon_stack, mon, sizeof *mon);
123 mon_count++;
124 free (mon); 130 free (mon);
@@ -176,2 +182,4 @@ static struct grecs_keyword monitor_kw[] = {
176 grecs_type_ulong, NULL, offsetof(struct monitor, max_rate) }, 182 grecs_type_ulong, NULL, offsetof(struct monitor, max_rate) },
183 { "max-adjust", NULL, N_("Adjust maximum by this value when needed"),
184 grecs_type_ulong, NULL, offsetof(struct monitor, max_adjust) },
177 { "rate-units", NULL, N_("Name of rate units"), 185 { "rate-units", NULL, N_("Name of rate units"),
@@ -184,2 +192,4 @@ static struct grecs_keyword monitor_kw[] = {
184 cb_double}, 192 cb_double},
193 { "y-step-absolute", NULL, N_("y-step is an absolute value"),
194 grecs_type_bool, NULL, offsetof(struct monitor, ystep_absolute) },
185 { "swap", NULL, N_("Swap in and out rates"), 195 { "swap", NULL, N_("Swap in and out rates"),
@@ -490,4 +500,2 @@ static struct grecs_keyword tagr_kw[] = {
490 500
491 { "rate-units", NULL, N_("Name of rate units"),
492 grecs_type_string, &rate_unit },
493 { "number-suffixes", N_("suffixes"), 501 { "number-suffixes", N_("suffixes"),
diff --git a/src/tagr.h b/src/tagr.h
index 5d7c3e0..6ed7ca2 100644
--- a/src/tagr.h
+++ b/src/tagr.h
@@ -45,10 +45,12 @@ struct monitor
45{ 45{
46 char *id; 46 char *id; /* Monitor ID */
47 char *name; 47 char *name; /* Full name */
48 char *dir; 48 char *dir; /* Output directory */
49 char *rate_unit; 49 char *rate_unit; /* Rate units */
50 unsigned long max_rate; 50 unsigned long max_rate; /* Max. rate value */
51 double scale; 51 unsigned long max_adjust; /* Adjustment for max. rate */
52 double ystep; 52 double scale; /* Y (rate) scale */
53 int swap; 53 double ystep; /* Step of Y grid, in fractions of max_rate */
54 int ystep_absolute; /* When true, ystep is an absolute value */
55 int swap; /* Swap input and output rates */
54}; 56};
@@ -77,4 +79,4 @@ extern int html_input_line;
77extern int verbose_level; 79extern int verbose_level;
78extern char *rate_unit;
79 80
81extern struct monitor default_monitor;
80extern int percent_option; 82extern int percent_option;

Return to:

Send suggestions and report system problems to the System administrator.