]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
include overall completed count in stats
authorerdgeist <>
Tue, 24 Mar 2009 16:55:28 +0000 (16:55 +0000)
committererdgeist <>
Tue, 24 Mar 2009 16:55:28 +0000 (16:55 +0000)
ot_http.c
ot_mutex.h
ot_stats.c
ot_stats.h
trackerlogic.c

index bf60104da517b49e5ce61ab46a6144cca4ed5f0e..98ee8fbbea4178615c7b5e6c0a9cd349a60bcbe3 100644 (file)
--- a/ot_http.c
+++ b/ot_http.c
@@ -163,7 +163,7 @@ static const ot_keywords keywords_main[] =
 static const ot_keywords keywords_mode[] =
   { { "peer", TASK_STATS_PEERS }, { "conn", TASK_STATS_CONNS }, { "scrp", TASK_STATS_SCRAPE }, { "udp4", TASK_STATS_UDP }, { "tcp4", TASK_STATS_TCP },
     { "busy", TASK_STATS_BUSY_NETWORKS }, { "torr", TASK_STATS_TORRENTS }, { "fscr", TASK_STATS_FULLSCRAPE },
-    { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS },
+    { "s24s", TASK_STATS_SLASH24S }, { "tpbs", TASK_STATS_TPB }, { "herr", TASK_STATS_HTTPERRORS }, { "completed", TASK_STATS_COMPLETED },
     { "top10", TASK_STATS_TOP10 }, { "renew", TASK_STATS_RENEW }, { "syncs", TASK_STATS_SYNCS }, { "version", TASK_STATS_VERSION },
     { "everything", TASK_STATS_EVERYTHING }, { "statedump", TASK_FULLSCRAPE_TPB_URLENCODED }, { NULL, -3 } };
 static const ot_keywords keywords_format[] =
index 6240bbb515062872e2aeb0a4927b93700eedc400..183fe2be328fb17e75adb34f4db338ae46853da5 100644 (file)
@@ -31,6 +31,7 @@ typedef enum {
   TASK_STATS_BUSY_NETWORKS         = 0x0009,
   TASK_STATS_RENEW                 = 0x000a,
   TASK_STATS_SYNCS                 = 0x000b,
+  TASK_STATS_COMPLETED             = 0x000c,
 
   TASK_STATS                       = 0x0100, /* Mask */
   TASK_STATS_TORRENTS              = 0x0101,
index a3cce6333dbdea25353cd8d37150689da7e257e8..e4c607a0c407c4a6215ce3237f06edd864545cfe 100644 (file)
@@ -44,6 +44,7 @@ static unsigned long long ot_overall_tcp_successfulscrapes = 0;
 static unsigned long long ot_overall_udp_successfulscrapes = 0;
 static unsigned long long ot_overall_tcp_connects = 0;
 static unsigned long long ot_overall_udp_connects = 0;
+static unsigned long long ot_overall_completed = 0;
 static unsigned long long ot_full_scrape_count = 0;
 static unsigned long long ot_full_scrape_request_count = 0;
 static unsigned long long ot_full_scrape_size = 0;
@@ -445,6 +446,19 @@ static size_t stats_return_sync_mrtg( char * reply ) {
                  );
 }
 
+static size_t stats_return_completed_mrtg( char * reply ) {
+  ot_time t = time( NULL ) - ot_start_time;
+
+  return sprintf( reply,
+                 "%llu\n%llu\n%i seconds (%i hours)\nopentracker, %lu completed/h.",
+                 ot_overall_completed,
+                 0LL,
+                 (int)t,
+                 (int)(t / 3600),
+                 events_per_time( ot_overall_completed, t / 3600 )
+                 );
+}
+
 static size_t stats_return_everything( char * reply ) {
   torrent_stats stats = {0,0,0};
   int i;
@@ -462,6 +476,7 @@ static size_t stats_return_everything( char * reply ) {
   r += sprintf( r, "  </torrents>\n" );
   r += sprintf( r, "  <peers>\n    <count>%llu</count>\n  </peers>\n", stats.peer_count );
   r += sprintf( r, "  <seeds>\n    <count>%llu</count>\n  </seeds>\n", stats.seed_count );
+  r += sprintf( r, "  <completed>\n    <count>%llu</count>\n  </completed", ot_overall_completed );
   r += sprintf( r, "  <connections>\n" );
   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 );
   r += sprintf( r, "    <udp>\n      <overall>%llu</overall>\n      <connect>%llu</connect>\n      <announce>%llu</announce>\n      <scrape>%llu</scrape>\n    </udp>\n", ot_overall_udp_connections, ot_overall_udp_connects, ot_overall_udp_successfulannounces, ot_overall_udp_successfulscrapes );
@@ -507,6 +522,8 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
       return stats_tcpconnections_mrtg( reply );
     case TASK_STATS_FULLSCRAPE:
       return stats_fullscrapes_mrtg( reply );
+    case TASK_STATS_COMPLETED:
+      return stats_return_completed_mrtg( reply );
     case TASK_STATS_HTTPERRORS:
       return stats_httperrors_txt( reply );
     case TASK_STATS_VERSION:
@@ -559,6 +576,9 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
     case EVENT_CONNECT:
       if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++;
       break;
+    case EVENT_COMPLETED:
+      ot_overall_completed++;
+      break;
     case EVENT_SCRAPE:
       if( proto == FLAG_TCP ) ot_overall_tcp_successfulscrapes++; else ot_overall_udp_successfulscrapes++;
     case EVENT_FULLSCRAPE:
index 77539471742851599938e8cc73122fb6c0d21931..d356aaf0a73101ad681aaac07109a2633a252b2f 100644 (file)
@@ -11,6 +11,7 @@ typedef enum {
   EVENT_READ,
   EVENT_CONNECT,      /* UDP only */
   EVENT_ANNOUNCE,
+  EVENT_COMPLETED,
   EVENT_RENEW,
   EVENT_SYNC,
   EVENT_SCRAPE,
index 1bd8ac716bb05b4ae1251bf8f0a8f25a491cd405..d1ef063c4adea774c1a2fe6d5f2046997c0ce1e7 100644 (file)
@@ -128,8 +128,10 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
 #endif
 
     torrent->peer_list->peer_count++;
-    if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED )
+    if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) {
       torrent->peer_list->down_count++;
+      stats_issue_event( EVENT_COMPLETED, 0, 0 );
+    }
     if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING )
       torrent->peer_list->seed_count++;
 
@@ -150,8 +152,10 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
       torrent->peer_list->seed_count--;
     if( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_SEEDING )   &&  (OT_PEERFLAG(peer) & PEER_FLAG_SEEDING ) )
       torrent->peer_list->seed_count++;
-    if( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED ) &&  (OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) )
+    if( !(OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED ) &&  (OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) ) {
       torrent->peer_list->down_count++;
+      stats_issue_event( EVENT_COMPLETED, 0, 0 );
+    }
     if(   OT_PEERFLAG(peer_dest) & PEER_FLAG_COMPLETED )
       OT_PEERFLAG( peer ) |= PEER_FLAG_COMPLETED;
   }