Browse Source

add support for more stats:

1. stats for added and removed torrents
2. stats for start and stopped events from peers

this should help to detect DoS attacks and is useful for
profiling
dynamic-accesslists
denis 17 years ago
parent
commit
65c3b24045
  1. 4
      ot_http.c
  2. 2
      ot_mutex.h
  3. 46
      ot_stats.c

4
ot_http.c

@ -251,6 +251,10 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d @@ -251,6 +251,10 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
mode = TASK_STATS_TPB;
else if( !byte_diff(data,4,"herr"))
mode = TASK_STATS_HTTPERRORS;
else if( !byte_diff(data,9,"startstop"))
mode = TASK_STATS_STARTSTOP;
else if( !byte_diff(data,10,"toraddrem"))
mode = TASK_STATS_TORADDREM;
else
HTTPERROR_400_PARAM;
break;

2
ot_mutex.h

@ -24,6 +24,8 @@ typedef enum { @@ -24,6 +24,8 @@ typedef enum {
TASK_STATS_TPB = 0x0007,
TASK_STATS_HTTPERRORS = 0x0008,
TASK_STATS_TORRENTS = 0x0009,
TASK_STATS_STARTSTOP = 0x000a,
TASK_STATS_TORADDREM = 0x000b,
TASK_STATS_SLASH24S = 0x0100,

46
ot_stats.c

@ -264,6 +264,48 @@ static size_t stats_peers_mrtg( char * reply ) { @@ -264,6 +264,48 @@ static size_t stats_peers_mrtg( char * reply ) {
);
}
static size_t stats_startstop_mrtg( char * reply )
{
size_t torrent_count = 0;
int bucket;
for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket )
{
ot_vector *torrents_list = mutex_bucket_lock( bucket );
torrent_count += torrents_list->size;
mutex_bucket_unlock( bucket );
}
return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker",
(size_t)0,
(size_t)0,
torrent_count
);
}
static size_t stats_toraddrem_mrtg( char * reply )
{
size_t peer_count = 0, j;
int bucket;
for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket )
{
ot_vector *torrents_list = mutex_bucket_lock( bucket );
for( j=0; j<torrents_list->size; ++j )
{
ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
peer_count += peer_list->peer_count;
}
mutex_bucket_unlock( bucket );
}
return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker",
(size_t)0,
(size_t)0,
peer_count
);
}
static size_t stats_torrents_mrtg( char * reply )
{
size_t torrent_count = 0;
@ -305,6 +347,10 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) { @@ -305,6 +347,10 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
return stats_peers_mrtg( reply );
case TASK_STATS_TORRENTS:
return stats_torrents_mrtg( reply );
case TASK_STATS_TORADDREM:
return stats_toraddrem_mrtg( reply );
case TASK_STATS_STARTSTOP:
return stats_startstop_mrtg( reply );
case TASK_STATS_SLASH24S:
return stats_slash24s_txt( reply, 25, 16 );
case TASK_STATS_TOP5:

Loading…
Cancel
Save