Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stats.h 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**@file stats.h
  20. * @ingroup monitoring */
  21. #ifndef _STATS__H___
  22. #define _STATS__H___
  23. #include "config.h"
  24. #include <fcgiapp.h>
  25. #include <stdarg.h>
  26. #include <signal.h>
  27. #include <string.h>
  28. #define PYFCGI_STATS_REQS_SAMPLES (900)
  29. typedef struct pyfcgi_stats_s pyfcgi_stats_t;
  30. #include "conf.h"
  31. #include "logger.h"
  32. struct pyfcgi_stats_s
  33. {
  34. /**@brief Request per seconds on 15 minutes */
  35. int reqs[PYFCGI_STATS_REQS_SAMPLES];
  36. /**@brief Current request index */
  37. int cur_req;
  38. /**@brief Repeating 1s timer sending SIGALRM */
  39. timer_t timerid;
  40. /**@brief Old SIGALRM handler */
  41. struct sigaction oldact;
  42. /**@brief Buffer to format the statistics before sending them */
  43. char *buff;
  44. size_t buff_ptr;
  45. size_t buff_len;
  46. };
  47. /**@brief Starts collecting statistics
  48. *
  49. * Set an handler for SIGALRM and set a repeating alarm each seconds
  50. * @warning designed to be called from monitor server process
  51. * @return -1 on error else 0
  52. */
  53. int pyfcgi_stats_init();
  54. /**@brief SIGALRM signal handler
  55. * @param int signum
  56. */
  57. void pyfcgi_stats_collector(int);
  58. /**@brief Format all stats in a buffer
  59. * @note uses the pyfcgi_stats.statsbuff buffer */
  60. size_t pyfcgi_stats_format();
  61. /**@brief Print in buffer using buff_ptr index
  62. *@note exit on mem alloc failure
  63. */
  64. void pyfcgi_stats_buffprintf(const char *fmt, ...);
  65. /**@brief Allocate the buffer with at least given space
  66. * @param size_t sz the minimum buffer size
  67. * @note allocation size is rounded
  68. * @return 0 if OK else -1
  69. */
  70. int pyfcgi_stats_reqbuff(size_t);
  71. const char *pyfcgi_stats_buff(const char **, size_t*);
  72. #endif