static ngx_int_t ngx_http_sysguard_handler(ngx_http_request_t *r) { ngx_http_sysguard_conf_t *glcf; if (r->main->sysguard_set) { return NGX_DECLINED; } glcf = ngx_http_get_module_loc_conf(r, ngx_http_sysguard_module); if (!glcf->enable) { return NGX_DECLINED; } r->main->sysguard_set = 1; /* load */ if (glcf->load != NGX_CONF_UNSET) { if (ngx_http_sysguard_cached_load_exptime < ngx_time()) { ngx_http_sysguard_update_load(r, glcf->interval); } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http sysguard handler load: %1.3f %1.3f %V %V", ngx_http_sysguard_cached_load * 1.0 / 1000, glcf->load * 1.0 / 1000, &r->uri, &glcf->load_action); if (ngx_http_sysguard_cached_load > glcf->load) { ngx_log_error(glcf->log_level, r->connection->log, 0, "sysguard load limited, current:%1.3f conf:%1.3f", ngx_http_sysguard_cached_load * 1.0 / 1000, glcf->load * 1.0 / 1000); return ngx_http_sysguard_do_redirect(r, &glcf->load_action); } } /* swap */ if (glcf->swap != NGX_CONF_UNSET) { if (ngx_http_sysguard_cached_mem_exptime < ngx_time()) { ngx_http_sysguard_update_mem(r, glcf->interval); } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http sysguard handler swap: %i %i %V %V", ngx_http_sysguard_cached_swapstat, glcf->swap, &r->uri, &glcf->swap_action); if (ngx_http_sysguard_cached_swapstat > glcf->swap) { ngx_log_error(glcf->log_level, r->connection->log, 0, "sysguard swap limited, current:%i conf:%i", ngx_http_sysguard_cached_swapstat, glcf->swap); return ngx_http_sysguard_do_redirect(r, &glcf->swap_action); } } /* mem free */ if (glcf->free != NGX_CONF_UNSET_SIZE) { if (ngx_http_sysguard_cached_mem_exptime < ngx_time()) { ngx_http_sysguard_update_mem(r, glcf->interval); } if (ngx_http_sysguard_cached_free != NGX_CONF_UNSET_SIZE) { ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http sysguard handler free: %uz %uz %V %V", ngx_http_sysguard_cached_free, glcf->free, &r->uri, &glcf->free_action); if (ngx_http_sysguard_cached_free < glcf->free) { ngx_log_error(glcf->log_level, r->connection->log, 0, "sysguard free limited, current:%uzM conf:%uzM", ngx_http_sysguard_cached_free / 1024 / 1024, glcf->free / 1024 / 1024); return ngx_http_sysguard_do_redirect(r, &glcf->free_action); } } } return NGX_DECLINED; }
static ngx_int_t ngx_http_sysguard_handler(ngx_http_request_t *r) { ngx_http_sysguard_conf_t *glcf; if (r->main->sysguard_set) { return NGX_DECLINED; } glcf = ngx_http_get_module_loc_conf(r, ngx_http_sysguard_module); if (!glcf->enable) { return NGX_DECLINED; } r->main->sysguard_set = 1; /* load */ if (glcf->load >= 0) { if (ngx_http_sysguard_cached_load_exptime < ngx_time()) { ngx_http_sysguard_update_load(r, glcf->interval); } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http sysguard handler load: %i %i %V %V", ngx_http_sysguard_cached_load, glcf->load, &r->uri, &glcf->load_action); if (ngx_http_sysguard_cached_load > glcf->load) { ngx_log_error(glcf->log_level, r->connection->log, 0, "sysguard load limited, current:%i conf:%i", ngx_http_sysguard_cached_load, glcf->load); return ngx_http_sysguard_do_redirect(r, &glcf->load_action); } } /* swap */ if (glcf->swap >= 0) { if (ngx_http_sysguard_cached_swap_exptime < ngx_time()) { ngx_http_sysguard_update_swap(r, glcf->interval); } ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http sysguard handler swap: %i %i %V %V", ngx_http_sysguard_cached_swapstat, glcf->swap, &r->uri, &glcf->swap_action); if (ngx_http_sysguard_cached_swapstat > glcf->swap) { ngx_log_error(glcf->log_level, r->connection->log, 0, "sysguard swap limited, current:%i conf:%i", ngx_http_sysguard_cached_swapstat, glcf->swap); return ngx_http_sysguard_do_redirect(r, &glcf->swap_action); } } return NGX_DECLINED; }