Browse Source

Allow logging of completed events to syslog

dynamic-accesslists
erdgeist 15 years ago
parent
commit
f4409df68a
  1. 1
      Makefile
  2. 17
      ot_stats.c
  3. 2
      trackerlogic.c

1
Makefile

@ -35,6 +35,7 @@ BINDIR?=$(PREFIX)/bin @@ -35,6 +35,7 @@ BINDIR?=$(PREFIX)/bin
#FEATURES+=-DWANT_LOG_NUMWANT
#FEATURES+=-DWANT_MODEST_FULLSCRAPES
#FEATURES+=-DWANT_SPOT_WOODPECKER
#FEATURES+=-DWANT_SYSLOGS
FEATURES+=-DWANT_FULLSCRAPE
#FEATURES+=-D_DEBUG_HTTPERROR

17
ot_stats.c

@ -14,6 +14,9 @@ @@ -14,6 +14,9 @@
#include <pthread.h>
#include <unistd.h>
#include <inttypes.h>
#ifdef WANT_SYSLOGS
#include <syslog.h>
#endif
/* Libowfat */
#include "byte.h"
@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event @@ -637,6 +640,13 @@ void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event
if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++;
break;
case EVENT_COMPLETED:
#ifdef WANT_SYSLOGS
if( event_data) {
char hex_out[42];
to_hex( hex_out, (uint8_t*)event_data );
syslog( LOG_INFO, "event=completed info_hash=%s", hex_out );
}
#endif
ot_overall_completed++;
break;
case EVENT_SCRAPE:
@ -715,10 +725,17 @@ static pthread_t thread_id; @@ -715,10 +725,17 @@ static pthread_t thread_id;
void stats_init( ) {
ot_start_time = g_now_seconds;
pthread_create( &thread_id, NULL, stats_worker, NULL );
#ifdef WANT_SYSLOGS
openlog( "opentracker", 0, LOG_USER );
setlogmask(LOG_UPTO(LOG_INFO));
#endif
}
void stats_deinit( ) {
pthread_cancel( thread_id );
#ifdef WANT_SYSLOGS
closelog();
#endif
}
const char *g_version_stats_c = "$Source$: $Revision$\n";

2
trackerlogic.c

@ -138,7 +138,7 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_ @@ -138,7 +138,7 @@ size_t add_peer_to_torrent_and_return_peers( ot_hash hash, ot_peer *peer, PROTO_
torrent->peer_list->peer_count++;
if( OT_PEERFLAG(peer) & PEER_FLAG_COMPLETED ) {
torrent->peer_list->down_count++;
stats_issue_event( EVENT_COMPLETED, 0, 0 );
stats_issue_event( EVENT_COMPLETED, 0, (uintptr_t)torrent->hash );
}
if( OT_PEERFLAG(peer) & PEER_FLAG_SEEDING )
torrent->peer_list->seed_count++;

Loading…
Cancel
Save