diff options
Diffstat (limited to 'ot_stats.c')
| -rw-r--r-- | ot_stats.c | 71 |
1 files changed, 12 insertions, 59 deletions
| @@ -46,7 +46,7 @@ static unsigned long long ot_full_scrape_count = 0; | |||
| 46 | static unsigned long long ot_full_scrape_request_count = 0; | 46 | static unsigned long long ot_full_scrape_request_count = 0; |
| 47 | static unsigned long long ot_full_scrape_size = 0; | 47 | static unsigned long long ot_full_scrape_size = 0; |
| 48 | static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; | 48 | static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; |
| 49 | static unsigned long long ot_renewed[OT_POOLS_COUNT]; | 49 | static unsigned long long ot_renewed[OT_PEER_TIMEOUT]; |
| 50 | 50 | ||
| 51 | static time_t ot_start_time; | 51 | static time_t ot_start_time; |
| 52 | 52 | ||
| @@ -214,7 +214,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
| 214 | 214 | ||
| 215 | uint32_t *counts[ NUM_BUFS ]; | 215 | uint32_t *counts[ NUM_BUFS ]; |
| 216 | uint32_t slash24s[amount*2]; /* first dword amount, second dword subnet */ | 216 | uint32_t slash24s[amount*2]; /* first dword amount, second dword subnet */ |
| 217 | int bucket; | 217 | // int bucket; |
| 218 | size_t i, j, k, l; | 218 | size_t i, j, k, l; |
| 219 | char *r = reply; | 219 | char *r = reply; |
| 220 | 220 | ||
| @@ -223,6 +223,8 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
| 223 | 223 | ||
| 224 | r += sprintf( r, "Stats for all /24s with more than %u announced torrents:\n\n", thresh ); | 224 | r += sprintf( r, "Stats for all /24s with more than %u announced torrents:\n\n", thresh ); |
| 225 | 225 | ||
| 226 | #if 0 | ||
| 227 | /* XXX: TOOD: Doesn't work yet with new peer storage model */ | ||
| 226 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | 228 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { |
| 227 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | 229 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); |
| 228 | for( j=0; j<torrents_list->size; ++j ) { | 230 | for( j=0; j<torrents_list->size; ++j ) { |
| @@ -248,6 +250,7 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
| 248 | } | 250 | } |
| 249 | mutex_bucket_unlock( bucket ); | 251 | mutex_bucket_unlock( bucket ); |
| 250 | } | 252 | } |
| 253 | #endif | ||
| 251 | 254 | ||
| 252 | k = l = 0; /* Debug: count allocated bufs */ | 255 | k = l = 0; /* Debug: count allocated bufs */ |
| 253 | for( i=0; i < NUM_BUFS; ++i ) { | 256 | for( i=0; i < NUM_BUFS; ++i ) { |
| @@ -283,8 +286,6 @@ static size_t stats_slash24s_txt( char * reply, size_t amount, uint32_t thresh ) | |||
| 283 | 286 | ||
| 284 | return r - reply; | 287 | return r - reply; |
| 285 | 288 | ||
| 286 | bailout_cleanup: | ||
| 287 | |||
| 288 | for( i=0; i < NUM_BUFS; ++i ) | 289 | for( i=0; i < NUM_BUFS; ++i ) |
| 289 | free( counts[i] ); | 290 | free( counts[i] ); |
| 290 | 291 | ||
| @@ -299,44 +300,6 @@ bailout_cleanup: | |||
| 299 | } | 300 | } |
| 300 | */ | 301 | */ |
| 301 | 302 | ||
| 302 | static ssize_t stats_vector_usage( char * reply ) { | ||
| 303 | size_t i, j, *vec_member; | ||
| 304 | char *r = reply; | ||
| 305 | int exactmatch, bucket; | ||
| 306 | |||
| 307 | ot_vector bucketsizes; | ||
| 308 | memset( &bucketsizes, 0, sizeof( bucketsizes )); | ||
| 309 | |||
| 310 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) { | ||
| 311 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | ||
| 312 | for( i=0; i<torrents_list->size; ++i ) { | ||
| 313 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[i] ).peer_list; | ||
| 314 | for( j=0; j<OT_POOLS_COUNT; ++j ) { | ||
| 315 | if( ! ( vec_member = vector_find_or_insert(&bucketsizes, &peer_list->peers[j].size, 3 * sizeof( size_t ), 2 * sizeof(size_t), &exactmatch) ) ) { | ||
| 316 | mutex_bucket_unlock( bucket ); | ||
| 317 | return 0; | ||
| 318 | } | ||
| 319 | if( !exactmatch ) { | ||
| 320 | vec_member[0] = peer_list->peers[j].size; | ||
| 321 | vec_member[1] = peer_list->peers[j].space; | ||
| 322 | vec_member[2] = 1; | ||
| 323 | } else | ||
| 324 | ++vec_member[2]; | ||
| 325 | } | ||
| 326 | } | ||
| 327 | mutex_bucket_unlock( bucket ); | ||
| 328 | } | ||
| 329 | |||
| 330 | for( i = 0; i<bucketsizes.size; ++i ) { | ||
| 331 | r += sprintf( r, "%zd\t%zd\t%zd\n", ((size_t*)bucketsizes.data)[3*i], ((size_t*)bucketsizes.data)[3*i+1], ((size_t*)bucketsizes.data)[3*i+2] ); | ||
| 332 | /* Prevent overflow. 8k should be enough for debugging */ | ||
| 333 | if( r - reply > OT_STATS_TMPSIZE - 3*10+3 /* 3*%zd + 2*\t + \n */ ) | ||
| 334 | break; | ||
| 335 | } | ||
| 336 | |||
| 337 | return r - reply; | ||
| 338 | } | ||
| 339 | |||
| 340 | static unsigned long events_per_time( unsigned long long events, time_t t ) { | 303 | static unsigned long events_per_time( unsigned long long events, time_t t ) { |
| 341 | return events / ( (unsigned int)t ? (unsigned int)t : 1 ); | 304 | return events / ( (unsigned int)t ? (unsigned int)t : 1 ); |
| 342 | } | 305 | } |
| @@ -497,20 +460,20 @@ static size_t stats_return_renew_bucket( char * reply ) { | |||
| 497 | char *r = reply; | 460 | char *r = reply; |
| 498 | int i; | 461 | int i; |
| 499 | 462 | ||
| 500 | for( i=0; i<OT_POOLS_COUNT; ++i ) | 463 | for( i=0; i<OT_PEER_TIMEOUT; ++i ) |
| 501 | r+=sprintf(r,"%02i %llu\n", i, ot_renewed[i] ); | 464 | r+=sprintf(r,"%02i %llu\n", i, ot_renewed[i] ); |
| 502 | return r - reply; | 465 | return r - reply; |
| 503 | } | 466 | } |
| 504 | 467 | ||
| 505 | extern const char | 468 | extern const char |
| 506 | *g_version_opentracker_c, *g_version_accesslist_c, *g_version_clean_c, *g_version_fullscrape_c, *g_version_http_c, | 469 | *g_version_opentracker_c, *g_version_accesslist_c, *g_version_clean_c, *g_version_fullscrape_c, *g_version_http_c, |
| 507 | *g_version_iovec_c, *g_version_mutex_c, *g_version_stats_c, *g_version_sync_c, *g_version_udp_c, *g_version_vector_c, | 470 | *g_version_iovec_c, *g_version_mutex_c, *g_version_stats_c, *g_version_udp_c, *g_version_vector_c, |
| 508 | *g_version_scan_urlencoded_query_c, *g_version_trackerlogic_c, *g_version_livesync_c; | 471 | *g_version_scan_urlencoded_query_c, *g_version_trackerlogic_c, *g_version_livesync_c; |
| 509 | 472 | ||
| 510 | size_t stats_return_tracker_version( char *reply ) { | 473 | size_t stats_return_tracker_version( char *reply ) { |
| 511 | return sprintf( reply, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", | 474 | return sprintf( reply, "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
| 512 | g_version_opentracker_c, g_version_accesslist_c, g_version_clean_c, g_version_fullscrape_c, g_version_http_c, | 475 | g_version_opentracker_c, g_version_accesslist_c, g_version_clean_c, g_version_fullscrape_c, g_version_http_c, |
| 513 | g_version_iovec_c, g_version_mutex_c, g_version_stats_c, g_version_sync_c, g_version_udp_c, g_version_vector_c, | 476 | g_version_iovec_c, g_version_mutex_c, g_version_stats_c, g_version_udp_c, g_version_vector_c, |
| 514 | g_version_scan_urlencoded_query_c, g_version_trackerlogic_c, g_version_livesync_c ); | 477 | g_version_scan_urlencoded_query_c, g_version_trackerlogic_c, g_version_livesync_c ); |
| 515 | } | 478 | } |
| 516 | 479 | ||
| @@ -541,10 +504,6 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) { | |||
| 541 | case TASK_STATS_BUSY_NETWORKS: | 504 | case TASK_STATS_BUSY_NETWORKS: |
| 542 | return stats_return_busy_networks( reply ); | 505 | return stats_return_busy_networks( reply ); |
| 543 | #endif | 506 | #endif |
| 544 | #ifdef _DEBUG_VECTOR | ||
| 545 | case TASK_STATS_VECTOR_DEBUG: | ||
| 546 | return vector_info( reply ); | ||
| 547 | #endif | ||
| 548 | default: | 507 | default: |
| 549 | return 0; | 508 | return 0; |
| 550 | } | 509 | } |
| @@ -563,7 +522,6 @@ static void stats_make( int *iovec_entries, struct iovec **iovector, ot_tasktype | |||
| 563 | case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break; | 522 | case TASK_STATS_PEERS: r += stats_peers_mrtg( r ); break; |
| 564 | case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 25, 16 ); break; | 523 | case TASK_STATS_SLASH24S: r += stats_slash24s_txt( r, 25, 16 ); break; |
| 565 | case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; | 524 | case TASK_STATS_TOP10: r += stats_top10_txt( r ); break; |
| 566 | case TASK_STATS_MEMORY: r += stats_vector_usage( r ); break; | ||
| 567 | default: | 525 | default: |
| 568 | iovec_free(iovec_entries, iovector); | 526 | iovec_free(iovec_entries, iovector); |
| 569 | return; | 527 | return; |
| @@ -594,14 +552,14 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uint32_t event_ | |||
| 594 | case EVENT_FULLSCRAPE_REQUEST: | 552 | case EVENT_FULLSCRAPE_REQUEST: |
| 595 | { | 553 | { |
| 596 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ | 554 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ |
| 597 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE\n", (unsigned int)(g_now - ot_start_time), ip[0], ip[1], ip[2], ip[3] ); | 555 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE\n", (unsigned int)(g_now_seconds - ot_start_time)/60, ip[0], ip[1], ip[2], ip[3] ); |
| 598 | ot_full_scrape_request_count++; | 556 | ot_full_scrape_request_count++; |
| 599 | } | 557 | } |
| 600 | break; | 558 | break; |
| 601 | case EVENT_FULLSCRAPE_REQUEST_GZIP: | 559 | case EVENT_FULLSCRAPE_REQUEST_GZIP: |
| 602 | { | 560 | { |
| 603 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ | 561 | uint8_t ip[4]; *(uint32_t*)ip = (uint32_t)proto; /* ugly hack to transfer ip to stats */ |
| 604 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now - ot_start_time), ip[0], ip[1], ip[2], ip[3] ); | 562 | LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now_seconds - ot_start_time)/60, ip[0], ip[1], ip[2], ip[3] ); |
| 605 | ot_full_scrape_request_count++; | 563 | ot_full_scrape_request_count++; |
| 606 | } | 564 | } |
| 607 | break; | 565 | break; |
| @@ -611,11 +569,6 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uint32_t event_ | |||
| 611 | case EVENT_RENEW: | 569 | case EVENT_RENEW: |
| 612 | ot_renewed[event_data]++; | 570 | ot_renewed[event_data]++; |
| 613 | break; | 571 | break; |
| 614 | case EVENT_SYNC_IN_REQUEST: | ||
| 615 | case EVENT_SYNC_IN: | ||
| 616 | case EVENT_SYNC_OUT_REQUEST: | ||
| 617 | case EVENT_SYNC_OUT: | ||
| 618 | break; | ||
| 619 | default: | 572 | default: |
| 620 | break; | 573 | break; |
| 621 | } | 574 | } |
| @@ -643,7 +596,7 @@ void stats_deliver( int64 socket, int tasktype ) { | |||
| 643 | 596 | ||
| 644 | static pthread_t thread_id; | 597 | static pthread_t thread_id; |
| 645 | void stats_init( ) { | 598 | void stats_init( ) { |
| 646 | ot_start_time = g_now; | 599 | ot_start_time = g_now_seconds; |
| 647 | pthread_create( &thread_id, NULL, stats_worker, NULL ); | 600 | pthread_create( &thread_id, NULL, stats_worker, NULL ); |
| 648 | } | 601 | } |
| 649 | 602 | ||
