]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Count invalid requests
authorerdgeist <>
Tue, 4 Dec 2007 23:57:29 +0000 (23:57 +0000)
committererdgeist <>
Tue, 4 Dec 2007 23:57:29 +0000 (23:57 +0000)
ot_http.c
ot_http.h
ot_mutex.h
ot_stats.c
ot_stats.h

index aad29f658e5355d9d251fed532d59c6a269b4757..4fbde78f421880cfab0f7706cf90d251dcb170c2 100644 (file)
--- 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<title>%s</title>\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:
index 134c309fa151127ac286b598923b10252f5a2fee..a64cf194262f3e3a94d61b3eeec599286525b4a2 100644 (file)
--- 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
index 43c30541b97e7045e17909a70379a95b1a12fe40..7f10c200ffc991a993143e9c0edeb58bd778c6a8 100644 (file)
@@ -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,
 
index e6825998579890fefe16e0dfd01285caf614ddbb..32dcc913cd3c8a00e3d8bd9de54df42c9c0d90f7 100644 (file)
@@ -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:
index b3ac1dcfddbef3bed7c83b0c12a4862eded48e4d..2fb7b4bb42e3545889f28c58d6aedc5474eb477d 100644 (file)
@@ -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( );