diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-27 00:50:31 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-27 00:50:31 +0300 |
commit | fe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3 (patch) | |
tree | 611a7c8505a0eb77a2b84de5dab80b6ca02a14e6 /src/stat.c | |
parent | d50fc04ded36255465184a16c70eb4c50acdb199 (diff) | |
download | tagr-fe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3.tar.gz tagr-fe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3.tar.bz2 |
Provide i18n markers
Diffstat (limited to 'src/stat.c')
-rw-r--r-- | src/stat.c | 65 |
1 files changed, 35 insertions, 30 deletions
@@ -36,38 +36,38 @@ interpolate (queue_t *q, | |||
36 | time_t last_time, struct traffic_history *last_rates, | 36 | time_t last_time, struct traffic_history *last_rates, |
37 | time_t interval, double inrate, double outrate, | 37 | time_t interval, double inrate, double outrate, |
38 | ovf_t ovf, | 38 | ovf_t ovf, |
39 | struct traffic_record *tr) | 39 | struct traffic_record *tr) |
40 | { | 40 | { |
41 | time_t next; | 41 | time_t next; |
42 | struct traffic_history th; | 42 | struct traffic_history th; |
43 | 43 | ||
44 | if (now - last_time <= step) | 44 | if (now - last_time <= step) |
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); |
52 | return; | 52 | return; |
53 | } | 53 | } |
54 | 54 | ||
55 | for (next = last_time + step; next <= now; next += step) | 55 | for (next = last_time + step; next <= now; next += step) |
56 | { | 56 | { |
57 | th.inrate = (inrate - last_rates->inrate) * (next - last_time) | 57 | th.inrate = (inrate - last_rates->inrate) * (next - last_time) |
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); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | int | 68 | int |
69 | overflow (struct traffic_history *th, | 69 | overflow (struct traffic_history *th, |
70 | struct traffic_record *tr, | 70 | struct traffic_record *tr, |
71 | time_t now, | 71 | time_t now, |
72 | ovf_t ovf, | 72 | ovf_t ovf, |
73 | struct avg_acc *avg, | 73 | struct avg_acc *avg, |
@@ -83,77 +83,80 @@ overflow (struct traffic_history *th, | |||
83 | step, | 83 | step, |
84 | now, | 84 | now, |
85 | avg->time, | 85 | avg->time, |
86 | lastp, | 86 | lastp, |
87 | now - avg->time, | 87 | now - avg->time, |
88 | avg->inrate, avg->outrate, | 88 | avg->inrate, avg->outrate, |
89 | ovf, tr); | 89 | ovf, tr); |
90 | else | 90 | else |
91 | { | 91 | { |
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 | ||
99 | avg->inrate = avg->outrate = 0; | 99 | avg->inrate = avg->outrate = 0; |
100 | avg->count = 0; | 100 | avg->count = 0; |
101 | avg->time = now; | 101 | avg->time = now; |
102 | } | 102 | } |
103 | avg->inrate = (avg->count * avg->inrate + th->inrate) / (avg->count + 1); | 103 | avg->inrate = (avg->count * avg->inrate + th->inrate) / (avg->count + 1); |
104 | avg->outrate = (avg->count * avg->outrate + th->outrate) / (avg->count + 1); | 104 | avg->outrate = (avg->count * avg->outrate + th->outrate) / (avg->count + 1); |
105 | avg->count++; | 105 | avg->count++; |
106 | } | 106 | } |
107 | 107 | ||
108 | int | 108 | int |
109 | ovf_monthly (struct traffic_history *th, struct traffic_record *tr, time_t now) | 109 | ovf_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 | ||
117 | int | 118 | int |
118 | ovf_weekly (struct traffic_history *th, struct traffic_record *tr, time_t now) | 119 | ovf_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 | ||
126 | int | 128 | int |
127 | ovf_daily (struct traffic_history *th, struct traffic_record *tr, time_t now) | 129 | ovf_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 | ||
135 | void | 138 | void |
136 | update_stats (struct monitor *mon, struct traffic_sample *sample, | 139 | update_stats (struct monitor *mon, struct traffic_sample *sample, |
137 | struct traffic_record *tr) | 140 | struct traffic_record *tr) |
138 | { | 141 | { |
139 | time_t interval; | 142 | time_t interval; |
140 | double inrate, outrate; | 143 | double inrate, outrate; |
141 | 144 | ||
142 | struct traffic_history *lastp = queue_get_tail (&tr->day_hist); | 145 | struct traffic_history *lastp = queue_get_tail (&tr->day_hist); |
143 | 146 | ||
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; |
151 | outrate = (double) sample->out / interval; | 154 | outrate = (double) sample->out / interval; |
152 | if (lastp) | 155 | if (lastp) |
153 | { | 156 | { |
154 | interpolate (&tr->day_hist, | 157 | interpolate (&tr->day_hist, |
155 | DAY_SAMPLE, | 158 | DAY_SAMPLE, |
156 | sample->time, | 159 | sample->time, |
157 | tr->last.time, | 160 | tr->last.time, |
158 | &tr->last_rates, | 161 | &tr->last_rates, |
159 | interval, | 162 | interval, |
@@ -208,25 +211,25 @@ _convert (queue_t *q, ovf_t ovf, | |||
208 | for (hp = hist + count - 1; hp >= hist; hp--) | 211 | for (hp = hist + count - 1; hp >= hist; hp--) |
209 | { | 212 | { |
210 | time_t interval; | 213 | time_t interval; |
211 | double inrate, outrate; | 214 | double inrate, outrate; |
212 | struct traffic_history *lastp = queue_get_tail (q); | 215 | struct traffic_history *lastp = queue_get_tail (q); |
213 | 216 | ||
214 | interval = hp->time - tr->last.time; | 217 | interval = hp->time - tr->last.time; |
215 | inrate = (double) hp->in; | 218 | inrate = (double) hp->in; |
216 | outrate = (double) hp->out; | 219 | outrate = (double) hp->out; |
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) |
224 | { | 227 | { |
225 | interpolate (q, | 228 | interpolate (q, |
226 | sample_interval, | 229 | sample_interval, |
227 | hp->time, | 230 | hp->time, |
228 | tr->last.time, | 231 | tr->last.time, |
229 | &tr->last_rates, | 232 | &tr->last_rates, |
230 | interval, | 233 | interval, |
231 | inrate, outrate, | 234 | inrate, outrate, |
232 | ovf, tr); | 235 | ovf, tr); |
@@ -243,64 +246,64 @@ _convert (queue_t *q, ovf_t ovf, | |||
243 | tr->last.time = hp->time; | 246 | tr->last.time = hp->time; |
244 | tr->last.in = hp->in; | 247 | tr->last.in = hp->in; |
245 | tr->last.out = hp->out; | 248 | tr->last.out = hp->out; |
246 | tr->last_rates.inrate = inrate; | 249 | tr->last_rates.inrate = inrate; |
247 | tr->last_rates.outrate = outrate; | 250 | tr->last_rates.outrate = outrate; |
248 | } | 251 | } |
249 | } | 252 | } |
250 | 253 | ||
251 | static void | 254 | static void |
252 | convert_yearly (struct traffic_record *tr, struct traffic_sample *hp, | 255 | convert_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); |