/* * Copyright (C) 2019 Weber Yann * * This file is part of PyFCGI. * * PyFCGI is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * PyFCGI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PyFCGI. If not, see . */ /**@file stats.h * @ingroup monitoring */ #ifndef _STATS__H___ #define _STATS__H___ #include "config.h" #include #include #include #include #define PYFCGI_STATS_SZ (900) typedef struct pyfcgi_stats_s pyfcgi_stats_t; #include "conf.h" #include "logger.h" struct pyfcgi_stats_s { /**@brief Request per seconds on 15 minutes */ int reqs[PYFCGI_STATS_SZ]; /**@brief Current request index */ int cur_req; /**@brief Repeating 1s timer sending SIGALRM */ timer_t timerid; /**@brief Old SIGALRM handler */ struct sigaction oldact; /**@brief Buffer to format the statistics before sending them */ char *buff; size_t buff_ptr; size_t buff_len; }; /**@brief Starts collecting statistics * * Set an handler for SIGALRM and set a repeating alarm each seconds * @warning designed to be called from monitor server process * @return -1 on error else 0 */ int pyfcgi_stats_init(); /**@brief SIGALRM signal handler * @param int signum */ void pyfcgi_stats_collector(int); /**@brief Format all stats in a buffer * @note uses the pyfcgi_stats.statsbuff buffer */ size_t pyfcgi_stats_format(); /**@brief Print in buffer using buff_ptr index *@note exit on mem alloc failure */ void pyfcgi_stats_buffprintf(const char *fmt, ...); /**@brief Allocate the buffer with at least given space * @param size_t sz the minimum buffer size * @note allocation size is rounded * @return 0 if OK else -1 */ int pyfcgi_stats_reqbuff(size_t); /**@brief Returns statistics about a 900s ringbuffer * * @param const int[PYFCGI_STATS_SZ] data : a 900 ringbuffer stats samples * @param int* idx_nxt next data index in ring buffer (allow interrupt * detection : when *idx_nxt changes) * @param int *last : last sample * @param double[4] avgs : average samples on 1, 5, 10 and 15 minutes * @return 0 if no error else -1 and set errno to EINTR */ int pyfcgi_stats_avg(const int[PYFCGI_STATS_SZ], int*, int*, double[4]); /**@brief Returns the formated buffer * @todo make @ref pyfcgi_stats_format() implement this functionnality * to remove this function... */ const char *pyfcgi_stats_buff(const char **, size_t*); #endif