summaryrefslogtreecommitdiffabout
path: root/src/stat.c
Unidiff
Diffstat (limited to 'src/stat.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/stat.c65
1 files changed, 35 insertions, 30 deletions
diff --git a/src/stat.c b/src/stat.c
index ed4ab8e..85b76d9 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -45,7 +45,7 @@ interpolate (queue_t *q,
45 { 45 {
46 th.inrate = inrate; 46 th.inrate = inrate;
47 th.outrate = outrate; 47 th.outrate = outrate;
48 verbose (3, "Insert %lu %g %g", next, th.inrate, th.outrate); 48 verbose (3, _("insert %lu %g %g"), next, th.inrate, th.outrate);
49 queue_put (q, &th); 49 queue_put (q, &th);
50 if (ovf) 50 if (ovf)
51 ovf (&th, tr, now); 51 ovf (&th, tr, now);
@@ -58,7 +58,7 @@ interpolate (queue_t *q,
58 / interval + last_rates->inrate; 58 / interval + last_rates->inrate;
59 th.outrate = (outrate - last_rates->outrate) * (next - last_time) 59 th.outrate = (outrate - last_rates->outrate) * (next - last_time)
60 / interval + last_rates->outrate; 60 / interval + last_rates->outrate;
61 verbose (3, "Insert %lu %g %g", next, th.inrate, th.outrate); 61 verbose (3, _("insert %lu %g %g"), next, th.inrate, th.outrate);
62 queue_put (q, &th); 62 queue_put (q, &th);
63 if (ovf) 63 if (ovf)
64 ovf (&th, tr, now); 64 ovf (&th, tr, now);
@@ -92,7 +92,7 @@ overflow (struct traffic_history *th,
92 struct traffic_history tmp; 92 struct traffic_history tmp;
93 tmp.inrate = avg->inrate; 93 tmp.inrate = avg->inrate;
94 tmp.outrate = avg->outrate; 94 tmp.outrate = avg->outrate;
95 verbose (3, "Insert %lu %g %g", now, tmp.inrate, tmp.outrate); 95 verbose (3, _("insert %lu %g %g"), now, tmp.inrate, tmp.outrate);
96 queue_put (q, &tmp); 96 queue_put (q, &tmp);
97 } 97 }
98 98
@@ -108,28 +108,31 @@ overflow (struct traffic_history *th,
108int 108int
109ovf_monthly (struct traffic_history *th, struct traffic_record *tr, time_t now) 109ovf_monthly (struct traffic_history *th, struct traffic_record *tr, time_t now)
110{ 110{
111 verbose (2, "begin overflow_monthly %lu %g %g", now, th->inrate, th->outrate); 111 verbose (2, _("begin overflow_monthly %lu %g %g"),
112 now, th->inrate, th->outrate);
112 overflow (th, tr, now, NULL, &tr->year_avg, &tr->year_hist, 113 overflow (th, tr, now, NULL, &tr->year_avg, &tr->year_hist,
113 YEAR_COUNT, YEAR_SAMPLE); 114 YEAR_COUNT, YEAR_SAMPLE);
114 verbose (2, "end overflow_monthly"); 115 verbose (2, _("end overflow_monthly"));
115} 116}
116 117
117int 118int
118ovf_weekly (struct traffic_history *th, struct traffic_record *tr, time_t now) 119ovf_weekly (struct traffic_history *th, struct traffic_record *tr, time_t now)
119{ 120{
120 verbose (2, "begin overflow_weekly %lu %g %g", now, th->inrate, th->outrate); 121 verbose (2, _("begin overflow_weekly %lu %g %g"),
122 now, th->inrate, th->outrate);
121 overflow (th, tr, now, ovf_monthly, &tr->month_avg, &tr->month_hist, 123 overflow (th, tr, now, ovf_monthly, &tr->month_avg, &tr->month_hist,
122 MONTH_COUNT, MONTH_SAMPLE); 124 MONTH_COUNT, MONTH_SAMPLE);
123 verbose (2, "end overflow_daily"); 125 verbose (2, _("end overflow_daily"));
124} 126}
125 127
126int 128int
127ovf_daily (struct traffic_history *th, struct traffic_record *tr, time_t now) 129ovf_daily (struct traffic_history *th, struct traffic_record *tr, time_t now)
128{ 130{
129 verbose (2, "begin overflow_daily %lu %g %g", now, th->inrate, th->outrate); 131 verbose (2, _("begin overflow_daily %lu %g %g"),
132 now, th->inrate, th->outrate);
130 overflow (th, tr, now, ovf_weekly, &tr->week_avg, &tr->week_hist, 133 overflow (th, tr, now, ovf_weekly, &tr->week_avg, &tr->week_hist,
131 WEEK_COUNT, WEEK_SAMPLE); 134 WEEK_COUNT, WEEK_SAMPLE);
132 verbose (2, "end overflow_daily"); 135 verbose (2, _("end overflow_daily"));
133} 136}
134 137
135void 138void
@@ -144,7 +147,7 @@ update_stats (struct monitor *mon, struct traffic_sample *sample,
144 interval = sample->time - tr->last.time; 147 interval = sample->time - tr->last.time;
145 if (interval == 0) 148 if (interval == 0)
146 { 149 {
147 logmsg (L_ERR, "Ignoring zero interval"); 150 logmsg (L_ERR, _("ignoring zero interval"));
148 return; 151 return;
149 } 152 }
150 inrate = (double) sample->in / interval; 153 inrate = (double) sample->in / interval;
@@ -217,7 +220,7 @@ _convert (queue_t *q, ovf_t ovf,
217 220
218 if (interval == 0) 221 if (interval == 0)
219 { 222 {
220 logmsg (L_ERR, "Ignoring zero interval"); 223 logmsg (L_ERR, _("ignoring zero interval"));
221 break; 224 break;
222 } 225 }
223 if (lastp) 226 if (lastp)
@@ -252,46 +255,46 @@ static void
252convert_yearly (struct traffic_record *tr, struct traffic_sample *hp, 255convert_yearly (struct traffic_record *tr, struct traffic_sample *hp,
253 size_t count) 256 size_t count)
254{ 257{
255 verbose (2, "begin convert_yearly"); 258 verbose (2, _("begin convert_yearly"));
256 _convert (&tr->year_hist, NULL, tr, 259 _convert (&tr->year_hist, NULL, tr,
257 hp, count, YEAR_SAMPLE); 260 hp, count, YEAR_SAMPLE);
258 compute_avg (&tr->year_avg, &tr->year_hist, &tr->last); 261 compute_avg (&tr->year_avg, &tr->year_hist, &tr->last);
259 verbose (2, "end convert_yearly"); 262 verbose (2, _("end convert_yearly"));
260} 263}
261 264
262static void 265static void
263convert_monthly (struct traffic_record *tr, struct traffic_sample *hp, 266convert_monthly (struct traffic_record *tr, struct traffic_sample *hp,
264 size_t count) 267 size_t count)
265{ 268{
266 verbose (2, "begin convert_monthly"); 269 verbose (2, _("begin convert_monthly"));
267 if (count > MONTH_COUNT+1) 270 if (count > MONTH_COUNT+1)
268 convert_yearly (tr, hp + MONTH_COUNT + 1, count - (MONTH_COUNT + 1)); 271 convert_yearly (tr, hp + MONTH_COUNT + 1, count - (MONTH_COUNT + 1));
269 _convert (&tr->month_hist, ovf_monthly, tr, 272 _convert (&tr->month_hist, ovf_monthly, tr,
270 hp, MONTH_COUNT + 1, MONTH_SAMPLE); 273 hp, MONTH_COUNT + 1, MONTH_SAMPLE);
271 compute_avg (&tr->month_avg, &tr->month_hist, &tr->last); 274 compute_avg (&tr->month_avg, &tr->month_hist, &tr->last);
272 verbose (2, "end convert_monthly"); 275 verbose (2, _("end convert_monthly"));
273} 276}
274 277
275static void 278static void
276convert_weekly (struct traffic_record *tr, struct traffic_sample *hp, size_t count) 279convert_weekly (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
277{ 280{
278 verbose (2, "begin convert_weekly"); 281 verbose (2, _("begin convert_weekly"));
279 if (count > WEEK_COUNT+1) 282 if (count > WEEK_COUNT+1)
280 convert_monthly (tr, hp + WEEK_COUNT + 1, count - (WEEK_COUNT + 1)); 283 convert_monthly (tr, hp + WEEK_COUNT + 1, count - (WEEK_COUNT + 1));
281 _convert (&tr->week_hist, ovf_weekly, 284 _convert (&tr->week_hist, ovf_weekly,
282 tr, hp, WEEK_COUNT + 1, WEEK_SAMPLE); 285 tr, hp, WEEK_COUNT + 1, WEEK_SAMPLE);
283 compute_avg (&tr->week_avg, &tr->week_hist, &tr->last); 286 compute_avg (&tr->week_avg, &tr->week_hist, &tr->last);
284 verbose (2, "end convert_weekly"); 287 verbose (2, _("end convert_weekly"));
285} 288}
286 289
287static void 290static void
288convert_daily (struct traffic_record *tr, struct traffic_sample *hp, size_t count) 291convert_daily (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
289{ 292{
290 verbose (2, "begin convert_daily"); 293 verbose (2, _("begin convert_daily"));
291 if (count > DAY_COUNT+1) 294 if (count > DAY_COUNT+1)
292 convert_weekly (tr, hp + DAY_COUNT + 1, count - (DAY_COUNT + 1)); 295 convert_weekly (tr, hp + DAY_COUNT + 1, count - (DAY_COUNT + 1));
293 _convert (&tr->day_hist, ovf_daily, tr, hp, DAY_COUNT + 1, DAY_SAMPLE); 296 _convert (&tr->day_hist, ovf_daily, tr, hp, DAY_COUNT + 1, DAY_SAMPLE);
294 verbose (2, "end convert_daily"); 297 verbose (2, _("end convert_daily"));
295} 298}
296 299
297static void 300static void
@@ -329,15 +332,15 @@ import_log (const char *name)
329 fp = fopen (name, "r"); 332 fp = fopen (name, "r");
330 if (!fp) 333 if (!fp)
331 { 334 {
332 logmsg (L_ERR, "cannot open `%s': %s", name, strerror (errno)); 335 logmsg (L_ERR, _("cannot open `%s': %s"), name, strerror (errno));
333 return 1; 336 return 1;
334 } 337 }
335 verbose (2, "Importing %s", name); 338 verbose (2, _("importing %s"), name);
336 339
337 340
338 if (fscanf (fp, "%ld %lu %lu\n", &last.time, &last.in, &last.out) != 3) 341 if (fscanf (fp, "%ld %lu %lu\n", &last.time, &last.in, &last.out) != 3)
339 { 342 {
340 logmsg (L_ERR, "%s:1: Unexpected number of fields", name); 343 logmsg (L_ERR, _("%s:1: unexpected number of fields"), name);
341 fclose (fp); 344 fclose (fp);
342 return 1; 345 return 1;
343 } 346 }
@@ -364,7 +367,7 @@ import_log (const char *name)
364 hist.time = rd[0]; 367 hist.time = rd[0];
365 if (hist.time > cur) 368 if (hist.time > cur)
366 { 369 {
367 logmsg (L_WARNING, "%s:%lu: is corrupted", name, line); 370 logmsg (L_WARNING, _("%s:%lu: is corrupted"), name, line);
368 break; 371 break;
369 } 372 }
370 cur = hist.time; 373 cur = hist.time;
@@ -399,7 +402,7 @@ import_log (const char *name)
399 mon = find_monitor (base); 402 mon = find_monitor (base);
400 if (!mon) 403 if (!mon)
401 { 404 {
402 logmsg (L_ERR, "cannot find monitor `%s'", base); 405 logmsg (L_ERR, _("cannot find monitor `%s'"), base);
403 rc = 1; 406 rc = 1;
404 } 407 }
405 else 408 else
@@ -416,10 +419,11 @@ import (const char *dirname)
416 size_t count = 0; 419 size_t count = 0;
417 struct stat st; 420 struct stat st;
418 421
419 verbose (2, "Examining `%s'", dirname); 422 verbose (2, _("examining `%s'"), dirname);
420 423
421 if (stat (dirname, &st)) 424 if (stat (dirname, &st))
422 die (EX_OSERR, "cannot stat file `%s': %s", dirname, strerror (errno)); 425 die (EX_OSERR, _("cannot stat file `%s': %s"),
426 dirname, strerror (errno));
423 else if (S_ISREG (st.st_mode)) 427 else if (S_ISREG (st.st_mode))
424 { 428 {
425 open_db (TAGR_DB_WR); 429 open_db (TAGR_DB_WR);
@@ -450,19 +454,20 @@ import (const char *dirname)
450 break; 454 break;
451 455
452 case GLOB_NOSPACE: 456 case GLOB_NOSPACE:
453 die (EX_UNAVAILABLE, "cannot scan directory: %s", strerror (ENOMEM)); 457 die (EX_UNAVAILABLE, _("cannot scan directory: %s"),
458 strerror (ENOMEM));
454 459
455 case GLOB_ABORTED: 460 case GLOB_ABORTED:
456 die (EX_UNAVAILABLE, "scanning aborted"); 461 die (EX_UNAVAILABLE, _("scanning aborted"));
457 462
458 case GLOB_NOMATCH: 463 case GLOB_NOMATCH:
459 break; 464 break;
460 465
461 default: 466 default:
462 die (EX_UNAVAILABLE, "cannot scan directory `%s'", dirname); 467 die (EX_UNAVAILABLE, _("cannot scan directory `%s'"), dirname);
463 } 468 }
464 } 469 }
465 470
466 verbose (1, "Number of imported log files: %d", count); 471 verbose (1, _("number of imported log files: %d"), count);
467} 472}
468 473

Return to:

Send suggestions and report system problems to the System administrator.