/* * 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 . */ /**@defgroup monitor_proc Monitoring process * @brief Collect informations and run a monitoring server providing statistics * @ingroup main_proc */ /**@defgroup monitoring Monitoring server * @brief A small UDP server for monitoring * * PyFCGI have the ability to listen on a UDP socket, replying to simple * queries (or simple stats). * @ingroup monitor_proc */ /**@file monitor.h * @brief Monitoring server headers * @ingroup monitoring */ #ifndef _MONITOR__H___ #define _MONITOR__H___ #include "config.h" #include /* fcgi library; put it first*/ #include #include #include #include #include #include #define UNIX_SOCKPATH_MAX 108 #define PYFCGI_MONITOR_STREAM_BACKLOG 5 typedef struct pyfcgi_monitor_s pyfcgi_monitor_t; typedef union pyfcgi_monitor_addr_u pyfcgi_monitor_addr_t; #include "conf.h" #include "logger.h" #include "stats.h" union pyfcgi_monitor_addr_u { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; }; struct pyfcgi_monitor_s { int sockserv; int sockcli; int sockargs[3]; pyfcgi_monitor_addr_t addr; }; /**@brief Attempt to init unitialized IPC component * * If an error occured it will be logged, and the init should be retry latter. * * @note the monitor process uses IPC_WREQS to count requests IPC_SEMST for * SHM syn and IPC_SHMST for SHM initalization */ int pyfcgi_monitor_IPC_init(); /**@brief Start the stats server monitoring server * @return PID of the child process and -1 on error * @note When called the configuration has to be parsed */ pid_t pyfcgi_spawn_monitor(); /**@brief Main function for socket stats server * * Create the socket & bind to indicated address. If bind fails, sleep 30s, then * exit, in order to retry the whole process */ void pyfcgi_monitor_loop(); void pyfcgi_monitor_stream_loop(); void pyfcgi_monitor_dgram_loop(); /**@brief Check socket URL validity * @param sockurl the URL to check * @return -1 if error else 0 * @note Logs error using dprintf(2, ...) because this function will * be called when checking configuration */ int pyfcgi_monitor_check_sock(const char* sockurl); /**@brief Parse stored socket URL * @param sockurl the URL to parse * @param sockargs socket creation arguments * @param listen_addr the addr to bind to * @return 0 if no error else -1 * @todo add support for xxx://[IPV6]:port */ int pyfcgi_monitor_parse_sock(const char* sockurl, int sockargs[3], pyfcgi_monitor_addr_t* listen_addr); /**@brief Parse an addres:port string in a sockaddr_in * @param addr_str the hostname:port string * @param socktype socket family * @param listen_addr the addr pointer * @param domain if not NULL will be set to choosen domain * @return 0 if no erro else -1 * @todo add support for xxx://[IPV6]:port */ int pyfcgi_monitor_parse_inet_addr(const char* addr_str, int socktype, pyfcgi_monitor_addr_t* listen_addr, int* domain); /**@brief Monitor process sighandler */ void pyfcgi_monitor_sighandler(int signum); /**@brief Monitor timeout sighandler */ void pyfcgi_monitor_timeout(int signum); #endif