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.c142
1 files changed, 88 insertions, 54 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index 6242637b..c586b0fa 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -68,15 +68,16 @@ getStatValue (long long *value,
68 *lvalue = lastStatValues[i].lvalue; 68 *lvalue = lastStatValues[i].lvalue;
69 if (dtime != NULL) 69 if (dtime != NULL)
70 *dtime = lastStatValues[i].delta; 70 *dtime = lastStatValues[i].delta;
71 if ((monotone == GNUNET_YES) && (lvalue != NULL) && (*lvalue > *value)) 71 if ((monotone == GNUNET_YES) && (lvalue != NULL)
72 return GNUNET_SYSERR; /* gnunetd restart? */ 72 && (*lvalue > *value))
73 return GNUNET_SYSERR; /* gnunetd restart? */
73 return GNUNET_OK; 74 return GNUNET_OK;
74 } 75 }
75 } 76 }
76#if FUNCTIONS_DEBUG 77#if FUNCTIONS_DEBUG
77 GNUNET_GELOG (ectx, 78 GNUNET_GELOG (ectx,
78 GNUNET_GEDEBUG | GNUNET_GEDEVELOPER | GNUNET_GEREQUEST, 79 GNUNET_GEDEBUG | GNUNET_GEDEVELOPER | GNUNET_GEREQUEST,
79 "Statistic not found: `%s'\n", optName); 80 "Statistic not found: `%s'\n", optName);
80#endif 81#endif
81 return GNUNET_SYSERR; 82 return GNUNET_SYSERR;
82} 83}
@@ -89,11 +90,14 @@ updateConnectionGoal (void *unused)
89 char *availableUp; 90 char *availableUp;
90 91
91 GNUNET_mutex_lock (lock); 92 GNUNET_mutex_lock (lock);
92 cmh = GNUNET_get_daemon_configuration_value (sock, "gnunetd", "connection-max-hosts"); 93 cmh =
93 availableDown = GNUNET_get_daemon_configuration_value (sock, 94 GNUNET_get_daemon_configuration_value (sock, "gnunetd",
94 "LOAD", "MAXNETDOWNBPSTOTAL"); 95 "connection-max-hosts");
95 availableUp = GNUNET_get_daemon_configuration_value (sock, 96 availableDown =
96 "LOAD", "MAXNETUPBPSTOTAL"); 97 GNUNET_get_daemon_configuration_value (sock, "LOAD",
98 "MAXNETDOWNBPSTOTAL");
99 availableUp =
100 GNUNET_get_daemon_configuration_value (sock, "LOAD", "MAXNETUPBPSTOTAL");
97 GNUNET_mutex_unlock (lock); 101 GNUNET_mutex_unlock (lock);
98 if (cmh == NULL) 102 if (cmh == NULL)
99 connectionGoal = 0; 103 connectionGoal = 0;
@@ -120,7 +124,8 @@ getConnectedNodesStat (const void *closure, gfloat ** data)
120 124
121 if (connectionGoal == 0) 125 if (connectionGoal == 0)
122 return GNUNET_SYSERR; 126 return GNUNET_SYSERR;
123 if (GNUNET_OK != getStatValue (&val, NULL, NULL, "# of connected peers", GNUNET_NO)) 127 if (GNUNET_OK !=
128 getStatValue (&val, NULL, NULL, "# of connected peers", GNUNET_NO))
124 return GNUNET_SYSERR; 129 return GNUNET_SYSERR;
125 data[0][0] = ((gfloat) val) / connectionGoal; 130 data[0][0] = ((gfloat) val) / connectionGoal;
126 return GNUNET_OK; 131 return GNUNET_OK;
@@ -134,15 +139,20 @@ getLoadStat (const void *closure, gfloat ** data)
134 long long valu; 139 long long valu;
135 long long vald; 140 long long vald;
136 141
137 if (GNUNET_OK != getStatValue (&valc, NULL, NULL, "% of allowed cpu load", GNUNET_NO)) 142 if (GNUNET_OK !=
143 getStatValue (&valc, NULL, NULL, "% of allowed cpu load", GNUNET_NO))
138 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
139 if (GNUNET_OK != getStatValue (&vali, NULL, NULL, "% of allowed io load", GNUNET_NO)) 145 if (GNUNET_OK !=
146 getStatValue (&vali, NULL, NULL, "% of allowed io load", GNUNET_NO))
140 return GNUNET_SYSERR; 147 return GNUNET_SYSERR;
141 if (GNUNET_OK != getStatValue (&valu, 148 if (GNUNET_OK != getStatValue (&valu,
142 NULL, NULL, "% of allowed network load (up)", GNUNET_NO)) 149 NULL, NULL, "% of allowed network load (up)",
150 GNUNET_NO))
143 return GNUNET_SYSERR; 151 return GNUNET_SYSERR;
144 if (GNUNET_OK != getStatValue (&vald, 152 if (GNUNET_OK != getStatValue (&vald,
145 NULL, NULL, "% of allowed network load (down)", GNUNET_NO)) 153 NULL, NULL,
154 "% of allowed network load (down)",
155 GNUNET_NO))
146 return GNUNET_SYSERR; 156 return GNUNET_SYSERR;
147 data[0][0] = (gfloat) valc / 100.0; 157 data[0][0] = (gfloat) valc / 100.0;
148 data[0][1] = (gfloat) vali / 100.0; 158 data[0][1] = (gfloat) vali / 100.0;
@@ -158,11 +168,13 @@ getQuotaStat (const void *closure, gfloat ** data)
158 long long have; 168 long long have;
159 169
160 if (GNUNET_OK != getStatValue (&allowed, 170 if (GNUNET_OK != getStatValue (&allowed,
161 NULL, NULL, "# bytes allowed in datastore", GNUNET_NO)) 171 NULL, NULL, "# bytes allowed in datastore",
172 GNUNET_NO))
162 return GNUNET_SYSERR; 173 return GNUNET_SYSERR;
163 if (allowed == 0) 174 if (allowed == 0)
164 return GNUNET_SYSERR; 175 return GNUNET_SYSERR;
165 if (GNUNET_OK != getStatValue (&have, NULL, NULL, "# bytes in datastore", GNUNET_NO)) 176 if (GNUNET_OK !=
177 getStatValue (&have, NULL, NULL, "# bytes in datastore", GNUNET_NO))
166 return GNUNET_SYSERR; 178 return GNUNET_SYSERR;
167 data[0][0] = ((gfloat) have) / allowed; 179 data[0][0] = ((gfloat) have) / allowed;
168 return GNUNET_OK; 180 return GNUNET_OK;
@@ -186,33 +198,42 @@ getTrafficRecvStats (const void *closure, gfloat ** data)
186 GNUNET_CronTime dtime; 198 GNUNET_CronTime dtime;
187 char *buffer; 199 char *buffer;
188 200
189 if (GNUNET_OK != getStatValue (&total, &ltotal, &dtime, "# bytes received", GNUNET_YES)) 201 if (GNUNET_OK !=
202 getStatValue (&total, &ltotal, &dtime, "# bytes received", GNUNET_YES))
190 return GNUNET_SYSERR; 203 return GNUNET_SYSERR;
191 if (GNUNET_OK != getStatValue (&noise, 204 if (GNUNET_OK != getStatValue (&noise,
192 &lnoise, NULL, "# bytes of noise received", GNUNET_YES)) 205 &lnoise, NULL, "# bytes of noise received",
206 GNUNET_YES))
193 return GNUNET_SYSERR; 207 return GNUNET_SYSERR;
194 buffer = GNUNET_malloc (512); 208 buffer = GNUNET_malloc (512);
195 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", GNUNET_P2P_PROTO_GAP_RESULT); 209 GNUNET_snprintf (buffer, 512, "# bytes received of type %d",
196 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES)) 210 GNUNET_P2P_PROTO_GAP_RESULT);
211 if (GNUNET_OK !=
212 getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES))
197 { 213 {
198 content = 0; 214 content = 0;
199 lcontent = 0; 215 lcontent = 0;
200 } 216 }
201 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", GNUNET_P2P_PROTO_HELLO); 217 GNUNET_snprintf (buffer, 512, "# bytes received of type %d",
218 GNUNET_P2P_PROTO_HELLO);
202 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES)) 219 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES))
203 { 220 {
204 hellos = 0; 221 hellos = 0;
205 lhellos = 0; 222 lhellos = 0;
206 } 223 }
207 GNUNET_snprintf (buffer, 512, "# bytes received of type %d", GNUNET_P2P_PROTO_GAP_QUERY); 224 GNUNET_snprintf (buffer, 512, "# bytes received of type %d",
208 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES)) 225 GNUNET_P2P_PROTO_GAP_QUERY);
226 if (GNUNET_OK !=
227 getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES))
209 { 228 {
210 queries = 0; 229 queries = 0;
211 lqueries = 0; 230 lqueries = 0;
212 } 231 }
213 if (GNUNET_OK != getStatValue (&rlimit, 232 if (GNUNET_OK != getStatValue (&rlimit,
214 &lrlimit, 233 &lrlimit,
215 NULL, "# total bytes per second receive limit", GNUNET_NO)) 234 NULL,
235 "# total bytes per second receive limit",
236 GNUNET_NO))
216 { 237 {
217 rlimit = 0; 238 rlimit = 0;
218 lrlimit = 0; 239 lrlimit = 0;
@@ -267,34 +288,42 @@ getTrafficSendStats (const void *closure, gfloat ** data)
267 char *buffer; 288 char *buffer;
268 289
269 if (GNUNET_OK != getStatValue (&total, 290 if (GNUNET_OK != getStatValue (&total,
270 &ltotal, &dtime, "# bytes transmitted", GNUNET_YES)) 291 &ltotal, &dtime, "# bytes transmitted",
292 GNUNET_YES))
271 return GNUNET_SYSERR; 293 return GNUNET_SYSERR;
272 if (GNUNET_OK != getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", GNUNET_YES)) 294 if (GNUNET_OK !=
295 getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", GNUNET_YES))
273 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
274 buffer = GNUNET_malloc (512); 297 buffer = GNUNET_malloc (512);
275 GNUNET_snprintf (buffer, 298 GNUNET_snprintf (buffer,
276 512, "# bytes transmitted of type %d", GNUNET_P2P_PROTO_GAP_RESULT); 299 512, "# bytes transmitted of type %d",
277 if (GNUNET_OK != getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES)) 300 GNUNET_P2P_PROTO_GAP_RESULT);
301 if (GNUNET_OK !=
302 getStatValue (&content, &lcontent, NULL, buffer, GNUNET_YES))
278 { 303 {
279 content = 0; 304 content = 0;
280 lcontent = 0; 305 lcontent = 0;
281 } 306 }
282 GNUNET_snprintf (buffer, 307 GNUNET_snprintf (buffer,
283 512, "# bytes transmitted of type %d", GNUNET_P2P_PROTO_GAP_QUERY); 308 512, "# bytes transmitted of type %d",
284 if (GNUNET_OK != getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES)) 309 GNUNET_P2P_PROTO_GAP_QUERY);
310 if (GNUNET_OK !=
311 getStatValue (&queries, &lqueries, NULL, buffer, GNUNET_YES))
285 { 312 {
286 queries = 0; 313 queries = 0;
287 lqueries = 0; 314 lqueries = 0;
288 } 315 }
289 GNUNET_snprintf (buffer, 512, "# bytes transmitted of type %d", GNUNET_P2P_PROTO_HELLO); 316 GNUNET_snprintf (buffer, 512, "# bytes transmitted of type %d",
317 GNUNET_P2P_PROTO_HELLO);
290 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES)) 318 if (GNUNET_OK != getStatValue (&hellos, &lhellos, NULL, buffer, GNUNET_YES))
291 { 319 {
292 queries = 0; 320 queries = 0;
293 lqueries = 0; 321 lqueries = 0;
294 } 322 }
295 if (GNUNET_OK != getStatValue (&slimit, 323 if (GNUNET_OK != getStatValue (&slimit,
296 &lslimit, 324 &lslimit,
297 NULL, "# total bytes per second send limit", GNUNET_NO)) 325 NULL, "# total bytes per second send limit",
326 GNUNET_NO))
298 { 327 {
299 slimit = 0; 328 slimit = 0;
300 lslimit = 0; 329 lslimit = 0;
@@ -353,19 +382,21 @@ getEffectivenessStats (const void *closure, gfloat ** data)
353 } 382 }
354 last = now; 383 last = now;
355 if (GNUNET_OK != getStatValue (&total, 384 if (GNUNET_OK != getStatValue (&total,
356 &ltotal, 385 &ltotal,
357 NULL, 386 NULL,
358 "# gap requests forwarded (counting each peer)", 387 "# gap requests forwarded (counting each peer)",
359 GNUNET_YES)) 388 GNUNET_YES))
360 return GNUNET_SYSERR; 389 return GNUNET_SYSERR;
361 if (GNUNET_OK != getStatValue (&success, 390 if (GNUNET_OK != getStatValue (&success,
362 &lsuccess, 391 &lsuccess,
363 NULL, "# gap routing successes (total)", GNUNET_YES)) 392 NULL, "# gap routing successes (total)",
393 GNUNET_YES))
364 return GNUNET_SYSERR; 394 return GNUNET_SYSERR;
365 if (GNUNET_OK != getStatValue (&local, 395 if (GNUNET_OK != getStatValue (&local,
366 &llocal, 396 &llocal,
367 NULL, 397 NULL,
368 "# gap requests processed: local result", GNUNET_YES)) 398 "# gap requests processed: local result",
399 GNUNET_YES))
369 return GNUNET_SYSERR; 400 return GNUNET_SYSERR;
370 total -= ltotal; 401 total -= ltotal;
371 data[0][0] = 0.0; 402 data[0][0] = 0.0;
@@ -448,7 +479,8 @@ updateStatValues (void *unused)
448 now = GNUNET_get_time (); 479 now = GNUNET_get_time ();
449 delta = now - lastUpdate; 480 delta = now - lastUpdate;
450 GNUNET_mutex_lock (lock); 481 GNUNET_mutex_lock (lock);
451 if (GNUNET_OK == GNUNET_STATS_get_statistics (ectx, sock, &statsProcessor, &delta)) 482 if (GNUNET_OK ==
483 GNUNET_STATS_get_statistics (ectx, sock, &statsProcessor, &delta))
452 lastUpdate = now; 484 lastUpdate = now;
453 GNUNET_mutex_unlock (lock); 485 GNUNET_mutex_unlock (lock);
454} 486}
@@ -532,19 +564,20 @@ init_functions (struct GNUNET_GEContext *e, struct GNUNET_GC_Configuration *c)
532 ectx = e; 564 ectx = e;
533 cfg = c; 565 cfg = c;
534 GNUNET_GC_get_configuration_value_number (cfg, 566 GNUNET_GC_get_configuration_value_number (cfg,
535 "GNUNET-GTK", 567 "GNUNET-GTK",
536 "STATS-INTERVAL", 568 "STATS-INTERVAL",
537 1, 569 1,
538 99 * GNUNET_CRON_YEARS, 570 99 * GNUNET_CRON_YEARS,
539 30 * GNUNET_CRON_SECONDS, &UPDATE_INTERVAL); 571 30 * GNUNET_CRON_SECONDS,
572 &UPDATE_INTERVAL);
540 sock = GNUNET_client_connection_create (ectx, cfg); 573 sock = GNUNET_client_connection_create (ectx, cfg);
541 lock = GNUNET_mutex_create (GNUNET_NO); 574 lock = GNUNET_mutex_create (GNUNET_NO);
542 cron = GNUNET_GTK_get_cron_manager (); 575 cron = GNUNET_GTK_get_cron_manager ();
543 GNUNET_cron_add_job (cron, 576 GNUNET_cron_add_job (cron,
544 &updateStatValues, UPDATE_INTERVAL, UPDATE_INTERVAL, NULL); 577 &updateStatValues, UPDATE_INTERVAL, UPDATE_INTERVAL,
545 GNUNET_cron_add_job (cron, 578 NULL);
546 &updateConnectionGoal, 579 GNUNET_cron_add_job (cron, &updateConnectionGoal, 5 * GNUNET_CRON_MINUTES,
547 5 * GNUNET_CRON_MINUTES, 5 * GNUNET_CRON_MINUTES, NULL); 580 5 * GNUNET_CRON_MINUTES, NULL);
548} 581}
549 582
550void 583void
@@ -552,7 +585,8 @@ done_functions ()
552{ 585{
553 int i; 586 int i;
554 587
555 GNUNET_cron_del_job (cron, &updateConnectionGoal, 5 * GNUNET_CRON_MINUTES, NULL); 588 GNUNET_cron_del_job (cron, &updateConnectionGoal, 5 * GNUNET_CRON_MINUTES,
589 NULL);
556 GNUNET_cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL); 590 GNUNET_cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL);
557 GNUNET_mutex_destroy (lock); 591 GNUNET_mutex_destroy (lock);
558 GNUNET_client_connection_destroy (sock); 592 GNUNET_client_connection_destroy (sock);