12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- /**@file stats.h
- * @ingroup monitoring */
- #ifndef _STATS__H___
- #define _STATS__H___
- #include "config.h"
-
- #include <fcgiapp.h>
-
- #include <stdarg.h>
- #include <signal.h>
- #include <string.h>
-
- #define PYFCGI_STATS_REQS_SAMPLES (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_REQS_SAMPLES];
- /**@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);
-
- int pyfcgi_stats_avg(const int[], int*, 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
|