aboutsummaryrefslogtreecommitdiff
path: root/src/stat.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-25 10:44:14 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-04-25 10:44:14 +0300
commitd8c782807ffbd0e7e30b07f88dd91b6dc0988219 (patch)
tree64cdbde6fc4f6ae6f3c2c0564cd1fc57d5de9088 /src/stat.c
parentcedb36dcc43d5cb89a0b4af0e7eeeddb02401595 (diff)
downloadtagr-d8c782807ffbd0e7e30b07f88dd91b6dc0988219.tar.gz
tagr-d8c782807ffbd0e7e30b07f88dd91b6dc0988219.tar.bz2
Normalize terminology.
* etc/upgrade.awk: Translate "router" to "monitor". Divide max rate by 8. * src/graph.c (rate_unit): New global. (draw_graph): Take monitor as an argument. Make rate units configurable. * src/readconfig.c (find_router, find_router_id): Rename to find_monitor, find_monitor_id. Rename "router" section to "monitor". New statement "rate-units", allowed both at top level and within a monitor. * src/tagr.h (HostData): Rename to monitor. Add new field: rate_unit. Rename `max' to `max_rate'. Remove t, in, out. (rate_unit): New declaration. (find_router, find_router_id): Rename to find_monitor, find_monitor_id. (struct last_sample): Rename to struct traffic_sample. * src/output.c, src/report.c, src/stat.c: Update
Diffstat (limited to 'src/stat.c')
-rw-r--r--src/stat.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/stat.c b/src/stat.c
index d196ead..3b8fb96 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -133,26 +133,27 @@ ovf_daily (struct traffic_history *th, struct traffic_record *tr, time_t now)
133} 133}
134 134
135void 135void
136update_stats (SD *sd, struct traffic_record *tr) 136update_stats (struct monitor *mon, struct traffic_sample *sample,
137 struct traffic_record *tr)
137{ 138{
138 time_t interval; 139 time_t interval;
139 double inrate, outrate; 140 double inrate, outrate;
140 141
141 struct traffic_history *lastp = queue_get_tail (&tr->day_hist); 142 struct traffic_history *lastp = queue_get_tail (&tr->day_hist);
142 143
143 interval = sd->t - tr->last.time; 144 interval = sample->time - tr->last.time;
144 if (interval == 0) 145 if (interval == 0)
145 { 146 {
146 logmsg (L_ERR, "Ignoring zero interval"); 147 logmsg (L_ERR, "Ignoring zero interval");
147 return; 148 return;
148 } 149 }
149 inrate = (double) sd->in / interval; 150 inrate = (double) sample->in / interval;
150 outrate = (double) sd->out / interval; 151 outrate = (double) sample->out / interval;
151 if (lastp) 152 if (lastp)
152 { 153 {
153 interpolate (&tr->day_hist, 154 interpolate (&tr->day_hist,
154 DAY_SAMPLE, 155 DAY_SAMPLE,
155 sd->t, 156 sample->time,
156 tr->last.time, 157 tr->last.time,
157 &tr->last_rates, 158 &tr->last_rates,
158 interval, 159 interval,
@@ -162,14 +163,14 @@ update_stats (SD *sd, struct traffic_record *tr)
162 else 163 else
163 { 164 {
164 struct traffic_history th; 165 struct traffic_history th;
165 interval = sd->t - tr->last.time; 166 interval = sample->time - tr->last.time;
166 th.inrate = inrate; 167 th.inrate = inrate;
167 th.outrate = outrate; 168 th.outrate = outrate;
168 queue_put (&tr->day_hist, &th); 169 queue_put (&tr->day_hist, &th);
169 } 170 }
170 tr->last.time = sd->t; 171 tr->last.time = sample->time;
171 tr->last.in = sd->in; 172 tr->last.in = sample->in;
172 tr->last.out = sd->out; 173 tr->last.out = sample->out;
173 tr->last_rates.inrate = inrate; 174 tr->last_rates.inrate = inrate;
174 tr->last_rates.outrate = outrate; 175 tr->last_rates.outrate = outrate;
175} 176}
@@ -178,7 +179,7 @@ update_stats (SD *sd, struct traffic_record *tr)
178 179
179 180
180static void 181static void
181compute_avg (struct avg_acc *avg, queue_t *q, struct last_sample *last) 182compute_avg (struct avg_acc *avg, queue_t *q, struct traffic_sample *last)
182{ 183{
183 int i, n = queue_count (q); 184 int i, n = queue_count (q);
184 avg->inrate = avg->outrate = 0; 185 avg->inrate = avg->outrate = 0;
@@ -195,15 +196,13 @@ compute_avg (struct avg_acc *avg, queue_t *q, struct last_sample *last)
195 avg->time = last->time; 196 avg->time = last->time;
196} 197}
197 198
198#define hist_rec last_sample
199
200static void 199static void
201_convert (queue_t *q, ovf_t ovf, 200_convert (queue_t *q, ovf_t ovf,
202 struct traffic_record *tr, struct hist_rec *hist, size_t count, 201 struct traffic_record *tr, struct traffic_sample *hist, size_t count,
203 time_t sample_interval) 202 time_t sample_interval)
204{ 203{
205 size_t i; 204 size_t i;
206 struct hist_rec *hp; 205 struct traffic_sample *hp;
207 206
208 tr->last.time = hist[count-1].time - sample_interval; 207 tr->last.time = hist[count-1].time - sample_interval;
209 for (hp = hist + count - 1; hp >= hist; hp--) 208 for (hp = hist + count - 1; hp >= hist; hp--)
@@ -250,7 +249,8 @@ _convert (queue_t *q, ovf_t ovf,
250} 249}
251 250
252static void 251static void
253convert_yearly (struct traffic_record *tr, struct hist_rec *hp, size_t count) 252convert_yearly (struct traffic_record *tr, struct traffic_sample *hp,
253 size_t count)
254{ 254{
255 verbose (2, "begin convert_yearly"); 255 verbose (2, "begin convert_yearly");
256 _convert (&tr->year_hist, NULL, tr, 256 _convert (&tr->year_hist, NULL, tr,
@@ -260,7 +260,8 @@ convert_yearly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
260} 260}
261 261
262static void 262static void
263convert_monthly (struct traffic_record *tr, struct hist_rec *hp, size_t count) 263convert_monthly (struct traffic_record *tr, struct traffic_sample *hp,
264 size_t count)
264{ 265{
265 verbose (2, "begin convert_monthly"); 266 verbose (2, "begin convert_monthly");
266 if (count > MONTH_COUNT+1) 267 if (count > MONTH_COUNT+1)
@@ -272,7 +273,7 @@ convert_monthly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
272} 273}
273 274
274static void 275static void
275convert_weekly (struct traffic_record *tr, struct hist_rec *hp, size_t count) 276convert_weekly (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
276{ 277{
277 verbose (2, "begin convert_weekly"); 278 verbose (2, "begin convert_weekly");
278 if (count > WEEK_COUNT+1) 279 if (count > WEEK_COUNT+1)
@@ -284,7 +285,7 @@ convert_weekly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
284} 285}
285 286
286static void 287static void
287convert_daily (struct traffic_record *tr, struct hist_rec *hp, size_t count) 288convert_daily (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
288{ 289{
289 verbose (2, "begin convert_daily"); 290 verbose (2, "begin convert_daily");
290 if (count > DAY_COUNT+1) 291 if (count > DAY_COUNT+1)
@@ -294,8 +295,8 @@ convert_daily (struct traffic_record *tr, struct hist_rec *hp, size_t count)
294} 295}
295 296
296static void 297static void
297convert_stats (SD *sd, struct hist_rec *last, 298convert_stats (struct monitor *mon, struct traffic_sample *last,
298 struct hist_rec *hp, size_t count) 299 struct traffic_sample *hp, size_t count)
299{ 300{
300 struct traffic_record *trp, tr; 301 struct traffic_record *trp, tr;
301 302
@@ -304,10 +305,10 @@ convert_stats (SD *sd, struct hist_rec *last,
304 305
305 convert_daily (&tr, hp, count); 306 convert_daily (&tr, hp, count);
306 307
307 read_db (sd, &trp); 308 read_db (mon, &trp);
308 *trp = tr; 309 *trp = tr;
309 trp->last = *last; 310 trp->last = *last;
310 write_db (sd, trp); 311 write_db (mon, trp);
311 free (trp); 312 free (trp);
312} 313}
313 314
@@ -317,7 +318,7 @@ import_log (const char *name)
317 FILE *fp; 318 FILE *fp;
318 int rc = 0; 319 int rc = 0;
319 struct obstack stk; 320 struct obstack stk;
320 struct hist_rec last, hist, *hp; 321 struct traffic_sample last, hist, *hp;
321 unsigned long inmax, outmax; 322 unsigned long inmax, outmax;
322 size_t count = 0; 323 size_t count = 0;
323 char *buf = NULL; 324 char *buf = NULL;
@@ -387,7 +388,7 @@ import_log (const char *name)
387 hp = obstack_finish (&stk); 388 hp = obstack_finish (&stk);
388 if (count) 389 if (count)
389 { 390 {
390 SD *sd; 391 struct monitor *mon;
391 392
392 char *p = strrchr (name, '/'); 393 char *p = strrchr (name, '/');
393 char *base = xstrdup (p ? p + 1 : name); 394 char *base = xstrdup (p ? p + 1 : name);
@@ -395,14 +396,14 @@ import_log (const char *name)
395 if (p) 396 if (p)
396 *p = 0; 397 *p = 0;
397 398
398 sd = find_router (base); 399 mon = find_monitor (base);
399 if (!sd) 400 if (!mon)
400 { 401 {
401 logmsg (L_ERR, "cannot find router `%s'", base); 402 logmsg (L_ERR, "cannot find monitor `%s'", base);
402 rc = 1; 403 rc = 1;
403 } 404 }
404 else 405 else
405 convert_stats (sd, &last, hp, count); 406 convert_stats (mon, &last, hp, count);
406 } 407 }
407 408
408 obstack_free (&stk, NULL); 409 obstack_free (&stk, NULL);

Return to:

Send suggestions and report system problems to the System administrator.