From ce26dd729e6842c9ec8cc83bf091167e4c50a1ec Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 29 Aug 2022 14:27:09 +0800 Subject: Implemented basic statistics API. --- src/nxt_status.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/nxt_status.c (limited to 'src/nxt_status.c') diff --git a/src/nxt_status.c b/src/nxt_status.c new file mode 100644 index 00000000..529f6ebb --- /dev/null +++ b/src/nxt_status.c @@ -0,0 +1,102 @@ + +/* + * Copyright (C) NGINX, Inc. + */ + +#include +#include +#include + + +nxt_conf_value_t * +nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) +{ + size_t i; + nxt_str_t name; + nxt_int_t ret; + nxt_status_app_t *app; + nxt_conf_value_t *status, *obj, *apps, *app_obj; + + static nxt_str_t conns_str = nxt_string("connections"); + static nxt_str_t acc_str = nxt_string("accepted"); + static nxt_str_t active_str = nxt_string("active"); + static nxt_str_t idle_str = nxt_string("idle"); + static nxt_str_t closed_str = nxt_string("closed"); + static nxt_str_t reqs_str = nxt_string("requests"); + static nxt_str_t apps_str = nxt_string("applications"); + static nxt_str_t procs_str = nxt_string("processes"); + static nxt_str_t run_str = nxt_string("running"); + static nxt_str_t start_str = nxt_string("starting"); + + status = nxt_conf_create_object(mp, 3); + if (nxt_slow_path(status == NULL)) { + return NULL; + } + + obj = nxt_conf_create_object(mp, 4); + if (nxt_slow_path(obj == NULL)) { + return NULL; + } + + nxt_conf_set_member(status, &conns_str, obj, 0); + + nxt_conf_set_member_integer(obj, &acc_str, report->accepted_conns, 0); + nxt_conf_set_member_integer(obj, &active_str, report->accepted_conns + - report->closed_conns + - report->idle_conns, 1); + nxt_conf_set_member_integer(obj, &idle_str, report->idle_conns, 2); + nxt_conf_set_member_integer(obj, &closed_str, report->closed_conns, 3); + + obj = nxt_conf_create_object(mp, 0); + if (nxt_slow_path(obj == NULL)) { + return NULL; + } + + nxt_conf_set_member(status, &reqs_str, obj, 1); + + apps = nxt_conf_create_object(mp, report->apps_count); + if (nxt_slow_path(obj == NULL)) { + return NULL; + } + + nxt_conf_set_member(status, &apps_str, apps, 2); + + for (i = 0; i < report->apps_count; i++) { + app = &report->apps[i]; + + app_obj = nxt_conf_create_object(mp, 2); + if (nxt_slow_path(app_obj == NULL)) { + return NULL; + } + + name.length = app->name.length; + name.start = nxt_pointer_to(report, (uintptr_t) app->name.start); + + ret = nxt_conf_set_member_dup(apps, mp, &name, app_obj, i); + if (nxt_slow_path(ret != NXT_OK)) { + return NULL; + } + + obj = nxt_conf_create_object(mp, 3); + if (nxt_slow_path(app_obj == NULL)) { + return NULL; + } + + nxt_conf_set_member(app_obj, &procs_str, obj, 0); + + nxt_conf_set_member_integer(obj, &run_str, app->processes, 0); + nxt_conf_set_member_integer(obj, &start_str, app->pending_processes, 1); + nxt_conf_set_member_integer(obj, &idle_str, app->idle_processes, 2); + + obj = nxt_conf_create_object(mp, 1); + if (nxt_slow_path(app_obj == NULL)) { + return NULL; + } + + nxt_conf_set_member(app_obj, &reqs_str, obj, 1); + + nxt_conf_set_member_integer(obj, &active_str, app->active_requests, 0); + } + + return status; +} -- cgit From 3ea113fcb7261a0be3b9dc8d32c402da1bcfadaa Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Mon, 29 Aug 2022 14:32:20 +0800 Subject: Status: added requests count. --- src/nxt_status.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nxt_status.c') diff --git a/src/nxt_status.c b/src/nxt_status.c index 529f6ebb..12280019 100644 --- a/src/nxt_status.c +++ b/src/nxt_status.c @@ -23,6 +23,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) static nxt_str_t idle_str = nxt_string("idle"); static nxt_str_t closed_str = nxt_string("closed"); static nxt_str_t reqs_str = nxt_string("requests"); + static nxt_str_t total_str = nxt_string("total"); static nxt_str_t apps_str = nxt_string("applications"); static nxt_str_t procs_str = nxt_string("processes"); static nxt_str_t run_str = nxt_string("running"); @@ -47,13 +48,15 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) nxt_conf_set_member_integer(obj, &idle_str, report->idle_conns, 2); nxt_conf_set_member_integer(obj, &closed_str, report->closed_conns, 3); - obj = nxt_conf_create_object(mp, 0); + obj = nxt_conf_create_object(mp, 1); if (nxt_slow_path(obj == NULL)) { return NULL; } nxt_conf_set_member(status, &reqs_str, obj, 1); + nxt_conf_set_member_integer(obj, &total_str, report->requests, 0); + apps = nxt_conf_create_object(mp, report->apps_count); if (nxt_slow_path(obj == NULL)) { return NULL; -- cgit From 9d3b9dba40924229b0c4909b0a4c60d08214501c Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Tue, 6 Sep 2022 09:40:54 +0800 Subject: Status: fixed incorrect pointer in test operation. Found by Coverity (CID 380755). --- src/nxt_status.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nxt_status.c') diff --git a/src/nxt_status.c b/src/nxt_status.c index 12280019..f8002e86 100644 --- a/src/nxt_status.c +++ b/src/nxt_status.c @@ -58,7 +58,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) nxt_conf_set_member_integer(obj, &total_str, report->requests, 0); apps = nxt_conf_create_object(mp, report->apps_count); - if (nxt_slow_path(obj == NULL)) { + if (nxt_slow_path(apps == NULL)) { return NULL; } @@ -81,7 +81,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) } obj = nxt_conf_create_object(mp, 3); - if (nxt_slow_path(app_obj == NULL)) { + if (nxt_slow_path(obj == NULL)) { return NULL; } @@ -92,7 +92,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp) nxt_conf_set_member_integer(obj, &idle_str, app->idle_processes, 2); obj = nxt_conf_create_object(mp, 1); - if (nxt_slow_path(app_obj == NULL)) { + if (nxt_slow_path(obj == NULL)) { return NULL; } -- cgit