diff options
-rw-r--r-- | ot_http.c | 25 | ||||
-rw-r--r-- | ot_http.h | 2 | ||||
-rw-r--r-- | ot_mutex.h | 1 | ||||
-rw-r--r-- | ot_stats.c | 14 | ||||
-rw-r--r-- | ot_stats.h | 15 |
5 files changed, 43 insertions, 14 deletions
@@ -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 ) |
88 | ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) { | 88 | ssize_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: |
@@ -23,6 +23,6 @@ struct http_data { | |||
23 | 23 | ||
24 | ssize_t http_handle_request( const int64 s, char *data, size_t l ); | 24 | ssize_t http_handle_request( const int64 s, char *data, size_t l ); |
25 | ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector ); | 25 | ssize_t http_sendiovecdata( const int64 s, int iovec_entries, struct iovec *iovector ); |
26 | ssize_t http_issue_error( const int64 s, const char *title, const char *message ); | 26 | ssize_t http_issue_error( const int64 s, int code ); |
27 | 27 | ||
28 | #endif | 28 | #endif |
@@ -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 | ||
@@ -37,6 +37,7 @@ static unsigned long long ot_overall_udp_connects = 0; | |||
37 | static unsigned long long ot_full_scrape_count = 0; | 37 | static unsigned long long ot_full_scrape_count = 0; |
38 | static unsigned long long ot_full_scrape_request_count = 0; | 38 | static unsigned long long ot_full_scrape_request_count = 0; |
39 | static unsigned long long ot_full_scrape_size = 0; | 39 | static unsigned long long ot_full_scrape_size = 0; |
40 | static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT]; | ||
40 | 41 | ||
41 | static time_t ot_start_time; | 42 | static 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 | ||
267 | static 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 | |||
266 | size_t return_stats_for_tracker( char *reply, int mode, int format ) { | 273 | size_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: |
@@ -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 | ||
23 | enum { | ||
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 | |||
25 | void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); | 34 | void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ); |
26 | size_t return_stats_for_tracker( char *reply, int mode, int format ); | 35 | size_t return_stats_for_tracker( char *reply, int mode, int format ); |
27 | void stats_init( ); | 36 | void stats_init( ); |