summaryrefslogtreecommitdiff
path: root/ot_stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_stats.c')
-rw-r--r--ot_stats.c83
1 files changed, 31 insertions, 52 deletions
diff --git a/ot_stats.c b/ot_stats.c
index 518dbb5..9ce985f 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -48,6 +48,7 @@ static unsigned long long ot_full_scrape_count = 0;
48static unsigned long long ot_full_scrape_request_count = 0; 48static unsigned long long ot_full_scrape_request_count = 0;
49static unsigned long long ot_full_scrape_size = 0; 49static unsigned long long ot_full_scrape_size = 0;
50static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; 50static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
51static char * ot_failed_request_names[] = { "302 Redirect", "400 Parse Error", "400 Invalid Parameter", "400 Invalid Parameter (compact=0)", "403 Access Denied", "404 Not found", "500 Internal Server Error" };
51static unsigned long long ot_renewed[OT_PEER_TIMEOUT]; 52static unsigned long long ot_renewed[OT_PEER_TIMEOUT];
52static unsigned long long ot_overall_sync_count; 53static unsigned long long ot_overall_sync_count;
53static unsigned long long ot_overall_stall_count; 54static unsigned long long ot_overall_stall_count;
@@ -314,14 +315,6 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh )
314 return 0; 315 return 0;
315} 316}
316 317
317/*
318 struct {
319 size_t size
320 size_t space
321 size_t count
322 }
323 */
324
325static unsigned long events_per_time( unsigned long long events, time_t t ) { 318static unsigned long events_per_time( unsigned long long events, time_t t ) {
326 return events / ( (unsigned int)t ? (unsigned int)t : 1 ); 319 return events / ( (unsigned int)t ? (unsigned int)t : 1 );
327} 320}
@@ -402,42 +395,6 @@ static size_t stats_peers_mrtg( char * reply ) {
402 ); 395 );
403} 396}
404 397
405static size_t stats_startstop_mrtg( char * reply )
406{
407 size_t torrent_count = mutex_get_torrent_count();
408
409 return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker",
410 (size_t)0,
411 (size_t)0,
412 torrent_count
413 );
414}
415
416static size_t stats_toraddrem_mrtg( char * reply )
417{
418 size_t peer_count = 0, j;
419 int bucket;
420
421 for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket )
422 {
423 ot_vector *torrents_list = mutex_bucket_lock( bucket );
424 for( j=0; j<torrents_list->size; ++j )
425 {
426 ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
427 peer_count += peer_list->peer_count;
428 }
429 mutex_bucket_unlock( bucket, 0 );
430 if( !g_opentracker_running )
431 return 0;
432 }
433
434 return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker",
435 (size_t)0,
436 (size_t)0,
437 peer_count
438 );
439}
440
441static size_t stats_torrents_mrtg( char * reply ) 398static size_t stats_torrents_mrtg( char * reply )
442{ 399{
443 size_t torrent_count = mutex_get_torrent_count(); 400 size_t torrent_count = mutex_get_torrent_count();
@@ -479,13 +436,38 @@ static size_t stats_return_sync_mrtg( char * reply ) {
479} 436}
480 437
481static size_t stats_return_everything( char * reply ) { 438static size_t stats_return_everything( char * reply ) {
439 torrent_stats stats = {0,0,0};
440 int i;
482 char * r = reply; 441 char * r = reply;
442
443 iterate_all_torrents( torrent_statter, (uintptr_t)&stats );
444
445 r += sprintf( r, "<version>\n" ); r += stats_return_tracker_version( r ); r += sprintf( r, "</version>\n" );
483 r += sprintf( r, "<stats>\n" ); 446 r += sprintf( r, "<stats>\n" );
484 r += sprintf( r, " <uptime>%llu</uptime>\n", (unsigned long long)(time( NULL ) - ot_start_time) ); 447 r += sprintf( r, " <uptime>%llu</uptime>\n", (unsigned long long)(time( NULL ) - ot_start_time) );
485 r += sprintf( r, " <torrents>%zd</torrents>\n", mutex_get_torrent_count() ); 448 r += sprintf( r, " <torrents>\n" );
486 /* r += sprintf( r, " <peers>%llu</peers>\n", ); */ 449 r += sprintf( r, " <count_mutex>%zd</count_mutex>\n", mutex_get_torrent_count() );
487 450 r += sprintf( r, " <count_iterator>%llu</count_iterator>\n", stats.torrent_count );
488 r += sprintf( reply, "</stats>" ); 451 r += sprintf( r, " </torrents>\n" );
452 r += sprintf( r, " <peers>\n <count>%llu</count>\n </peers>\n", stats.peer_count );
453 r += sprintf( r, " <seeds>\n <count>%llu</count>\n </seeds>\n", stats.seed_count );
454 r += sprintf( r, " <connections>\n" );
455 r += sprintf( r, " <tcp>\n <accept>%llu</accept>\n <announce>%llu</announce>\n <scrape>%llu</scrape>\n </tcp>\n", ot_overall_tcp_connections, ot_overall_tcp_successfulannounces, ot_overall_udp_successfulscrapes );
456 r += sprintf( r, " <udp>\n <overall>%llu</overall>\n <connect>%llu</connect>\n <announce>%llu</announce>\n <scrape>%llu</scrape>\n </tcp>\n", ot_overall_udp_connections, ot_overall_udp_connects, ot_overall_udp_successfulannounces, ot_overall_udp_successfulscrapes );
457 r += sprintf( r, " <livesync>\n <count>%llu</count>\n </livesync>\n", ot_overall_sync_count );
458 r += sprintf( r, " </connections>\n" );
459 r += sprintf( r, " <debug>\n" );
460 r += sprintf( r, " <renew>\n" );
461 for( i=0; i<OT_PEER_TIMEOUT; ++i )
462 r += sprintf( r, " <count interval=\"%02i\">%llu</count>\n", i, ot_renewed[i] );
463 r += sprintf( r, " </renew>\n" );
464 r += sprintf( r, " <http_error>\n" );
465 for( i=0; i<CODE_HTTPERROR_COUNT; ++i )
466 r += sprintf( r, " <count code=\"%s\">%llu</count>\n", ot_failed_request_names[i], ot_failed_request_counts[i] );
467 r += sprintf( r, " </http_error>\n" );
468 r += sprintf( r, " <mutex_stall>\n <count>%llu</count>\n </mutex_stall>\n", ot_overall_stall_count );
469 r += sprintf( r, " </debug>\n" );
470 r += sprintf( r, "</stats>" );
489 return r - reply; 471 return r - reply;
490} 472}
491 473
@@ -512,10 +494,6 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
512 return stats_udpconnections_mrtg( reply ); 494 return stats_udpconnections_mrtg( reply );
513 case TASK_STATS_TCP: 495 case TASK_STATS_TCP:
514 return stats_tcpconnections_mrtg( reply ); 496 return stats_tcpconnections_mrtg( reply );
515 case TASK_STATS_TORADDREM:
516 return stats_toraddrem_mrtg( reply );
517 case TASK_STATS_STARTSTOP:
518 return stats_startstop_mrtg( reply );
519 case TASK_STATS_FULLSCRAPE: 497 case TASK_STATS_FULLSCRAPE:
520 return stats_fullscrapes_mrtg( reply ); 498 return stats_fullscrapes_mrtg( reply );
521 case TASK_STATS_HTTPERRORS: 499 case TASK_STATS_HTTPERRORS:
@@ -548,6 +526,7 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype
548 case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break; 526 case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break;
549 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 25, 16 ); break; 527 case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 25, 16 ); break;
550 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; 528 case TASK_STATS_TOP10: r += stats_top10_txt( r ); break;
529 case TASK_STATS_EVERYTHING: r += stats_return_everything( r ); break;
551 default: 530 default:
552 iovec_free(iovec_entries, iovector); 531 iovec_free(iovec_entries, iovector);
553 return; 532 return;