aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/stats/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/stats/functions.c')
-rw-r--r--src/plugins/stats/functions.c723
1 files changed, 320 insertions, 403 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index 5b6e2542..9c5e90db 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -29,13 +29,13 @@
29 29
30#define FUNCTIONS_DEBUG NO 30#define FUNCTIONS_DEBUG NO
31 31
32static StatPair * lastStatValues; 32static StatPair *lastStatValues;
33 33
34static unsigned int lsv_size; 34static unsigned int lsv_size;
35 35
36static struct ClientServerConnection * sock; 36static struct ClientServerConnection *sock;
37 37
38static struct MUTEX * lock; 38static struct MUTEX *lock;
39 39
40static long connectionGoal; 40static long connectionGoal;
41 41
@@ -43,126 +43,106 @@ static long long banddown;
43 43
44static long long bandup; 44static long long bandup;
45 45
46static struct GE_Context * ectx; 46static struct GE_Context *ectx;
47 47
48static struct GC_Configuration * cfg; 48static struct GC_Configuration *cfg;
49 49
50static struct CronManager * cron; 50static struct CronManager *cron;
51 51
52static int getStatValue(long long * value, 52static int
53 long long * lvalue, 53getStatValue (long long *value,
54 cron_t * dtime, 54 long long *lvalue,
55 const char * optName, 55 cron_t * dtime, const char *optName, int monotone)
56 int monotone) { 56{
57 unsigned int i; 57 unsigned int i;
58 58
59 *value = 0; 59 *value = 0;
60 if (lvalue != NULL) 60 if (lvalue != NULL)
61 *lvalue = 0; 61 *lvalue = 0;
62 for (i=0;i<lsv_size;i++) { 62 for (i = 0; i < lsv_size; i++)
63 if (0 == strcmp(optName, 63 {
64 lastStatValues[i].statName)) { 64 if (0 == strcmp (optName, lastStatValues[i].statName))
65 *value = lastStatValues[i].value; 65 {
66 if (lvalue != NULL) 66 *value = lastStatValues[i].value;
67 *lvalue = lastStatValues[i].lvalue; 67 if (lvalue != NULL)
68 if (dtime != NULL) 68 *lvalue = lastStatValues[i].lvalue;
69 *dtime = lastStatValues[i].delta; 69 if (dtime != NULL)
70 if ( (monotone == YES) && 70 *dtime = lastStatValues[i].delta;
71 (lvalue != NULL) && 71 if ((monotone == YES) && (lvalue != NULL) && (*lvalue > *value))
72 (*lvalue > *value) ) 72 return SYSERR; /* gnunetd restart? */
73 return SYSERR; /* gnunetd restart? */ 73 return OK;
74 return OK; 74 }
75 } 75 }
76 }
77#if FUNCTIONS_DEBUG 76#if FUNCTIONS_DEBUG
78 GE_LOG(ectx, 77 GE_LOG (ectx,
79 GE_DEBUG | GE_DEVELOPER | GE_REQUEST, 78 GE_DEBUG | GE_DEVELOPER | GE_REQUEST,
80 "Statistic not found: `%s'\n", 79 "Statistic not found: `%s'\n", optName);
81 optName);
82#endif 80#endif
83 return SYSERR; 81 return SYSERR;
84} 82}
85 83
86static void updateConnectionGoal(void * unused) { 84static void
87 char * cmh; 85updateConnectionGoal (void *unused)
88 char * availableDown; 86{
89 char * availableUp; 87 char *cmh;
90 88 char *availableDown;
91 MUTEX_LOCK(lock); 89 char *availableUp;
92 cmh = getConfigurationOptionValue(sock, 90
93 "gnunetd", 91 MUTEX_LOCK (lock);
94 "connection-max-hosts"); 92 cmh = getConfigurationOptionValue (sock, "gnunetd", "connection-max-hosts");
95 availableDown = getConfigurationOptionValue(sock, 93 availableDown = getConfigurationOptionValue (sock,
96 "LOAD", 94 "LOAD", "MAXNETDOWNBPSTOTAL");
97 "MAXNETDOWNBPSTOTAL"); 95 availableUp = getConfigurationOptionValue (sock,
98 availableUp = getConfigurationOptionValue(sock, 96 "LOAD", "MAXNETUPBPSTOTAL");
99 "LOAD", 97 MUTEX_UNLOCK (lock);
100 "MAXNETUPBPSTOTAL");
101 MUTEX_UNLOCK(lock);
102 if (cmh == NULL) 98 if (cmh == NULL)
103 connectionGoal = 0; 99 connectionGoal = 0;
104 else 100 else
105 connectionGoal = atol(cmh); 101 connectionGoal = atol (cmh);
106 if (availableDown == NULL) 102 if (availableDown == NULL)
107 banddown = 0; 103 banddown = 0;
108 else 104 else
109 banddown = atol(availableDown); 105 banddown = atol (availableDown);
110 if (availableUp == NULL) 106 if (availableUp == NULL)
111 bandup = 0; 107 bandup = 0;
112 else 108 else
113 bandup = atol(availableUp); 109 bandup = atol (availableUp);
114 110
115 FREENONNULL(cmh); 111 FREENONNULL (cmh);
116 FREENONNULL(availableDown); 112 FREENONNULL (availableDown);
117 FREENONNULL(availableUp); 113 FREENONNULL (availableUp);
118} 114}
119 115
120static int getConnectedNodesStat(const void * closure, 116static int
121 gfloat ** data) { 117getConnectedNodesStat (const void *closure, gfloat ** data)
118{
122 long long val; 119 long long val;
123 120
124 if (connectionGoal == 0) 121 if (connectionGoal == 0)
125 return SYSERR; 122 return SYSERR;
126 if (OK != getStatValue(&val, 123 if (OK != getStatValue (&val, NULL, NULL, "# of connected peers", NO))
127 NULL,
128 NULL,
129 "# of connected peers",
130 NO))
131 return SYSERR; 124 return SYSERR;
132 data[0][0] = ((gfloat) val) / connectionGoal; 125 data[0][0] = ((gfloat) val) / connectionGoal;
133 return OK; 126 return OK;
134} 127}
135 128
136static int getLoadStat(const void * closure, 129static int
137 gfloat ** data) { 130getLoadStat (const void *closure, gfloat ** data)
131{
138 long long valc; 132 long long valc;
139 long long vali; 133 long long vali;
140 long long valu; 134 long long valu;
141 long long vald; 135 long long vald;
142 136
143 if (OK != getStatValue(&valc, 137 if (OK != getStatValue (&valc, NULL, NULL, "% of allowed cpu load", NO))
144 NULL,
145 NULL,
146 "% of allowed cpu load",
147 NO))
148 return SYSERR; 138 return SYSERR;
149 if (OK != getStatValue(&vali, 139 if (OK != getStatValue (&vali, NULL, NULL, "% of allowed io load", NO))
150 NULL,
151 NULL,
152 "% of allowed io load",
153 NO))
154 return SYSERR; 140 return SYSERR;
155 if (OK != getStatValue(&valu, 141 if (OK != getStatValue (&valu,
156 NULL, 142 NULL, NULL, "% of allowed network load (up)", NO))
157 NULL,
158 "% of allowed network load (up)",
159 NO))
160 return SYSERR; 143 return SYSERR;
161 if (OK != getStatValue(&vald, 144 if (OK != getStatValue (&vald,
162 NULL, 145 NULL, NULL, "% of allowed network load (down)", NO))
163 NULL,
164 "% of allowed network load (down)",
165 NO))
166 return SYSERR; 146 return SYSERR;
167 data[0][0] = (gfloat) valc / 100.0; 147 data[0][0] = (gfloat) valc / 100.0;
168 data[0][1] = (gfloat) vali / 100.0; 148 data[0][1] = (gfloat) vali / 100.0;
@@ -171,31 +151,26 @@ static int getLoadStat(const void * closure,
171 return OK; 151 return OK;
172} 152}
173 153
174static int getQuotaStat(const void * closure, 154static int
175 gfloat ** data) { 155getQuotaStat (const void *closure, gfloat ** data)
156{
176 long long allowed; 157 long long allowed;
177 long long have; 158 long long have;
178 159
179 if (OK != getStatValue(&allowed, 160 if (OK != getStatValue (&allowed,
180 NULL, 161 NULL, NULL, "# bytes allowed in datastore", NO))
181 NULL,
182 "# bytes allowed in datastore",
183 NO))
184 return SYSERR; 162 return SYSERR;
185 if (allowed == 0) 163 if (allowed == 0)
186 return SYSERR; 164 return SYSERR;
187 if (OK != getStatValue(&have, 165 if (OK != getStatValue (&have, NULL, NULL, "# bytes in datastore", NO))
188 NULL,
189 NULL,
190 "# bytes in datastore",
191 NO))
192 return SYSERR; 166 return SYSERR;
193 data[0][0] = ((gfloat) have) / allowed; 167 data[0][0] = ((gfloat) have) / allowed;
194 return OK; 168 return OK;
195} 169}
196 170
197static int getTrafficRecvStats(const void * closure, 171static int
198 gfloat ** data) { 172getTrafficRecvStats (const void *closure, gfloat ** data)
173{
199 long long total; 174 long long total;
200 long long noise; 175 long long noise;
201 long long content; 176 long long content;
@@ -209,66 +184,40 @@ static int getTrafficRecvStats(const void * closure,
209 long long lhellos; 184 long long lhellos;
210 long long lrlimit; 185 long long lrlimit;
211 cron_t dtime; 186 cron_t dtime;
212 char * buffer; 187 char *buffer;
213 188
214 if (OK != getStatValue(&total, 189 if (OK != getStatValue (&total, &ltotal, &dtime, "# bytes received", YES))
215 &ltotal,
216 &dtime,
217 "# bytes received",
218 YES))
219 return SYSERR; 190 return SYSERR;
220 if (OK != getStatValue(&noise, 191 if (OK != getStatValue (&noise,
221 &lnoise, 192 &lnoise, NULL, "# bytes of noise received", YES))
222 NULL,
223 "# bytes of noise received",
224 YES))
225 return SYSERR; 193 return SYSERR;
226 buffer = MALLOC(512); 194 buffer = MALLOC (512);
227 SNPRINTF(buffer, 195 SNPRINTF (buffer, 512, "# bytes received of type %d", P2P_PROTO_gap_RESULT);
228 512, 196 if (OK != getStatValue (&content, &lcontent, NULL, buffer, YES))
229 "# bytes received of type %d", 197 {
230 P2P_PROTO_gap_RESULT); 198 content = 0;
231 if (OK != getStatValue(&content, 199 lcontent = 0;
232 &lcontent, 200 }
233 NULL, 201 SNPRINTF (buffer, 512, "# bytes received of type %d", p2p_PROTO_hello);
234 buffer, 202 if (OK != getStatValue (&hellos, &lhellos, NULL, buffer, YES))
235 YES)) { 203 {
236 content = 0; 204 hellos = 0;
237 lcontent = 0; 205 lhellos = 0;
238 } 206 }
239 SNPRINTF(buffer, 207 SNPRINTF (buffer, 512, "# bytes received of type %d", P2P_PROTO_gap_QUERY);
240 512, 208 if (OK != getStatValue (&queries, &lqueries, NULL, buffer, YES))
241 "# bytes received of type %d", 209 {
242 p2p_PROTO_hello); 210 queries = 0;
243 if (OK != getStatValue(&hellos, 211 lqueries = 0;
244 &lhellos, 212 }
245 NULL, 213 if (OK != getStatValue (&rlimit,
246 buffer, 214 &lrlimit,
247 YES)) { 215 NULL, "# total bytes per second receive limit", NO))
248 hellos = 0; 216 {
249 lhellos = 0; 217 rlimit = 0;
250 } 218 lrlimit = 0;
251 SNPRINTF(buffer, 219 }
252 512, 220 FREE (buffer);
253 "# bytes received of type %d",
254 P2P_PROTO_gap_QUERY);
255 if (OK != getStatValue(&queries,
256 &lqueries,
257 NULL,
258 buffer,
259 YES)) {
260 queries = 0;
261 lqueries = 0;
262 }
263 if (OK != getStatValue(&rlimit,
264 &lrlimit,
265 NULL,
266 "# total bytes per second receive limit",
267 NO)) {
268 rlimit = 0;
269 lrlimit = 0;
270 }
271 FREE(buffer);
272 if (banddown == 0) 221 if (banddown == 0)
273 return SYSERR; 222 return SYSERR;
274 223
@@ -277,32 +226,31 @@ static int getTrafficRecvStats(const void * closure,
277 queries -= lqueries; 226 queries -= lqueries;
278 content -= lcontent; 227 content -= lcontent;
279 hellos -= lhellos; 228 hellos -= lhellos;
280 if (banddown < 0) { 229 if (banddown < 0)
281 data[0][0] = 0.0; 230 {
282 data[0][1] = 0.0; 231 data[0][0] = 0.0;
283 data[0][2] = 0.0; 232 data[0][1] = 0.0;
284 data[0][3] = 0.0; 233 data[0][2] = 0.0;
285 data[0][4] = 0.0; 234 data[0][3] = 0.0;
286 data[0][5] = 0.0; 235 data[0][4] = 0.0;
287 return OK; 236 data[0][5] = 0.0;
288 } 237 return OK;
289 data[0][0] = ((gfloat) noise) / (banddown * dtime / cronSECONDS); /* red */ 238 }
290 data[0][1] = ((gfloat) (content+noise)) / (banddown * dtime / cronSECONDS); /* green */ 239 data[0][0] = ((gfloat) noise) / (banddown * dtime / cronSECONDS); /* red */
291 data[0][2] = ((gfloat)(queries+content+noise)) / (banddown * dtime / cronSECONDS); /* yellow */ 240 data[0][1] = ((gfloat) (content + noise)) / (banddown * dtime / cronSECONDS); /* green */
292 data[0][3] = ((gfloat)(queries+content+noise+hellos)) / (banddown * dtime / cronSECONDS); /* blue */ 241 data[0][2] = ((gfloat) (queries + content + noise)) / (banddown * dtime / cronSECONDS); /* yellow */
293 data[0][4] = ((gfloat) total) / (banddown * dtime / cronSECONDS); /* gray */ 242 data[0][3] = ((gfloat) (queries + content + noise + hellos)) / (banddown * dtime / cronSECONDS); /* blue */
294 data[0][5] = (gfloat) rlimit / banddown; /* magenta */ 243 data[0][4] = ((gfloat) total) / (banddown * dtime / cronSECONDS); /* gray */
244 data[0][5] = (gfloat) rlimit / banddown; /* magenta */
295#if 0 245#if 0
296 printf("I: %f %f %f %f\n", 246 printf ("I: %f %f %f %f\n", data[0][0], data[0][1], data[0][2]);
297 data[0][0],
298 data[0][1],
299 data[0][2]);
300#endif 247#endif
301 return OK; 248 return OK;
302} 249}
303 250
304static int getTrafficSendStats(const void * closure, 251static int
305 gfloat ** data) { 252getTrafficSendStats (const void *closure, gfloat ** data)
253{
306 long long total; 254 long long total;
307 long long noise; 255 long long noise;
308 long long content; 256 long long content;
@@ -316,66 +264,42 @@ static int getTrafficSendStats(const void * closure,
316 long long lhellos; 264 long long lhellos;
317 long long lslimit; 265 long long lslimit;
318 cron_t dtime; 266 cron_t dtime;
319 char * buffer; 267 char *buffer;
320 268
321 if (OK != getStatValue(&total, 269 if (OK != getStatValue (&total,
322 &ltotal, 270 &ltotal, &dtime, "# bytes transmitted", YES))
323 &dtime,
324 "# bytes transmitted",
325 YES))
326 return SYSERR; 271 return SYSERR;
327 if (OK != getStatValue(&noise, 272 if (OK != getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", YES))
328 &lnoise,
329 NULL,
330 "# bytes noise sent",
331 YES))
332 return SYSERR; 273 return SYSERR;
333 buffer = MALLOC(512); 274 buffer = MALLOC (512);
334 SNPRINTF(buffer, 275 SNPRINTF (buffer,
335 512, 276 512, "# bytes transmitted of type %d", P2P_PROTO_gap_RESULT);
336 "# bytes transmitted of type %d", 277 if (OK != getStatValue (&content, &lcontent, NULL, buffer, YES))
337 P2P_PROTO_gap_RESULT); 278 {
338 if (OK != getStatValue(&content, 279 content = 0;
339 &lcontent, 280 lcontent = 0;
340 NULL, 281 }
341 buffer, 282 SNPRINTF (buffer,
342 YES)) { 283 512, "# bytes transmitted of type %d", P2P_PROTO_gap_QUERY);
343 content = 0; 284 if (OK != getStatValue (&queries, &lqueries, NULL, buffer, YES))
344 lcontent = 0; 285 {
345 } 286 queries = 0;
346 SNPRINTF(buffer, 287 lqueries = 0;
347 512, 288 }
348 "# bytes transmitted of type %d", 289 SNPRINTF (buffer, 512, "# bytes transmitted of type %d", p2p_PROTO_hello);
349 P2P_PROTO_gap_QUERY); 290 if (OK != getStatValue (&hellos, &lhellos, NULL, buffer, YES))
350 if (OK != getStatValue(&queries, 291 {
351 &lqueries, 292 queries = 0;
352 NULL, 293 lqueries = 0;
353 buffer, 294 }
354 YES)) { 295 if (OK != getStatValue (&slimit,
355 queries = 0; 296 &lslimit,
356 lqueries = 0; 297 NULL, "# total bytes per second send limit", NO))
357 } 298 {
358 SNPRINTF(buffer, 299 slimit = 0;
359 512, 300 lslimit = 0;
360 "# bytes transmitted of type %d", 301 }
361 p2p_PROTO_hello); 302 FREE (buffer);
362 if (OK != getStatValue(&hellos,
363 &lhellos,
364 NULL,
365 buffer,
366 YES)) {
367 queries = 0;
368 lqueries = 0;
369 }
370 if (OK != getStatValue(&slimit,
371 &lslimit,
372 NULL,
373 "# total bytes per second send limit",
374 NO)) {
375 slimit = 0;
376 lslimit = 0;
377 }
378 FREE(buffer);
379 if (bandup == 0) 303 if (bandup == 0)
380 return SYSERR; 304 return SYSERR;
381 total -= ltotal; 305 total -= ltotal;
@@ -383,34 +307,32 @@ static int getTrafficSendStats(const void * closure,
383 queries -= lqueries; 307 queries -= lqueries;
384 content -= lcontent; 308 content -= lcontent;
385 hellos -= lhellos; 309 hellos -= lhellos;
386 if (bandup < 0) { 310 if (bandup < 0)
387 data[0][0] = 0.0; 311 {
388 data[0][1] = 0.0; 312 data[0][0] = 0.0;
389 data[0][2] = 0.0; 313 data[0][1] = 0.0;
390 data[0][3] = 0.0; 314 data[0][2] = 0.0;
391 data[0][4] = 0.0; 315 data[0][3] = 0.0;
392 data[0][5] = 0.0; 316 data[0][4] = 0.0;
393 return OK; 317 data[0][5] = 0.0;
394 } 318 return OK;
395 data[0][0] = ((gfloat) noise) / (bandup * dtime / cronSECONDS); /* red */ 319 }
396 data[0][1] = ((gfloat) (noise + content)) / (bandup*dtime / cronSECONDS); /* green */ 320 data[0][0] = ((gfloat) noise) / (bandup * dtime / cronSECONDS); /* red */
397 data[0][2] = ((gfloat) (noise + content + queries)) / (bandup*dtime / cronSECONDS); /* yellow */ 321 data[0][1] = ((gfloat) (noise + content)) / (bandup * dtime / cronSECONDS); /* green */
398 data[0][3] = ((gfloat) (noise + content + queries + hellos)) / (bandup*dtime / cronSECONDS); /* blue */ 322 data[0][2] = ((gfloat) (noise + content + queries)) / (bandup * dtime / cronSECONDS); /* yellow */
399 data[0][4] = ((gfloat) total) / (bandup*dtime / cronSECONDS); /* grey */ 323 data[0][3] = ((gfloat) (noise + content + queries + hellos)) / (bandup * dtime / cronSECONDS); /* blue */
400 data[0][5] = ((gfloat) slimit) / bandup ; /* magenta */ 324 data[0][4] = ((gfloat) total) / (bandup * dtime / cronSECONDS); /* grey */
325 data[0][5] = ((gfloat) slimit) / bandup; /* magenta */
401#if 0 326#if 0
402 printf("O: %f %f %f %f\n", 327 printf ("O: %f %f %f %f\n", data[0][0], data[0][1], data[0][2], data[0][3]);
403 data[0][0],
404 data[0][1],
405 data[0][2],
406 data[0][3]);
407#endif 328#endif
408 return OK; 329 return OK;
409} 330}
410 331
411 332
412static int getEffectivenessStats(const void * closure, 333static int
413 gfloat ** data) { 334getEffectivenessStats (const void *closure, gfloat ** data)
335{
414 static cron_t last; 336 static cron_t last;
415 static double lastdata; 337 static double lastdata;
416 static double lastavg; 338 static double lastavg;
@@ -422,39 +344,41 @@ static int getEffectivenessStats(const void * closure,
422 long long llocal; 344 long long llocal;
423 cron_t now; 345 cron_t now;
424 346
425 now = get_time(); 347 now = get_time ();
426 if (now < last + 2 * cronMINUTES) { 348 if (now < last + 2 * cronMINUTES)
427 data[0][0] = lastdata; 349 {
428 data[0][1] = lastavg; 350 data[0][0] = lastdata;
429 return OK; 351 data[0][1] = lastavg;
430 } 352 return OK;
353 }
431 last = now; 354 last = now;
432 if (OK != getStatValue(&total, 355 if (OK != getStatValue (&total,
433 &ltotal, 356 &ltotal,
434 NULL, 357 NULL,
435 "# gap requests forwarded (counting each peer)", 358 "# gap requests forwarded (counting each peer)",
436 YES)) 359 YES))
437 return SYSERR; 360 return SYSERR;
438 if (OK != getStatValue(&success, 361 if (OK != getStatValue (&success,
439 &lsuccess, 362 &lsuccess,
440 NULL, 363 NULL, "# gap routing successes (total)", YES))
441 "# gap routing successes (total)",
442 YES))
443 return SYSERR; 364 return SYSERR;
444 if (OK != getStatValue(&local, 365 if (OK != getStatValue (&local,
445 &llocal, 366 &llocal,
446 NULL, 367 NULL,
447 "# gap requests processed: local result", 368 "# gap requests processed: local result", YES))
448 YES))
449 return SYSERR; 369 return SYSERR;
450 total -= ltotal; 370 total -= ltotal;
451 data[0][0] = 0.0; 371 data[0][0] = 0.0;
452 if (ltotal + total > 0) { 372 if (ltotal + total > 0)
453 data[0][1] = lastavg = 1.0 * (success + lsuccess - local - llocal) / (total + ltotal); 373 {
454 } else { 374 data[0][1] = lastavg =
455 data[0][1] = 0.0; 375 1.0 * (success + lsuccess - local - llocal) / (total + ltotal);
456 return OK; 376 }
457 } 377 else
378 {
379 data[0][1] = 0.0;
380 return OK;
381 }
458 if (total == 0) 382 if (total == 0)
459 return OK; 383 return OK;
460 success -= lsuccess; 384 success -= lsuccess;
@@ -467,9 +391,9 @@ static int getEffectivenessStats(const void * closure,
467 return OK; 391 return OK;
468} 392}
469 393
470static int statsProcessor(const char * optName, 394static int
471 unsigned long long value, 395statsProcessor (const char *optName, unsigned long long value, void *data)
472 void * data) { 396{
473 /** 397 /**
474 * Keep track of last match (or, more precisely, position 398 * Keep track of last match (or, more precisely, position
475 * of next expected match) since 99.99% of the time we 399 * of next expected match) since 99.99% of the time we
@@ -477,7 +401,7 @@ static int statsProcessor(const char * optName,
477 * this will predict correctly). 401 * this will predict correctly).
478 */ 402 */
479 static unsigned int last; 403 static unsigned int last;
480 cron_t * delta = data; 404 cron_t *delta = data;
481 int j; 405 int j;
482 int found; 406 int found;
483 407
@@ -485,33 +409,28 @@ static int statsProcessor(const char * optName,
485 last = 0; 409 last = 0;
486 j = last; 410 j = last;
487 found = -1; 411 found = -1;
488 if ( (j < lsv_size) && 412 if ((j < lsv_size) && (0 == strcmp (optName, lastStatValues[j].statName)))
489 (0 == strcmp(optName,
490 lastStatValues[j].statName)) )
491 found = j; 413 found = j;
492 if (found == -1) { 414 if (found == -1)
493 for (j=0;j<lsv_size;j++) { 415 {
494 if (0 == strcmp(optName, 416 for (j = 0; j < lsv_size; j++)
495 lastStatValues[j].statName)) { 417 {
496 found = j; 418 if (0 == strcmp (optName, lastStatValues[j].statName))
497 break; 419 {
498 } 420 found = j;
421 break;
422 }
423 }
424 }
425 if (found == -1)
426 {
427 found = lsv_size;
428 GROW (lastStatValues, lsv_size, lsv_size + 1);
429 lastStatValues[found].statName = STRDUP (optName);
499 } 430 }
500 } 431 lastStatValues[found].lvalue = lastStatValues[found].value;
501 if (found == -1) { 432 lastStatValues[found].value = value;
502 found = lsv_size; 433 lastStatValues[found].delta = *delta;
503 GROW(lastStatValues,
504 lsv_size,
505 lsv_size+1);
506 lastStatValues[found].statName
507 = STRDUP(optName);
508 }
509 lastStatValues[found].lvalue
510 = lastStatValues[found].value;
511 lastStatValues[found].value
512 = value;
513 lastStatValues[found].delta
514 = *delta;
515 last = found + 1; 434 last = found + 1;
516 return OK; 435 return OK;
517} 436}
@@ -519,129 +438,127 @@ static int statsProcessor(const char * optName,
519/** 438/**
520 * Cron-job that updates all stat values. 439 * Cron-job that updates all stat values.
521 */ 440 */
522static void updateStatValues(void * unused) { 441static void
442updateStatValues (void *unused)
443{
523 static cron_t lastUpdate; 444 static cron_t lastUpdate;
524 cron_t now; 445 cron_t now;
525 cron_t delta; 446 cron_t delta;
526 447
527 now = get_time(); 448 now = get_time ();
528 delta = now - lastUpdate; 449 delta = now - lastUpdate;
529 MUTEX_LOCK(lock); 450 MUTEX_LOCK (lock);
530 if (OK == STATS_getStatistics(ectx, 451 if (OK == STATS_getStatistics (ectx, sock, &statsProcessor, &delta))
531 sock,
532 &statsProcessor,
533 &delta))
534 lastUpdate = now; 452 lastUpdate = now;
535 MUTEX_UNLOCK(lock); 453 MUTEX_UNLOCK (lock);
536} 454}
537 455
538 456
539StatEntry stats[] = { 457StatEntry stats[] = {
540 { 458 {
541 gettext_noop("Connectivity"), 459 gettext_noop ("Connectivity"),
542 gettext_noop("# connected nodes (100% = connection table size)"), 460 gettext_noop ("# connected nodes (100% = connection table size)"),
543 &getConnectedNodesStat, 461 &getConnectedNodesStat,
544 NULL, 462 NULL,
545 1, 463 1,
546 NO, 464 NO,
547 }, 465 }
466 ,
548 { 467 {
549 gettext_noop("System load"), 468 gettext_noop ("System load"),
550 gettext_noop("CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"), 469 gettext_noop
551 &getLoadStat, 470 ("CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"),
552 NULL, 471 &getLoadStat,
553 4, 472 NULL,
554 NO, 473 4,
555 }, 474 NO,
475 }
476 ,
556 { 477 {
557 gettext_noop("Datastore capacity"), 478 gettext_noop ("Datastore capacity"),
558 gettext_noop("Data in datastore (in percent of allowed quota)"), 479 gettext_noop ("Data in datastore (in percent of allowed quota)"),
559 &getQuotaStat, 480 &getQuotaStat,
560 NULL, 481 NULL,
561 1, 482 1,
562 NO, 483 NO,
563 }, 484 }
485 ,
564 { 486 {
565 gettext_noop("Inbound Traffic"), 487 gettext_noop ("Inbound Traffic"),
566 gettext_noop("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), 488 gettext_noop
567 &getTrafficRecvStats, 489 ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"),
568 NULL, 490 &getTrafficRecvStats,
569 6, 491 NULL,
570 5, 492 6,
571 }, 493 5,
494 }
495 ,
572 { 496 {
573 gettext_noop("Outbound Traffic"), 497 gettext_noop ("Outbound Traffic"),
574 gettext_noop("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), 498 gettext_noop
575 &getTrafficSendStats, 499 ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"),
576 NULL, 500 &getTrafficSendStats,
577 6, 501 NULL,
578 5, 502 6,
579 }, 503 5,
504 }
505 ,
580 { 506 {
581 gettext_noop("Routing Effectiveness"), 507 gettext_noop ("Routing Effectiveness"),
582 gettext_noop("Current (red) and average (green) effectiveness (100% = perfect)"), 508 gettext_noop
583 &getEffectivenessStats, 509 ("Current (red) and average (green) effectiveness (100% = perfect)"),
584 NULL, 510 &getEffectivenessStats,
585 2, 511 NULL,
586 NO, 512 2,
587 }, 513 NO,
514 }
515 ,
588 { 516 {
589 NULL, 517 NULL,
590 NULL, 518 NULL,
591 NULL, 519 NULL,
592 NULL, 520 NULL,
593 0, 521 0,
594 NO, 522 NO,
595 }, 523 }
524 ,
596}; 525};
597 526
598static unsigned long long UPDATE_INTERVAL; 527static unsigned long long UPDATE_INTERVAL;
599 528
600void init_functions(struct GE_Context * e, 529void
601 struct GC_Configuration * c) { 530init_functions (struct GE_Context *e, struct GC_Configuration *c)
531{
602 ectx = e; 532 ectx = e;
603 cfg = c; 533 cfg = c;
604 GC_get_configuration_value_number(cfg, 534 GC_get_configuration_value_number (cfg,
605 "GNUNET-GTK", 535 "GNUNET-GTK",
606 "STATS-INTERVAL", 536 "STATS-INTERVAL",
607 1, 537 1,
608 99 * cronYEARS, 538 99 * cronYEARS,
609 30 * cronSECONDS, 539 30 * cronSECONDS, &UPDATE_INTERVAL);
610 &UPDATE_INTERVAL); 540 sock = client_connection_create (ectx, cfg);
611 sock = client_connection_create(ectx, 541 lock = MUTEX_CREATE (NO);
612 cfg); 542 cron = gnunet_gtk_get_cron ();
613 lock = MUTEX_CREATE(NO); 543 cron_add_job (cron,
614 cron = gnunet_gtk_get_cron(); 544 &updateStatValues, UPDATE_INTERVAL, UPDATE_INTERVAL, NULL);
615 cron_add_job(cron, 545 cron_add_job (cron,
616 &updateStatValues, 546 &updateConnectionGoal,
617 UPDATE_INTERVAL, 547 5 * cronMINUTES, 5 * cronMINUTES, NULL);
618 UPDATE_INTERVAL,
619 NULL);
620 cron_add_job(cron,
621 &updateConnectionGoal,
622 5 * cronMINUTES,
623 5 * cronMINUTES,
624 NULL);
625} 548}
626 549
627void done_functions() { 550void
551done_functions ()
552{
628 int i; 553 int i;
629 554
630 cron_del_job(cron, 555 cron_del_job (cron, &updateConnectionGoal, 5 * cronMINUTES, NULL);
631 &updateConnectionGoal, 556 cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL);
632 5 * cronMINUTES, 557 MUTEX_DESTROY (lock);
633 NULL); 558 connection_destroy (sock);
634 cron_del_job(cron, 559 for (i = 0; i < lsv_size; i++)
635 &updateStatValues, 560 FREE (lastStatValues[i].statName);
636 UPDATE_INTERVAL, 561 GROW (lastStatValues, lsv_size, 0);
637 NULL);
638 MUTEX_DESTROY(lock);
639 connection_destroy(sock);
640 for (i=0;i<lsv_size;i++)
641 FREE(lastStatValues[i].statName);
642 GROW(lastStatValues,
643 lsv_size,
644 0);
645 sock = NULL; 562 sock = NULL;
646} 563}
647 564