diff options
| author | denis <> | 2007-12-14 22:01:14 +0000 |
|---|---|---|
| committer | denis <> | 2007-12-14 22:01:14 +0000 |
| commit | 65c3b2404560b976bfeff0db190c97d4b9487644 (patch) | |
| tree | 1c26a7981f8a05c031e38ab8f941cbc34b696340 | |
| parent | c2cbe1dc273984c689c97f5eca8798195d5a35a0 (diff) | |
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
| -rw-r--r-- | ot_http.c | 4 | ||||
| -rw-r--r-- | ot_mutex.h | 2 | ||||
| -rw-r--r-- | ot_stats.c | 46 |
3 files changed, 52 insertions, 0 deletions
| @@ -251,6 +251,10 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d | |||
| 251 | mode = TASK_STATS_TPB; | 251 | mode = TASK_STATS_TPB; |
| 252 | else if( !byte_diff(data,4,"herr")) | 252 | else if( !byte_diff(data,4,"herr")) |
| 253 | mode = TASK_STATS_HTTPERRORS; | 253 | mode = TASK_STATS_HTTPERRORS; |
| 254 | else if( !byte_diff(data,9,"startstop")) | ||
| 255 | mode = TASK_STATS_STARTSTOP; | ||
| 256 | else if( !byte_diff(data,10,"toraddrem")) | ||
| 257 | mode = TASK_STATS_TORADDREM; | ||
| 254 | else | 258 | else |
| 255 | HTTPERROR_400_PARAM; | 259 | HTTPERROR_400_PARAM; |
| 256 | break; | 260 | break; |
| @@ -24,6 +24,8 @@ typedef enum { | |||
| 24 | TASK_STATS_TPB = 0x0007, | 24 | TASK_STATS_TPB = 0x0007, |
| 25 | TASK_STATS_HTTPERRORS = 0x0008, | 25 | TASK_STATS_HTTPERRORS = 0x0008, |
| 26 | TASK_STATS_TORRENTS = 0x0009, | 26 | TASK_STATS_TORRENTS = 0x0009, |
| 27 | TASK_STATS_STARTSTOP = 0x000a, | ||
| 28 | TASK_STATS_TORADDREM = 0x000b, | ||
| 27 | 29 | ||
| 28 | TASK_STATS_SLASH24S = 0x0100, | 30 | TASK_STATS_SLASH24S = 0x0100, |
| 29 | 31 | ||
| @@ -264,6 +264,48 @@ static size_t stats_peers_mrtg( char * reply ) { | |||
| 264 | ); | 264 | ); |
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | static size_t stats_startstop_mrtg( char * reply ) | ||
| 268 | { | ||
| 269 | size_t torrent_count = 0; | ||
| 270 | int bucket; | ||
| 271 | |||
| 272 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) | ||
| 273 | { | ||
| 274 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | ||
| 275 | torrent_count += torrents_list->size; | ||
| 276 | mutex_bucket_unlock( bucket ); | ||
| 277 | } | ||
| 278 | |||
| 279 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd torrents\nopentracker", | ||
| 280 | (size_t)0, | ||
| 281 | (size_t)0, | ||
| 282 | torrent_count | ||
| 283 | ); | ||
| 284 | } | ||
| 285 | |||
| 286 | static size_t stats_toraddrem_mrtg( char * reply ) | ||
| 287 | { | ||
| 288 | size_t peer_count = 0, j; | ||
| 289 | int bucket; | ||
| 290 | |||
| 291 | for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) | ||
| 292 | { | ||
| 293 | ot_vector *torrents_list = mutex_bucket_lock( bucket ); | ||
| 294 | for( j=0; j<torrents_list->size; ++j ) | ||
| 295 | { | ||
| 296 | ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list; | ||
| 297 | peer_count += peer_list->peer_count; | ||
| 298 | } | ||
| 299 | mutex_bucket_unlock( bucket ); | ||
| 300 | } | ||
| 301 | |||
| 302 | return sprintf( reply, "%zd\n%zd\nopentracker handling %zd peers\nopentracker", | ||
| 303 | (size_t)0, | ||
| 304 | (size_t)0, | ||
| 305 | peer_count | ||
| 306 | ); | ||
| 307 | } | ||
| 308 | |||
| 267 | static size_t stats_torrents_mrtg( char * reply ) | 309 | static size_t stats_torrents_mrtg( char * reply ) |
| 268 | { | 310 | { |
| 269 | size_t torrent_count = 0; | 311 | size_t torrent_count = 0; |
| @@ -305,6 +347,10 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) { | |||
| 305 | return stats_peers_mrtg( reply ); | 347 | return stats_peers_mrtg( reply ); |
| 306 | case TASK_STATS_TORRENTS: | 348 | case TASK_STATS_TORRENTS: |
| 307 | return stats_torrents_mrtg( reply ); | 349 | return stats_torrents_mrtg( reply ); |
| 350 | case TASK_STATS_TORADDREM: | ||
| 351 | return stats_toraddrem_mrtg( reply ); | ||
| 352 | case TASK_STATS_STARTSTOP: | ||
| 353 | return stats_startstop_mrtg( reply ); | ||
| 308 | case TASK_STATS_SLASH24S: | 354 | case TASK_STATS_SLASH24S: |
| 309 | return stats_slash24s_txt( reply, 25, 16 ); | 355 | return stats_slash24s_txt( reply, 25, 16 ); |
| 310 | case TASK_STATS_TOP5: | 356 | case TASK_STATS_TOP5: |
