#include "fpm_config.h" #include <sys/types.h> #include <systemd/sd-daemon.h> #include "fpm.h" #include "fpm_clock.h" #include "fpm_worker_pool.h" #include "fpm_scoreboard.h" #include "zlog.h" #include "fpm_systemd.h" static void fpm_systemd() /* {{{ */ { static unsigned long int last=0; struct fpm_worker_pool_s *wp; unsigned long int requests=0, slow_req=0; int active=0, idle=0; for (wp = fpm_worker_all_pools; wp; wp = wp->next) { if (wp->scoreboard) { active += wp->scoreboard->active; idle += wp->scoreboard->idle; requests += wp->scoreboard->requests; slow_req += wp->scoreboard->slow_rq; } } /* zlog(ZLOG_DEBUG, "systemd %s (Processes active:%d, idle:%d, Requests:%lu, slow:%lu, Traffic:%.3greq/sec)", fpm_global_config.systemd_watchdog ? "watchdog" : "heartbeat", active, idle, requests, slow_req, ((float)requests - last) * 1000.0 / fpm_global_config.systemd_interval); */ if (0 > sd_notifyf(0, "READY=1\n%s" "STATUS=Processes active: %d, idle: %d, Requests: %lu, slow: %lu, Traffic: %.3greq/sec", fpm_global_config.systemd_watchdog ? "WATCHDOG=1\n" : "", active, idle, requests, slow_req, ((float)requests - last) * 1000.0 / fpm_global_config.systemd_interval)) { zlog(ZLOG_NOTICE, "failed to notify status to systemd"); } last = requests; } /* }}} */ void fpm_systemd_heartbeat(struct fpm_event_s *ev, short which, void *arg) /* {{{ */ { static struct fpm_event_s heartbeat; if (fpm_globals.parent_pid != getpid()) { return; /* sanity check */ } if (which == FPM_EV_TIMEOUT) { fpm_systemd(); return; } if (0 > sd_notifyf(0, "READY=1\n" "STATUS=Ready to handle connections\n" "MAINPID=%lu", (unsigned long) getpid())) { zlog(ZLOG_WARNING, "failed to notify start to systemd"); } else { zlog(ZLOG_DEBUG, "have notify start to systemd"); } /* first call without setting which to initialize the timer */ if (fpm_global_config.systemd_interval > 0) { fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_systemd_heartbeat, NULL); fpm_event_add(&heartbeat, fpm_global_config.systemd_interval); zlog(ZLOG_NOTICE, "systemd monitor interval set to %dms", fpm_global_config.systemd_interval); } else { zlog(ZLOG_NOTICE, "systemd monitor disabled"); } } /* }}} */ int fpm_systemd_conf() /* {{{ */ { char *watchdog; int interval = 0; watchdog = getenv("WATCHDOG_USEC"); if (watchdog) { /* usec to msec, and half the configured delay */ interval = (int)(atol(watchdog) / 2000L); zlog(ZLOG_DEBUG, "WATCHDOG_USEC=%s, interval=%d", watchdog, interval); } if (interval > 1000) { if (fpm_global_config.systemd_interval > 0) { zlog(ZLOG_WARNING, "systemd_interval option ignored"); } zlog(ZLOG_NOTICE, "systemd watchdog configured to %.3gsec", (float)interval / 1000.0); fpm_global_config.systemd_watchdog = 1; fpm_global_config.systemd_interval = interval; } else if (fpm_global_config.systemd_interval < 0) { /* not set => default value */ fpm_global_config.systemd_interval = FPM_SYSTEMD_DEFAULT_HEARTBEAT; } else { /* sec to msec */ fpm_global_config.systemd_interval *= 1000; } return 0; } /* }}} */
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
events | Folder | 0755 |
|
|
fastcgi.c | File | 25.94 KB | 0644 |
|
fastcgi.h | File | 4.47 KB | 0644 |
|
fpm.c | File | 2.84 KB | 0644 |
|
fpm.h | File | 1.13 KB | 0644 |
|
fpm_arrays.h | File | 1.82 KB | 0644 |
|
fpm_atomic.h | File | 3.95 KB | 0644 |
|
fpm_children.c | File | 10.99 KB | 0644 |
|
fpm_children.h | File | 873 B | 0644 |
|
fpm_cleanup.c | File | 849 B | 0644 |
|
fpm_cleanup.h | File | 519 B | 0644 |
|
fpm_clock.c | File | 2.23 KB | 0644 |
|
fpm_clock.h | File | 239 B | 0644 |
|
fpm_conf.c | File | 49.14 KB | 0644 |
|
fpm_conf.h | File | 2.43 KB | 0644 |
|
fpm_env.c | File | 5.39 KB | 0644 |
|
fpm_env.h | File | 491 B | 0644 |
|
fpm_events.c | File | 11.67 KB | 0644 |
|
fpm_events.h | File | 1.59 KB | 0644 |
|
fpm_log.c | File | 11.53 KB | 0644 |
|
fpm_log.h | File | 300 B | 0644 |
|
fpm_main.c | File | 62.74 KB | 0644 |
|
fpm_php.c | File | 6.42 KB | 0644 |
|
fpm_php.h | File | 1.23 KB | 0644 |
|
fpm_php_trace.c | File | 3.49 KB | 0644 |
|
fpm_process_ctl.c | File | 13.65 KB | 0644 |
|
fpm_process_ctl.h | File | 1.23 KB | 0644 |
|
fpm_request.c | File | 8.01 KB | 0644 |
|
fpm_request.h | File | 1.18 KB | 0644 |
|
fpm_scoreboard.c | File | 7.84 KB | 0644 |
|
fpm_scoreboard.h | File | 2.5 KB | 0644 |
|
fpm_shm.c | File | 1.23 KB | 0644 |
|
fpm_shm.h | File | 263 B | 0644 |
|
fpm_signals.c | File | 4.72 KB | 0644 |
|
fpm_signals.h | File | 315 B | 0644 |
|
fpm_sockets.c | File | 11.39 KB | 0644 |
|
fpm_sockets.h | File | 1006 B | 0644 |
|
fpm_status.c | File | 13.7 KB | 0644 |
|
fpm_status.h | File | 1.03 KB | 0644 |
|
fpm_stdio.c | File | 7.36 KB | 0644 |
|
fpm_stdio.h | File | 569 B | 0644 |
|
fpm_str.h | File | 483 B | 0644 |
|
fpm_systemd.c | File | 3.11 KB | 0644 |
|
fpm_systemd.h | File | 275 B | 0644 |
|
fpm_trace.c | File | 641 B | 0644 |
|
fpm_trace.h | File | 378 B | 0644 |
|
fpm_trace_ptrace.c | File | 1.6 KB | 0644 |
|
fpm_unix.c | File | 19.23 KB | 0644 |
|
fpm_unix.h | File | 518 B | 0644 |
|
fpm_worker_pool.c | File | 1.57 KB | 0644 |
|
fpm_worker_pool.h | File | 1.23 KB | 0644 |
|
zlog.c | File | 4.47 KB | 0644 |
|
zlog.h | File | 978 B | 0644 |
|