Count invalid requests

dynamic-accesslists
erdgeist 17 years ago
parent a146a32885
commit 31d876d53d

@ -79,19 +79,24 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
} }
} }
#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." ) #define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" ) #define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." ) #define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
#define HTTPERROR_403_IP return http_issue_error( client_socket, "403 Access Denied", "Your ip address is not allowed to administrate this server." ) #define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP )
#define HTTPERROR_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." ) #define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." ) #define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) { ssize_t http_issue_error( const int64 client_socket, int code ) {
char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request",
"403 Access Denied", "404 Not Found", "500 Internal Server Error" };
char *title = error_code[code];
size_t reply_size = sprintf( static_outbuf, size_t reply_size = sprintf( static_outbuf,
"HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n", "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n",
title, strlen(message)+strlen(title)+16-4,title+4); title, 2*strlen(title)+16-4,title+4);
#ifdef _DEBUG_HTTPERROR #ifdef _DEBUG_HTTPERROR
fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
#endif #endif
stats_issue_event( EVENT_FAILED, 1, code );
http_senddata( client_socket, static_outbuf, reply_size); http_senddata( client_socket, static_outbuf, reply_size);
return -2; return -2;
} }
@ -237,6 +242,8 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
mode = TASK_STATS_SLASH24S; mode = TASK_STATS_SLASH24S;
else if( !byte_diff(data,4,"tpbs")) else if( !byte_diff(data,4,"tpbs"))
mode = TASK_STATS_TPB; mode = TASK_STATS_TPB;
else if( !byte_diff(data,4,"herr"))
mode = TASK_STATS_HTTPERRORS;
else else
HTTPERROR_400_PARAM; HTTPERROR_400_PARAM;
break; break;

@ -23,6 +23,6 @@ struct http_data {
ssize_t http_handle_request( const int64 s, char *data, size_t l ); ssize_t http_handle_request( const int64 s, char *data, size_t l );
ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector ); ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector );
ssize_t http_issue_error( const int64 s, const char *title, const char *message ); ssize_t http_issue_error( const int64 s, int code );
#endif #endif

@ -22,6 +22,7 @@ typedef enum {
TASK_STATS_SCRAPE = 0x0005, TASK_STATS_SCRAPE = 0x0005,
TASK_STATS_FULLSCRAPE = 0x0006, TASK_STATS_FULLSCRAPE = 0x0006,
TASK_STATS_TPB = 0x0007, TASK_STATS_TPB = 0x0007,
TASK_STATS_HTTPERRORS = 0x0008,
TASK_STATS_SLASH24S = 0x0100, TASK_STATS_SLASH24S = 0x0100,

@ -37,6 +37,7 @@ static unsigned long long ot_overall_udp_connects = 0;
static unsigned long long ot_full_scrape_count = 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_request_count = 0;
static unsigned long long ot_full_scrape_size = 0; static unsigned long long ot_full_scrape_size = 0;
static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
static time_t ot_start_time; static time_t ot_start_time;
@ -263,6 +264,12 @@ static size_t stats_peers_mrtg( char * reply ) {
); );
} }
static size_t stats_httperrors_txt ( char * reply ) {
return sprintf( reply, "400 ... %llu\n400 PAR %llu\n400 COM %llu\n403 IP %llu\n404 INV %llu\n500 SRV %llu\n",
ot_failed_request_counts[0], ot_failed_request_counts[1], ot_failed_request_counts[2],
ot_failed_request_counts[3], ot_failed_request_counts[4], ot_failed_request_counts[5]);
}
size_t return_stats_for_tracker( char *reply, int mode, int format ) { size_t return_stats_for_tracker( char *reply, int mode, int format ) {
format = format; format = format;
switch( mode ) { switch( mode ) {
@ -282,6 +289,8 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
return stats_top5_txt( reply ); return stats_top5_txt( reply );
case TASK_STATS_FULLSCRAPE: case TASK_STATS_FULLSCRAPE:
return stats_fullscrapes_mrtg( reply ); return stats_fullscrapes_mrtg( reply );
case TASK_STATS_HTTPERRORS:
return stats_httperrors_txt( reply );
default: default:
return 0; return 0;
} }
@ -318,6 +327,9 @@ void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ) {
ot_full_scrape_request_count++; ot_full_scrape_request_count++;
} }
break; break;
case EVENT_FAILED:
ot_failed_request_counts[event_data]++;
break;
case EVENT_SYNC_IN_REQUEST: case EVENT_SYNC_IN_REQUEST:
case EVENT_SYNC_IN: case EVENT_SYNC_IN:
case EVENT_SYNC_OUT_REQUEST: case EVENT_SYNC_OUT_REQUEST:

@ -17,11 +17,20 @@ typedef enum {
EVENT_SYNC_IN, EVENT_SYNC_IN,
EVENT_SYNC_OUT_REQUEST, EVENT_SYNC_OUT_REQUEST,
EVENT_SYNC_OUT, EVENT_SYNC_OUT,
EVENT_FAILED_400, EVENT_FAILED
EVENT_FAILED_404,
EVENT_FAILED_505
} ot_status_event; } ot_status_event;
enum {
CODE_HTTPERROR_400,
CODE_HTTPERROR_400_PARAM,
CODE_HTTPERROR_400_COMPACT,
CODE_HTTPERROR_403_IP,
CODE_HTTPERROR_404,
CODE_HTTPERROR_500,
CODE_HTTPERROR_COUNT
};
void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data );
size_t return_stats_for_tracker( char *reply, int mode, int format ); size_t return_stats_for_tracker( char *reply, int mode, int format );
void stats_init( ); void stats_init( );

Loading…
Cancel
Save