summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <>2007-12-04 23:57:29 +0000
committererdgeist <>2007-12-04 23:57:29 +0000
commit31d876d53dfdafc4370b7c23febbb6978b271a77 (patch)
tree8ccc3959e75f5e61c5bf4acd6f96367c8793afca
parenta146a328856a1f8b5099064f0262a34d5623021b (diff)
Count invalid requests
-rw-r--r--ot_http.c25
-rw-r--r--ot_http.h2
-rw-r--r--ot_mutex.h1
-rw-r--r--ot_stats.c14
-rw-r--r--ot_stats.h15
5 files changed, 43 insertions, 14 deletions
diff --git a/ot_http.c b/ot_http.c
index aad29f6..4fbde78 100644
--- a/ot_http.c
+++ b/ot_http.c
@@ -79,19 +79,24 @@ static void http_senddata( const int64 client_socket, char *buffer, size_t size
79 } 79 }
80} 80}
81 81
82#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." ) 82#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
83#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" ) 83#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
84#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." ) 84#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
85#define HTTPERROR_403_IP return http_issue_error( client_socket, "403 Access Denied", "Your ip address is not allowed to administrate this server." ) 85#define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP )
86#define HTTPERROR_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." ) 86#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
87#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." ) 87#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
88ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) { 88ssize_t http_issue_error( const int64 client_socket, int code ) {
89 char *error_code[] = { "400 Invalid Request", "400 Invalid Request", "400 Invalid Request",
90 "403 Access Denied", "404 Not Found", "500 Internal Server Error" };
91 char *title = error_code[code];
92
89 size_t reply_size = sprintf( static_outbuf, 93 size_t reply_size = sprintf( static_outbuf,
90 "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n", 94 "HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n<title>%s</title>\n",
91 title, strlen(message)+strlen(title)+16-4,title+4); 95 title, 2*strlen(title)+16-4,title+4);
92#ifdef _DEBUG_HTTPERROR 96#ifdef _DEBUG_HTTPERROR
93 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); 97 fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
94#endif 98#endif
99 stats_issue_event( EVENT_FAILED, 1, code );
95 http_senddata( client_socket, static_outbuf, reply_size); 100 http_senddata( client_socket, static_outbuf, reply_size);
96 return -2; 101 return -2;
97} 102}
@@ -237,6 +242,8 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
237 mode = TASK_STATS_SLASH24S; 242 mode = TASK_STATS_SLASH24S;
238 else if( !byte_diff(data,4,"tpbs")) 243 else if( !byte_diff(data,4,"tpbs"))
239 mode = TASK_STATS_TPB; 244 mode = TASK_STATS_TPB;
245 else if( !byte_diff(data,4,"herr"))
246 mode = TASK_STATS_HTTPERRORS;
240 else 247 else
241 HTTPERROR_400_PARAM; 248 HTTPERROR_400_PARAM;
242 break; 249 break;
@@ -518,7 +525,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
518 break; 525 break;
519#endif 526#endif
520 case 5: /* stats ? */ 527 case 5: /* stats ? */
521 if( byte_diff(data,5,"stats")) HTTPERROR_404; 528 if( byte_diff( data, 5, "stats") ) HTTPERROR_404;
522 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length ); 529 reply_size = http_handle_stats( client_socket, c, recv_header, recv_length );
523 break; 530 break;
524 default: 531 default:
diff --git a/ot_http.h b/ot_http.h
index 134c309..a64cf19 100644
--- a/ot_http.h
+++ b/ot_http.h
@@ -23,6 +23,6 @@ struct http_data {
23 23
24ssize_t http_handle_request( const int64 s, char *data, size_t l ); 24ssize_t http_handle_request( const int64 s, char *data, size_t l );
25ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector ); 25ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector );
26ssize_t http_issue_error( const int64 s, const char *title, const char *message ); 26ssize_t http_issue_error( const int64 s, int code );
27 27
28#endif 28#endif
diff --git a/ot_mutex.h b/ot_mutex.h
index 43c3054..7f10c20 100644
--- a/ot_mutex.h
+++ b/ot_mutex.h
@@ -22,6 +22,7 @@ typedef enum {
22 TASK_STATS_SCRAPE = 0x0005, 22 TASK_STATS_SCRAPE = 0x0005,
23 TASK_STATS_FULLSCRAPE = 0x0006, 23 TASK_STATS_FULLSCRAPE = 0x0006,
24 TASK_STATS_TPB = 0x0007, 24 TASK_STATS_TPB = 0x0007,
25 TASK_STATS_HTTPERRORS = 0x0008,
25 26
26 TASK_STATS_SLASH24S = 0x0100, 27 TASK_STATS_SLASH24S = 0x0100,
27 28
diff --git a/ot_stats.c b/ot_stats.c
index e682599..32dcc91 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -37,6 +37,7 @@ static unsigned long long ot_overall_udp_connects = 0;
37static unsigned long long ot_full_scrape_count = 0; 37static unsigned long long ot_full_scrape_count = 0;
38static unsigned long long ot_full_scrape_request_count = 0; 38static unsigned long long ot_full_scrape_request_count = 0;
39static unsigned long long ot_full_scrape_size = 0; 39static unsigned long long ot_full_scrape_size = 0;
40static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
40 41
41static time_t ot_start_time; 42static time_t ot_start_time;
42 43
@@ -263,6 +264,12 @@ static size_t stats_peers_mrtg( char * reply ) {
263 ); 264 );
264} 265}
265 266
267static size_t stats_httperrors_txt ( char * reply ) {
268 return sprintf( reply, "400 ... %llu\n400 PAR %llu\n400 COM %llu\n403 IP %llu\n404 INV %llu\n500 SRV %llu\n",
269 ot_failed_request_counts[0], ot_failed_request_counts[1], ot_failed_request_counts[2],
270 ot_failed_request_counts[3], ot_failed_request_counts[4], ot_failed_request_counts[5]);
271}
272
266size_t return_stats_for_tracker( char *reply, int mode, int format ) { 273size_t return_stats_for_tracker( char *reply, int mode, int format ) {
267 format = format; 274 format = format;
268 switch( mode ) { 275 switch( mode ) {
@@ -282,6 +289,8 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
282 return stats_top5_txt( reply ); 289 return stats_top5_txt( reply );
283 case TASK_STATS_FULLSCRAPE: 290 case TASK_STATS_FULLSCRAPE:
284 return stats_fullscrapes_mrtg( reply ); 291 return stats_fullscrapes_mrtg( reply );
292 case TASK_STATS_HTTPERRORS:
293 return stats_httperrors_txt( reply );
285 default: 294 default:
286 return 0; 295 return 0;
287 } 296 }
@@ -317,7 +326,10 @@ void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ) {
317 LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now - ot_start_time), ip[0], ip[1], ip[2], ip[3] ); 326 LOG_TO_STDERR( "[%08d] scrp: %d.%d.%d.%d - FULL SCRAPE GZIP\n", (unsigned int)(g_now - ot_start_time), ip[0], ip[1], ip[2], ip[3] );
318 ot_full_scrape_request_count++; 327 ot_full_scrape_request_count++;
319 } 328 }
320 break; 329 break;
330 case EVENT_FAILED:
331 ot_failed_request_counts[event_data]++;
332 break;
321 case EVENT_SYNC_IN_REQUEST: 333 case EVENT_SYNC_IN_REQUEST:
322 case EVENT_SYNC_IN: 334 case EVENT_SYNC_IN:
323 case EVENT_SYNC_OUT_REQUEST: 335 case EVENT_SYNC_OUT_REQUEST:
diff --git a/ot_stats.h b/ot_stats.h
index b3ac1dc..2fb7b4b 100644
--- a/ot_stats.h
+++ b/ot_stats.h
@@ -17,11 +17,20 @@ typedef enum {
17 EVENT_SYNC_IN, 17 EVENT_SYNC_IN,
18 EVENT_SYNC_OUT_REQUEST, 18 EVENT_SYNC_OUT_REQUEST,
19 EVENT_SYNC_OUT, 19 EVENT_SYNC_OUT,
20 EVENT_FAILED_400, 20 EVENT_FAILED
21 EVENT_FAILED_404,
22 EVENT_FAILED_505
23} ot_status_event; 21} ot_status_event;
24 22
23enum {
24 CODE_HTTPERROR_400,
25 CODE_HTTPERROR_400_PARAM,
26 CODE_HTTPERROR_400_COMPACT,
27 CODE_HTTPERROR_403_IP,
28 CODE_HTTPERROR_404,
29 CODE_HTTPERROR_500,
30
31 CODE_HTTPERROR_COUNT
32};
33
25void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); 34void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data );
26size_t return_stats_for_tracker( char *reply, int mode, int format ); 35size_t return_stats_for_tracker( char *reply, int mode, int format );
27void stats_init( ); 36void stats_init( );