summaryrefslogtreecommitdiffabout
path: root/src/stat.c
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-25 07:44:14 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-04-25 07:44:14 (GMT)
commitd8c782807ffbd0e7e30b07f88dd91b6dc0988219 (patch) (side-by-side diff)
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') (more/less context) (ignore whitespace changes)
-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)
}
void
-update_stats (SD *sd, struct traffic_record *tr)
+update_stats (struct monitor *mon, struct traffic_sample *sample,
+ struct traffic_record *tr)
{
time_t interval;
double inrate, outrate;
struct traffic_history *lastp = queue_get_tail (&tr->day_hist);
- interval = sd->t - tr->last.time;
+ interval = sample->time - tr->last.time;
if (interval == 0)
{
logmsg (L_ERR, "Ignoring zero interval");
return;
}
- inrate = (double) sd->in / interval;
- outrate = (double) sd->out / interval;
+ inrate = (double) sample->in / interval;
+ outrate = (double) sample->out / interval;
if (lastp)
{
interpolate (&tr->day_hist,
DAY_SAMPLE,
- sd->t,
+ sample->time,
tr->last.time,
&tr->last_rates,
interval,
@@ -162,14 +163,14 @@ update_stats (SD *sd, struct traffic_record *tr)
else
{
struct traffic_history th;
- interval = sd->t - tr->last.time;
+ interval = sample->time - tr->last.time;
th.inrate = inrate;
th.outrate = outrate;
queue_put (&tr->day_hist, &th);
}
- tr->last.time = sd->t;
- tr->last.in = sd->in;
- tr->last.out = sd->out;
+ tr->last.time = sample->time;
+ tr->last.in = sample->in;
+ tr->last.out = sample->out;
tr->last_rates.inrate = inrate;
tr->last_rates.outrate = outrate;
}
@@ -178,7 +179,7 @@ update_stats (SD *sd, struct traffic_record *tr)
static void
-compute_avg (struct avg_acc *avg, queue_t *q, struct last_sample *last)
+compute_avg (struct avg_acc *avg, queue_t *q, struct traffic_sample *last)
{
int i, n = queue_count (q);
avg->inrate = avg->outrate = 0;
@@ -195,15 +196,13 @@ compute_avg (struct avg_acc *avg, queue_t *q, struct last_sample *last)
avg->time = last->time;
}
-#define hist_rec last_sample
-
static void
_convert (queue_t *q, ovf_t ovf,
- struct traffic_record *tr, struct hist_rec *hist, size_t count,
+ struct traffic_record *tr, struct traffic_sample *hist, size_t count,
time_t sample_interval)
{
size_t i;
- struct hist_rec *hp;
+ struct traffic_sample *hp;
tr->last.time = hist[count-1].time - sample_interval;
for (hp = hist + count - 1; hp >= hist; hp--)
@@ -250,7 +249,8 @@ _convert (queue_t *q, ovf_t ovf,
}
static void
-convert_yearly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+convert_yearly (struct traffic_record *tr, struct traffic_sample *hp,
+ size_t count)
{
verbose (2, "begin convert_yearly");
_convert (&tr->year_hist, NULL, tr,
@@ -260,7 +260,8 @@ convert_yearly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
}
static void
-convert_monthly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+convert_monthly (struct traffic_record *tr, struct traffic_sample *hp,
+ size_t count)
{
verbose (2, "begin convert_monthly");
if (count > MONTH_COUNT+1)
@@ -272,7 +273,7 @@ convert_monthly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
}
static void
-convert_weekly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+convert_weekly (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
{
verbose (2, "begin convert_weekly");
if (count > WEEK_COUNT+1)
@@ -284,7 +285,7 @@ convert_weekly (struct traffic_record *tr, struct hist_rec *hp, size_t count)
}
static void
-convert_daily (struct traffic_record *tr, struct hist_rec *hp, size_t count)
+convert_daily (struct traffic_record *tr, struct traffic_sample *hp, size_t count)
{
verbose (2, "begin convert_daily");
if (count > DAY_COUNT+1)
@@ -294,8 +295,8 @@ convert_daily (struct traffic_record *tr, struct hist_rec *hp, size_t count)
}
static void
-convert_stats (SD *sd, struct hist_rec *last,
- struct hist_rec *hp, size_t count)
+convert_stats (struct monitor *mon, struct traffic_sample *last,
+ struct traffic_sample *hp, size_t count)
{
struct traffic_record *trp, tr;
@@ -304,10 +305,10 @@ convert_stats (SD *sd, struct hist_rec *last,
convert_daily (&tr, hp, count);
- read_db (sd, &trp);
+ read_db (mon, &trp);
*trp = tr;
trp->last = *last;
- write_db (sd, trp);
+ write_db (mon, trp);
free (trp);
}
@@ -317,7 +318,7 @@ import_log (const char *name)
FILE *fp;
int rc = 0;
struct obstack stk;
- struct hist_rec last, hist, *hp;
+ struct traffic_sample last, hist, *hp;
unsigned long inmax, outmax;
size_t count = 0;
char *buf = NULL;
@@ -387,7 +388,7 @@ import_log (const char *name)
hp = obstack_finish (&stk);
if (count)
{
- SD *sd;
+ struct monitor *mon;
char *p = strrchr (name, '/');
char *base = xstrdup (p ? p + 1 : name);
@@ -395,14 +396,14 @@ import_log (const char *name)
if (p)
*p = 0;
- sd = find_router (base);
- if (!sd)
+ mon = find_monitor (base);
+ if (!mon)
{
- logmsg (L_ERR, "cannot find router `%s'", base);
+ logmsg (L_ERR, "cannot find monitor `%s'", base);
rc = 1;
}
else
- convert_stats (sd, &last, hp, count);
+ convert_stats (mon, &last, hp, count);
}
obstack_free (&stk, NULL);

Return to:

Send suggestions and report system problems to the System administrator.