From 31d876d53dfdafc4370b7c23febbb6978b271a77 Mon Sep 17 00:00:00 2001
From: erdgeist <>
Date: Tue, 4 Dec 2007 23:57:29 +0000
Subject: Count invalid requests
---
ot_http.c | 25 ++++++++++++++++---------
ot_http.h | 2 +-
ot_mutex.h | 1 +
ot_stats.c | 14 +++++++++++++-
ot_stats.h | 15 ++++++++++++---
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
}
}
-#define HTTPERROR_400 return http_issue_error( client_socket, "400 Invalid Request", "This server only understands GET." )
-#define HTTPERROR_400_PARAM return http_issue_error( client_socket, "400 Invalid Request", "Invalid parameter" )
-#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, "400 Invalid Request", "This server only delivers compact results." )
-#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_404 return http_issue_error( client_socket, "404 Not Found", "No such file or directory." )
-#define HTTPERROR_500 return http_issue_error( client_socket, "500 Internal Server Error", "A server error has occured. Please retry later." )
-ssize_t http_issue_error( const int64 client_socket, const char *title, const char *message ) {
+#define HTTPERROR_400 return http_issue_error( client_socket, CODE_HTTPERROR_400 )
+#define HTTPERROR_400_PARAM return http_issue_error( client_socket, CODE_HTTPERROR_400_PARAM )
+#define HTTPERROR_400_COMPACT return http_issue_error( client_socket, CODE_HTTPERROR_400_COMPACT )
+#define HTTPERROR_403_IP return http_issue_error( client_socket, CODE_HTTPERROR_403_IP )
+#define HTTPERROR_404 return http_issue_error( client_socket, CODE_HTTPERROR_404 )
+#define HTTPERROR_500 return http_issue_error( client_socket, CODE_HTTPERROR_500 )
+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,
"HTTP/1.0 %s\r\nContent-Type: text/html\r\nConnection: close\r\nContent-Length: %zd\r\n\r\n
%s\n",
- title, strlen(message)+strlen(title)+16-4,title+4);
+ title, 2*strlen(title)+16-4,title+4);
#ifdef _DEBUG_HTTPERROR
fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request );
#endif
+ stats_issue_event( EVENT_FAILED, 1, code );
http_senddata( client_socket, static_outbuf, reply_size);
return -2;
}
@@ -237,6 +242,8 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d
mode = TASK_STATS_SLASH24S;
else if( !byte_diff(data,4,"tpbs"))
mode = TASK_STATS_TPB;
+ else if( !byte_diff(data,4,"herr"))
+ mode = TASK_STATS_HTTPERRORS;
else
HTTPERROR_400_PARAM;
break;
@@ -518,7 +525,7 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_
break;
#endif
case 5: /* stats ? */
- if( byte_diff(data,5,"stats")) HTTPERROR_404;
+ if( byte_diff( data, 5, "stats") ) HTTPERROR_404;
reply_size = http_handle_stats( client_socket, c, recv_header, recv_length );
break;
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 {
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_issue_error( const int64 s, const char *title, const char *message );
+ssize_t http_issue_error( const int64 s, int code );
#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 {
TASK_STATS_SCRAPE = 0x0005,
TASK_STATS_FULLSCRAPE = 0x0006,
TASK_STATS_TPB = 0x0007,
+ TASK_STATS_HTTPERRORS = 0x0008,
TASK_STATS_SLASH24S = 0x0100,
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;
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_size = 0;
+static unsigned long long ot_failed_request_counts[CODE_HTTPERROR_COUNT];
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 ) {
format = format;
switch( mode ) {
@@ -282,6 +289,8 @@ size_t return_stats_for_tracker( char *reply, int mode, int format ) {
return stats_top5_txt( reply );
case TASK_STATS_FULLSCRAPE:
return stats_fullscrapes_mrtg( reply );
+ case TASK_STATS_HTTPERRORS:
+ return stats_httperrors_txt( reply );
default:
return 0;
}
@@ -317,7 +326,10 @@ void stats_issue_event( ot_status_event event, int is_tcp, size_t event_data ) {
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] );
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:
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 {
EVENT_SYNC_IN,
EVENT_SYNC_OUT_REQUEST,
EVENT_SYNC_OUT,
- EVENT_FAILED_400,
- EVENT_FAILED_404,
- EVENT_FAILED_505
+ EVENT_FAILED
} 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 );
size_t return_stats_for_tracker( char *reply, int mode, int format );
void stats_init( );
--
cgit v1.2.3