aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/graph.c14
-rw-r--r--src/grid.c30
-rw-r--r--src/output.c41
-rw-r--r--src/readconfig.c7
-rw-r--r--src/tagr.h10
5 files changed, 52 insertions, 50 deletions
diff --git a/src/graph.c b/src/graph.c
index 02e0586..80b2a97 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -89,7 +89,7 @@ draw_graph (FILE *fp,
89 int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1]; 89 int full_xsize = graph_xsize + graph_h_margin[0] + graph_h_margin[1];
90 int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; 90 int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1];
91 grid_t grid; 91 grid_t grid;
92 unsigned long ymax = mon->max_rate; 92 double ymax = mon->max_rate;
93 93
94 yscale = (double) graph_ysize / ymax; 94 yscale = (double) graph_ysize / ymax;
95 xscale = (double) graph_xsize / xmax; 95 xscale = (double) graph_xsize / xmax;
@@ -210,16 +210,16 @@ draw_graph (FILE *fp,
210 grid = grid_create (ygrid, dataq, 0, ymax, mon); 210 grid = grid_create (ygrid, dataq, 0, ymax, mon);
211 if (grid) 211 if (grid)
212 { 212 {
213 unsigned long i; 213 double d;
214 char *str = NULL; 214 char *str = NULL;
215 215
216 draw_vtext (graph, i_grid, 216 draw_vtext (graph, i_grid,
217 mon->rate_unit ? mon->rate_unit : rate_unit); 217 mon->rate_unit ? mon->rate_unit : rate_unit);
218 218
219 /* Draw vertical grid */ 219 /* Draw vertical grid */
220 while ((i = grid_next (grid, &str, NULL)) < ymax) 220 while ((d = grid_next (grid, &str, NULL)) < ymax)
221 { 221 {
222 int y = ytr (i); 222 int y = ytr (d);
223 223
224 /* Left tick */ 224 /* Left tick */
225 gdImageLine (graph, 225 gdImageLine (graph,
@@ -247,13 +247,13 @@ draw_graph (FILE *fp,
247 grid = grid_create (xgrid, dataq, 0, xmax, &start); 247 grid = grid_create (xgrid, dataq, 0, xmax, &start);
248 if (grid) 248 if (grid)
249 { 249 {
250 unsigned long i; 250 double d;
251 char *str = NULL; 251 char *str = NULL;
252 int mark; 252 int mark;
253 253
254 while ((i = grid_next (grid, &str, &mark)) < xmax) 254 while ((d = grid_next (grid, &str, &mark)) < xmax)
255 { 255 {
256 int x = xtr (i); 256 int x = xtr (d);
257 257
258 /* Tick */ 258 /* Tick */
259 gdImageLine (graph, 259 gdImageLine (graph,
diff --git a/src/grid.c b/src/grid.c
index 1671753..08e1c08 100644
--- a/src/grid.c
+++ b/src/grid.c
@@ -25,16 +25,16 @@ struct grid
25{ 25{
26 struct grid_class *class; 26 struct grid_class *class;
27 queue_t *q; 27 queue_t *q;
28 unsigned long vmin; 28 double vmin;
29 unsigned long vmax; 29 double vmax;
30 unsigned long cur; 30 double cur;
31 char *str; 31 char *str;
32 void *data; 32 void *data;
33}; 33};
34 34
35grid_t 35grid_t
36grid_create (struct grid_class *class, queue_t *q, 36grid_create (struct grid_class *class, queue_t *q,
37 unsigned long vmin, unsigned long vmax, void *cdata) 37 double vmin, double vmax, void *cdata)
38{ 38{
39 grid_t grid; 39 grid_t grid;
40 40
@@ -54,7 +54,7 @@ grid_create (struct grid_class *class, queue_t *q,
54 return grid; 54 return grid;
55} 55}
56 56
57unsigned long 57double
58grid_next (grid_t grid, char **str, int *mark) 58grid_next (grid_t grid, char **str, int *mark)
59{ 59{
60 return grid->class->next (grid, str, mark); 60 return grid->class->next (grid, str, mark);
@@ -87,7 +87,7 @@ size_t number_suffix_count = sizeof (short_suffix) / sizeof (short_suffix[0]);
87 87
88struct ygrid_data 88struct ygrid_data
89{ 89{
90 unsigned long step; 90 double step;
91}; 91};
92 92
93static void * 93static void *
@@ -99,7 +99,7 @@ ygrid_create (grid_t grid, void *cdata)
99 return gr; 99 return gr;
100} 100}
101 101
102static unsigned long 102static double
103ygrid_next (grid_t grid, char **str, int *mark) 103ygrid_next (grid_t grid, char **str, int *mark)
104{ 104{
105 struct ygrid_data *gr = grid->data; 105 struct ygrid_data *gr = grid->data;
@@ -154,11 +154,11 @@ xgrid_2h_create (grid_t grid, void *cdata)
154 return gr; 154 return gr;
155} 155}
156 156
157static unsigned long 157static double
158xgrid_2h_next (grid_t grid, char **str, int *mark) 158xgrid_2h_next (grid_t grid, char **str, int *mark)
159{ 159{
160 struct xgrid_data *gr = grid->data; 160 struct xgrid_data *gr = grid->data;
161 unsigned long ret = gr->off; 161 double ret = gr->off;
162 162
163 if (grid->str) 163 if (grid->str)
164 { 164 {
@@ -200,11 +200,11 @@ xgrid_wday_create (grid_t grid, void *cdata)
200 return gr; 200 return gr;
201} 201}
202 202
203static unsigned long 203static double
204xgrid_wday_next (grid_t grid, char **str, int *mark) 204xgrid_wday_next (grid_t grid, char **str, int *mark)
205{ 205{
206 struct xgrid_data *gr = grid->data; 206 struct xgrid_data *gr = grid->data;
207 unsigned long ret = gr->off; 207 double ret = gr->off;
208 char buf[80]; 208 char buf[80];
209 struct tm *tm = localtime (&gr->start); 209 struct tm *tm = localtime (&gr->start);
210 210
@@ -250,11 +250,11 @@ xgrid_week_create (grid_t grid, void *cdata)
250 return gr; 250 return gr;
251} 251}
252 252
253static unsigned long 253static double
254xgrid_week_next (grid_t grid, char **str, int *mark) 254xgrid_week_next (grid_t grid, char **str, int *mark)
255{ 255{
256 struct xgrid_data *gr = grid->data; 256 struct xgrid_data *gr = grid->data;
257 unsigned long ret = gr->off; 257 double ret = gr->off;
258 struct tm *tm = localtime (&gr->start); 258 struct tm *tm = localtime (&gr->start);
259 259
260 if (tm->tm_mday && tm->tm_mday < 7 && mark && gr->unit == 0) 260 if (tm->tm_mday && tm->tm_mday < 7 && mark && gr->unit == 0)
@@ -307,11 +307,11 @@ xgrid_month_create (grid_t grid, void *cdata)
307 return gr; 307 return gr;
308} 308}
309 309
310static unsigned long 310static double
311xgrid_month_next (grid_t grid, char **str, int *mark) 311xgrid_month_next (grid_t grid, char **str, int *mark)
312{ 312{
313 struct xgrid_data *gr = grid->data; 313 struct xgrid_data *gr = grid->data;
314 unsigned long ret = gr->off; 314 double ret = gr->off;
315 unsigned long frac; 315 unsigned long frac;
316 struct tm *tm = localtime (&gr->start); 316 struct tm *tm = localtime (&gr->start);
317 int mon; 317 int mon;
diff --git a/src/output.c b/src/output.c
index e2e8b92..3c266b7 100644
--- a/src/output.c
+++ b/src/output.c
@@ -114,29 +114,30 @@ add_stats (pp_tab_t **ptab, struct monitor *mon, queue_t *q,
114 int i, n = queue_count (q); 114 int i, n = queue_count (q);
115 struct traffic_history *tptr, th; 115 struct traffic_history *tptr, th;
116 116
117 if (!n) 117 if (n)
118 return;
119 for (i = 0; i < n; i++)
120 { 118 {
121 tptr = queue_get_ptr (q, i); 119 for (i = 0; i < n; i++)
122 scale_sample (mon, tptr, &th); 120 {
121 tptr = queue_get_ptr (q, i);
122 scale_sample (mon, tptr, &th);
123
124 val[avgin_name] += th.inrate;
125 if (th.inrate > val[maxin_name])
126 val[maxin_name] = th.inrate;
127
128 val[avgout_name] += th.outrate;
129 if (th.outrate > val[maxout_name])
130 val[maxout_name] = th.outrate;
131 }
132 val[avgin_name] /= n;
133 val[avgout_name] /= n;
123 134
124 val[avgin_name] += th.inrate; 135 tptr = queue_get_tail (q);
125 if (th.inrate > val[maxin_name]) 136 scale_sample (mon, tptr, &th);
126 val[maxin_name] = th.inrate; 137 val[curin_name] = th.inrate;
127 138 val[curout_name] = th.outrate;
128 val[avgout_name] += th.outrate;
129 if (th.outrate > val[maxout_name])
130 val[maxout_name] = th.outrate;
131 } 139 }
132 val[avgin_name] /= n; 140
133 val[avgout_name] /= n;
134
135 tptr = queue_get_tail (q);
136 scale_sample (mon, tptr, &th);
137 val[curin_name] = th.inrate;
138 val[curout_name] = th.outrate;
139
140 for (i = 0; i < sizeof (val) / sizeof (val[0]); i++) 141 for (i = 0; i < sizeof (val) / sizeof (val[0]); i++)
141 add_numeric_value (ptab, symname[i], val[i]); 142 add_numeric_value (ptab, symname[i], val[i]);
142} 143}
diff --git a/src/readconfig.c b/src/readconfig.c
index a514691..1c22cb1 100644
--- a/src/readconfig.c
+++ b/src/readconfig.c
@@ -100,7 +100,7 @@ cb_monitor (enum grecs_callback_command cmd,
100 mon = xzalloc (sizeof (*mon)); 100 mon = xzalloc (sizeof (*mon));
101 mon->id = strdup (value->v.string); 101