Exemple #1
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);
                }
        }

}
Exemple #2
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;
		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 == EAGAIN || res == EINTR || res == 0)
			continue;

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

		if (res < 0) {
			brubeck_server_mark_dropped(server);
			continue;
		}

		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_statsd_msg_parse(&msg, buf, len) < 0) {
				brubeck_server_mark_dropped(server);
				log_splunk("sampler=statsd event=packet_drop");
				continue;
			}

			metric = brubeck_metric_find(server, msg.key, msg.key_len, msg.type);
			if (metric != NULL)
				brubeck_metric_record(metric, msg.value);
		}
	}
}
Exemple #3
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);
            }

	}

}
Exemple #4
0
void brubeck_statsd_packet_parse(struct brubeck_server *server, char *buffer, char *end)
{
	struct brubeck_statsd_msg msg;
	struct brubeck_metric *metric;

	while (buffer < end) {
		char *stat_end = memchr(buffer, '\n', end - buffer);
		if (!stat_end)
			stat_end = end;

		if (brubeck_statsd_msg_parse(&msg, buffer, stat_end) < 0) {
			brubeck_stats_inc(server, errors);
			log_splunk("sampler=statsd event=packet_drop");
		} else {
			brubeck_stats_inc(server, metrics);
			metric = brubeck_metric_find(server, msg.key, msg.key_len, msg.type);
			if (metric != NULL)
				brubeck_metric_record(metric, msg.value, msg.sample_freq);
		}

		/* move buf past this stat */
		buffer = stat_end + 1;
	}
}
Exemple #5
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);
		}
	}
}