Example #1
0
void graphite_loop(void *d) {
	struct callmaster *cm = d;

	if (!cm->conf.graphite_interval) {
		ilog(LOG_WARNING,"Graphite send interval was not set. Setting it to 1 second.");
		cm->conf.graphite_interval=1;
	}

	connect_to_graphite_server(&cm->conf.graphite_ep);

	while (!g_shutdown)
		graphite_loop_run(cm,cm->conf.graphite_interval); // time in seconds
}
Example #2
0
static void graphite_loop(void *d) {
	struct callmaster *cm = d;

	if (!graphite_interval) {
		ilog(LOG_WARNING,"Graphite send interval was not set. Setting it to 1 second.");
		graphite_interval=1;
	}

	connect_to_graphite_server(graphite_ip,graphite_port);

	while (!global_shutdown)
		graphite_loop_run(cm,graphite_interval); // time in seconds
}
Example #3
0
void graphite_loop_run(struct callmaster* callmaster, int seconds) {

	int rc=0;
	fd_set wfds;
	FD_ZERO(&wfds);
	struct timeval tv;
	int optval=0;
	socklen_t optlen=sizeof(optval);

	if (connectinprogress && graphite_sock.fd >= 0) {
		FD_SET(graphite_sock.fd,&wfds);
		tv.tv_sec = 0;
		tv.tv_usec = 1000000;

		rc = select (graphite_sock.fd+1, NULL, &wfds, NULL, &tv);
		if ((rc == -1) && (errno == EINTR)) {
			ilog(LOG_ERROR,"Error on the socket.");
			close_socket(&graphite_sock);
			return;
		} else if (rc==0) {
			// timeout
			return;
		} else {
			if (!FD_ISSET(graphite_sock.fd,&wfds)) {
				ilog(LOG_WARN,"fd active but not the graphite fd.");
			close_socket(&graphite_sock);
				return;
			}
			rc = getsockopt(graphite_sock.fd, SOL_SOCKET, SO_ERROR, &optval, &optlen);
			if (rc) ilog(LOG_ERROR,"getsockopt failure.");
			if (optval != 0) {
				ilog(LOG_ERROR,"Socket connect failed. fd: %i, Reason: %s\n",graphite_sock.fd, strerror(optval));
				close_socket(&graphite_sock);
				return;
			}
			ilog(LOG_INFO, "Graphite server connected.");
			connectinprogress=0;
			next_run=0; // fake next run to skip sleep after reconnect
		}
	}

	gettimeofday(&g_now, NULL);
	if (g_now.tv_sec < next_run) {
		usleep(100000);
		return;
	}

	next_run = g_now.tv_sec + seconds;

	if (!cm)
		cm = callmaster;

	if (graphite_sock.fd < 0 && !connectinprogress) {
		rc = connect_to_graphite_server(graphite_ep);
	}

	if (graphite_sock.fd >= 0 && !connectinprogress) {
		add_total_calls_duration_in_interval(cm, &graphite_interval_tv);

		rc = send_graphite_data(&graphite_stats);
		gettimeofday(&cm->latest_graphite_interval_start, NULL);
		if (rc<0) {
			ilog(LOG_ERROR,"Sending graphite data failed.");
		}

		copy_with_lock(&cm->totalstats_lastinterval, &graphite_stats, &cm->totalstats_lastinterval.total_average_lock);
	}

}