Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Output details of connecting and disconnecting listeners to stats

  • Loading branch information...
commit 307209f3aea4efbe5004eb8d40dad15d4a0a200d 1 parent 5324d4d
@cato- authored
Showing with 68 additions and 2 deletions.
  1. +13 −1 src/auth.c
  2. +1 −0  src/connection.h
  3. +53 −0 src/format.c
  4. +1 −1  src/stats.c
View
14 src/auth.c
@@ -569,9 +569,21 @@ void auth_add_listener (const char *mount, client_t *client)
*/
int auth_release_listener (client_t *client)
{
+ const char *mount = httpp_getvar (client->parser, HTTPP_VAR_URI);
+
+ if (client->format_data != NULL) {
+ time_t now = time(NULL);
+ time_t stayed = now - client->con->con_time;
+
+ stats_event_args(mount, "listener_disconnected",
+ "{\"ip\": \"%s\", \"port\": %i, \"sent_bytes\": %" PRIu64 ", \"connected_time\": %lu}",
+ client->con->ip,
+ client->con->port,
+ client->con->sent_bytes,
+ (unsigned long)stayed);
+ }
if (client->authenticated)
{
- const char *mount = httpp_getvar (client->parser, HTTPP_VAR_URI);
/* drop any queue reference here, we do not want a race between the source thread
* and the auth/fserve thread */
View
1  src/connection.h
@@ -48,6 +48,7 @@ typedef struct connection_tag
int (*read)(struct connection_tag *handle, void *buf, size_t len);
char *ip;
+ int port;
char *host;
} connection_t;
View
53 src/format.c
@@ -29,6 +29,8 @@
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
+#include <sys/socket.h>
+#include <netinet/in.h>
#include "connection.h"
#include "refbuf.h"
@@ -215,6 +217,57 @@ int format_check_http_buffer (source_t *source, client_t *client)
}
client->respcode = 200;
stats_event_inc (NULL, "listeners");
+
+ char reqbuf[1024];
+ /* build the request */
+ snprintf (reqbuf, sizeof(reqbuf), "%s %s %s/%s",
+ httpp_getvar (client->parser, HTTPP_VAR_REQ_TYPE),
+ httpp_getvar (client->parser, HTTPP_VAR_URI),
+ httpp_getvar (client->parser, HTTPP_VAR_PROTOCOL),
+ httpp_getvar (client->parser, HTTPP_VAR_VERSION));
+
+ const char *referrer, *user_agent, *username;
+ if (client->username == NULL)
+ username = "-";
+ else
+ username = client->username;
+
+ referrer = httpp_getvar (client->parser, "referer");
+ if (referrer == NULL)
+ referrer = "-";
+
+ user_agent = httpp_getvar (client->parser, "user-agent");
+ if (user_agent == NULL)
+ user_agent = "-";
+
+ socklen_t len;
+ struct sockaddr_storage addr;
+ int peer_port;
+ len = sizeof addr;
+ getpeername(client->con->sock, (struct sockaddr*)&addr, &len);
+
+ // deal with both IPv4 and IPv6:
+ if (addr.ss_family == AF_INET) {
+ struct sockaddr_in *s = (struct sockaddr_in *)&addr;
+ peer_port = ntohs(s->sin_port);
+ } else { // AF_INET6
+ struct sockaddr_in6 *s = (struct sockaddr_in6 *)&addr;
+ peer_port = ntohs(s->sin6_port);
+ }
+
+ client->con->port = peer_port;
+ stats_event_args(source->mount, "listener_connected",
+ "{\"ip\": \"%s\", \"port\": %i, \"request_type\": \"%s\", \"request_uri\": \"%s\", \"protocol\": \"%s/%s\", \"username\": \"%s\", \"referer\": \"%s\", \"user-agent\": \"%s\"}",
+ client->con->ip,
+ peer_port,
+ httpp_getvar (client->parser, HTTPP_VAR_REQ_TYPE),
+ httpp_getvar (client->parser, HTTPP_VAR_URI),
+ httpp_getvar (client->parser, HTTPP_VAR_PROTOCOL),
+ httpp_getvar (client->parser, HTTPP_VAR_VERSION),
+ username,
+ referrer,
+ user_agent);
+
stats_event_inc (NULL, "listener_connections");
stats_event_inc (source->mount, "listener_connections");
}
View
2  src/stats.c
@@ -735,7 +735,7 @@ static stats_event_t *_get_event_from_queue (event_queue_t *queue)
static int _send_event_to_client(stats_event_t *event, client_t *client)
{
int len;
- char buf [200];
+ char buf [512];
/* send data to the client!!!! */
len = snprintf (buf, sizeof (buf), "EVENT %s %s %s\n",
Please sign in to comment.
Something went wrong with that request. Please try again.