aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-11-23 23:02:12 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-11-23 23:02:12 +0000
commitd6fcfeeceda7b10383677244eb871dce30e0e359 (patch)
treef45c356e7d0ad0d938421f0bc5f899c9fe866a42
parent7f78bca4ccd8ec85d3b1c5ab74e81457a5c9233f (diff)
downloadtagr-d6fcfeeceda7b10383677244eb871dce30e0e359.tar.gz
tagr-d6fcfeeceda7b10383677244eb871dce30e0e359.tar.bz2
(overflow): Fix avg computation
(import_log): Scale values git-svn-id: file:///svnroot/tagr/trunk@71 7c378d0d-a4e4-4a64-9229-dfce8bfd23d4
-rw-r--r--stat.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/stat.c b/stat.c
index c847550..63f87fa 100644
--- a/stat.c
+++ b/stat.c
@@ -91,8 +91,8 @@ overflow (struct traffic_history *th,
avg->count = 0;
avg->time = now;
}
- avg->inrate = (avg->inrate + avg->count * th->inrate) / avg->count + 1;
- avg->inrate = (avg->outrate + avg->count * th->outrate) / avg->count + 1;
+ avg->inrate = (avg->count * avg->inrate + th->inrate) / (avg->count + 1);
+ avg->outrate = (avg->count * avg->outrate + th->outrate) / (avg->count + 1);
avg->count++;
}
@@ -178,8 +178,8 @@ convert_stats (SD *sd, struct hist_rec *last,
for (i = count - 1; i+1 > 0; i--)
{
sd->t = hp[i].time;
- sd->in = hp[i].in * 300;
- sd->out = hp[i].out * 300;
+ sd->in = hp[i].in;
+ sd->out = hp[i].out;
verbose (3, "Data %lu %lu %lu", sd->t, sd->in, sd->out);
update_stats (sd, &tr);
}
@@ -227,7 +227,8 @@ import_log (const char *name)
{
int i;
unsigned long rd[5];
-
+ unsigned scale;
+
line++;
if (sscanf (buf, "%lu %lu %lu %lu %lu",
@@ -241,8 +242,18 @@ import_log (const char *name)
rd[i] = rd[i] < 0 ? 0 : rd[i];
hist.time = rd[0];
- hist.in = rd[1];
- hist.out = rd[2];
+ if (line == 2)
+ scale = 300;
+ else if (hist.time > cur)
+ {
+ logmsg (L_WARNING, "%s:%lu: is corrupted", name, line);
+ break;
+ }
+ else
+ scale = cur - hist.time;
+ cur = hist.time;
+ hist.in = rd[1] * scale;
+ hist.out = rd[2] * scale;
if (inmax < rd[3])
inmax = rd[3];
if (inmax < hist.in)
@@ -252,11 +263,6 @@ import_log (const char *name)
if (outmax < hist.out)
outmax = hist.out;
- if (hist.time > cur)
- {
- logmsg (L_WARNING, "%s:%lu: is corrupted", name, line);
- break;
- }
obstack_grow (&stk, &hist, sizeof (hist));
count++;
}

Return to:

Send suggestions and report system problems to the System administrator.