Beispiel #1
0
static void carbon_disconnect(struct brubeck_carbon *self)
{
	log_splunk_errno("backend=carbon event=disconnected");

	close(self->out_sock);
	self->out_sock = -1;
}
Beispiel #2
0
static void statsd_run_recvmsg(struct brubeck_statsd *statsd, int sock)
{
	struct brubeck_server *server = statsd->sampler.server;

	char *buffer = xmalloc(MAX_PACKET_SIZE);
	struct sockaddr_in reporter;
	socklen_t reporter_len = sizeof(reporter);
	memset(&reporter, 0, reporter_len);

	log_splunk("sampler=statsd event=worker_online syscall=recvmsg socket=%d", sock);

	for (;;) {
		int res = recvfrom(sock, buffer, MAX_PACKET_SIZE - 1, 0,
			(struct sockaddr *)&reporter, &reporter_len);

		if (res < 0) {
			if (errno == EAGAIN || errno == EINTR)
				continue;

			log_splunk_errno("sampler=statsd event=failed_read from=%s",
				inet_ntoa(reporter.sin_addr));
			brubeck_stats_inc(server, errors);
			continue;
		}

		brubeck_atomic_inc(&statsd->sampler.inflow);
		brubeck_statsd_packet_parse(server, buffer, buffer + res);
	}
}
Beispiel #3
0
static int carbon_connect(void *backend)
{
	struct brubeck_carbon *self = (struct brubeck_carbon *)backend;

	if (is_connected(self))
		return 0;

	self->out_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

	if (self->out_sock >= 0) {
		int rc = connect(self->out_sock,
				(struct sockaddr *)&self->out_sockaddr,
				sizeof(self->out_sockaddr));
		
		if (rc == 0) {
			log_splunk("backend=carbon event=connected");
			sock_enlarge_out(self->out_sock);
			return 0;
		}

		close(self->out_sock);
		self->out_sock = -1;
	}

	log_splunk_errno("backend=carbon event=failed_to_connect");
	return -1;
}
Beispiel #4
0
static void graphite_run_recvmmsg(struct brubeck_graphite *graphite, int sock)
{
        const unsigned int SIM_PACKETS = graphite->mmsg_count;
        struct brubeck_server *server = graphite->sampler.server;

        struct brubeck_graphite_msg msg;
        struct brubeck_metric *metric;
        unsigned int i;

        struct iovec iovecs[SIM_PACKETS];
        struct mmsghdr msgs[SIM_PACKETS];

        memset(msgs, 0x0, sizeof(msgs));

        for (i = 0; i < SIM_PACKETS; ++i) {
                iovecs[i].iov_base = xmalloc(MAX_PACKET_SIZE);
                iovecs[i].iov_len = MAX_PACKET_SIZE - 1;
                msgs[i].msg_hdr.msg_iov = &iovecs[i];
                msgs[i].msg_hdr.msg_iovlen = 1;
        }

        log_splunk("sampler=graphite event=worker_online syscall=recvmmsg socket=%d", sock);

        for (;;) {
                int res = recvmmsg(sock, msgs, SIM_PACKETS, 0, NULL);

                if (res < 0) {
                        if (errno == EAGAIN || errno == EINTR)
                                continue;

                        log_splunk_errno("sampler=graphite event=failed_read");
                        brubeck_server_mark_dropped(server);
                        continue;
                }

                /* store stats */
                brubeck_atomic_add(&server->stats.metrics, SIM_PACKETS);
                brubeck_atomic_add(&graphite->sampler.inflow, SIM_PACKETS);

                for (i = 0; i < SIM_PACKETS; ++i) {
                        char *buf = msgs[i].msg_hdr.msg_iov->iov_base;
                        int len = msgs[i].msg_len;

                        if (brubeck_graphite_msg_parse(&msg, buf, len) < 0) {
                                log_splunk("sampler=graphite event=bad_key key='%.*s'", len, buf);
                                brubeck_server_mark_dropped(server);
                                continue;
                        }

                        metric = brubeck_metric_find(server, msg.key, msg.key_len, BRUBECK_MT_GAUGE);

                        if (metric != NULL)
                                brubeck_metric_record(metric, msg.value);
                }
        }

}
Beispiel #5
0
static void statsd_run_recvmsg(struct brubeck_statsd *statsd, int sock)
{
	struct brubeck_server *server = statsd->sampler.server;

	struct brubeck_statsd_msg msg;
	struct brubeck_metric *metric;

	char buffer[MAX_PACKET_SIZE];

	struct sockaddr_in reporter;
	socklen_t reporter_len = sizeof(reporter);
	memset(&reporter, 0, reporter_len);

	log_splunk("sampler=statsd event=worker_online syscall=recvmsg socket=%d", sock);

	for (;;) {
		int res = recvfrom(sock, buffer,
			sizeof(buffer) - 1, 0,
			(struct sockaddr *)&reporter, &reporter_len);

		if (res < 0) {
			if (errno == EAGAIN || errno == EINTR)
				continue;

			log_splunk_errno("sampler=statsd event=failed_read from=%s",
				inet_ntoa(reporter.sin_addr));
			brubeck_server_mark_dropped(server);
			continue;
		}

		/* store stats */
		brubeck_atomic_inc(&server->stats.metrics);
		brubeck_atomic_inc(&statsd->sampler.inflow);


            if (brubeck_statsd_msg_parse(&msg, buffer, (size_t) res) < 0) {
                if (msg.key_len > 0)
                    buffer[msg.key_len] = ':';

                log_splunk("sampler=statsd event=bad_key key='%.*s' from=%s",
                           res, buffer, inet_ntoa(reporter.sin_addr));

                brubeck_server_mark_dropped(server);
                continue;
            }

            metric = brubeck_metric_find(server, msg.key, msg.key_len, msg.type);
            if (metric != NULL) {
                brubeck_metric_record(metric, msg.value);
            }

	}

}
Beispiel #6
0
static void
dump_all_metrics(struct brubeck_server *server)
{
	FILE *dump = NULL;

	log_splunk("event=dump_metrics");

	if (server->dump_path)
		dump = fopen(server->dump_path, "w+");

	if (!dump) {
		log_splunk_errno("event=dump_failed");
		return;
	}

	brubeck_hashtable_foreach(server->metrics, &dump_metric, dump);
	fclose(dump);
}
Beispiel #7
0
static void statsd_run_recvmmsg(struct brubeck_statsd *statsd, int sock)
{
	const unsigned int SIM_PACKETS = statsd->mmsg_count;
	struct brubeck_server *server = statsd->sampler.server;

	unsigned int i;
	struct iovec iovecs[SIM_PACKETS];
	struct mmsghdr msgs[SIM_PACKETS];

	memset(msgs, 0x0, sizeof(msgs));

	for (i = 0; i < SIM_PACKETS; ++i) {
		iovecs[i].iov_base = xmalloc(MAX_PACKET_SIZE);
		iovecs[i].iov_len = MAX_PACKET_SIZE - 1;
		msgs[i].msg_hdr.msg_iov = &iovecs[i];
		msgs[i].msg_hdr.msg_iovlen = 1;
	}

	log_splunk("sampler=statsd event=worker_online syscall=recvmmsg socket=%d", sock);

	for (;;) {
		int res = recvmmsg(sock, msgs, SIM_PACKETS, 0, NULL);

		if (res < 0) {
			if (errno == EAGAIN || errno == EINTR)
				continue;

			log_splunk_errno("sampler=statsd event=failed_read");
			brubeck_stats_inc(server, errors);
			continue;
		}

		/* store stats */
		brubeck_atomic_add(&statsd->sampler.inflow, SIM_PACKETS);

		for (i = 0; i < SIM_PACKETS; ++i) {
			char *buf = msgs[i].msg_hdr.msg_iov->iov_base;
			char *end = buf + msgs[i].msg_len;
			brubeck_statsd_packet_parse(server, buf, end);
		}
	}
}
Beispiel #8
0
static void statsd_run_recvmmsg(struct brubeck_statsd *statsd, int sock)
{
	const unsigned int SIM_PACKETS = statsd->mmsg_count;
	struct brubeck_server *server = statsd->sampler.server;

	struct brubeck_statsd_msg msg;
	struct brubeck_metric *metric;
	unsigned int i;

	struct iovec iovecs[SIM_PACKETS];
	struct mmsghdr msgs[SIM_PACKETS];

	memset(msgs, 0x0, sizeof(msgs));

	for (i = 0; i < SIM_PACKETS; ++i) {
		iovecs[i].iov_base = xmalloc(MAX_PACKET_SIZE);
		iovecs[i].iov_len = MAX_PACKET_SIZE - 1;
		msgs[i].msg_hdr.msg_iov = &iovecs[i];
		msgs[i].msg_hdr.msg_iovlen = 1;
	}

	log_splunk("sampler=statsd event=worker_online syscall=recvmmsg socket=%d", sock);

	for (;;) {
		int res = recvmmsg(sock, msgs, SIM_PACKETS, 0, NULL);

		if (res < 0) {
			if (errno == EAGAIN || errno == EINTR)
				continue;

			log_splunk_errno("sampler=statsd event=failed_read");
			brubeck_server_mark_dropped(server);
			continue;
		}

		/* store stats */
		brubeck_atomic_add(&server->stats.metrics, SIM_PACKETS);
		brubeck_atomic_add(&statsd->sampler.inflow, SIM_PACKETS);

		for (i = 0; i < SIM_PACKETS; ++i) {
			char *buf = msgs[i].msg_hdr.msg_iov->iov_base;
			int len = msgs[i].msg_len;

            char *cur;
            int curLen;

            int processed = 0;

            do {
                cur = memchr(buf,'\n', len);
                if(cur == NULL){
                    cur = buf;
                    curLen = len - processed;
                }
                else{
                    curLen = cur - buf;
                    cur = buf;
                }

                //log_splunk("msg to be processed ='%.*s'", curLen, cur);
                if (brubeck_statsd_msg_parse(&msg, cur, curLen) < 0) {
                    if (msg.key_len > 0)
                        buf[msg.key_len] = ':';

                    log_splunk("sampler=statsd event=bad_key key='%.*s'", curLen, cur);

                    brubeck_server_mark_dropped(server);
                    continue;
                }

                //log_splunk("key: %s, value: %s",msg.key, msg.value);

                metric = brubeck_metric_find(server, msg.key, msg.key_len, msg.type);
                if (metric != NULL)
                    brubeck_metric_record(metric, msg.value);

                processed += curLen +1;
                buf += curLen +1;
            }while(processed < len);
		}
	}
}