/** * Initialise the polling system we are using for the gateway. * * In this case we are using the Linux epoll mechanism */ void poll_init() { int i; if (epoll_fd != -1) return; if ((epoll_fd = epoll_create(MAX_EVENTS)) == -1) { perror("epoll_create"); exit(-1); } memset(&pollStats, 0, sizeof(pollStats)); memset(&queueStats, 0, sizeof(queueStats)); bitmask_init(&poll_mask); n_threads = config_threadcount(); if ((thread_data = (THREAD_DATA *)malloc(n_threads * sizeof(THREAD_DATA))) != NULL) { for (i = 0; i < n_threads; i++) { thread_data[i].state = THREAD_STOPPED; } } #if MUTEX_EPOLL simple_mutex_init(&epoll_wait_mutex, "epoll_wait_mutex"); #endif hktask_add("Load Average", poll_loadav, NULL, POLL_LOAD_FREQ); n_avg_samples = 15 * 60 / POLL_LOAD_FREQ; avg_samples = (double *)malloc(sizeof(double) * n_avg_samples); for (i = 0; i < n_avg_samples; i++) avg_samples[i] = 0.0; evqp_samples = (int *)malloc(sizeof(int) * n_avg_samples); for (i = 0; i < n_avg_samples; i++) evqp_samples[i] = 0.0; number_poll_spins = config_nbpolls(); max_poll_sleep = config_pollsleep(); #if PROFILE_POLL plog = memlog_create("EventQueueWaitTime", ML_LONG, 10000); #endif }
/** * Return some basic statistics from the router in response to a COM_STATISTICS * request. * * @param router The router instance * @param session The connection that requested the statistics * @param queue The statistics request * * @return non-zero on sucessful send */ static int maxinfo_statistics(INFO_INSTANCE *router, INFO_SESSION *session, GWBUF *queue) { char result[1000], *ptr; GWBUF *ret; int len; snprintf(result, 1000, "Uptime: %u Threads: %u Sessions: %u ", maxscale_uptime(), config_threadcount(), serviceSessionCountAll()); if ((ret = gwbuf_alloc(4 + strlen(result))) == NULL) return 0; len = strlen(result); ptr = GWBUF_DATA(ret); *ptr++ = len & 0xff; *ptr++ = (len & 0xff00) >> 8; *ptr++ = (len & 0xff0000) >> 16; *ptr++ = 1; strncpy(ptr, result, len); return session->dcb->func.write(session->dcb, ret); }