summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_status.c
diff options
context:
space:
mode:
authorKonstantin Pavlov <thresh@nginx.com>2022-09-13 13:17:16 +0400
committerKonstantin Pavlov <thresh@nginx.com>2022-09-13 13:17:16 +0400
commitce964aa30b163e2b3263c5af57c1a6dae7d0cebb (patch)
tree26bf70c1a5991f6471fc4caed8628e068fdc0b7b /src/nxt_status.c
parenteba4c3c98fa1bf275d94df8c727f70692ae7eae1 (diff)
parent38bd7e76a134084ab95a4ee3125af1ccd7b35864 (diff)
downloadunit-ce964aa30b163e2b3263c5af57c1a6dae7d0cebb.tar.gz
unit-ce964aa30b163e2b3263c5af57c1a6dae7d0cebb.tar.bz2
Merged with the default branch.1.28.0-1
Diffstat (limited to 'src/nxt_status.c')
-rw-r--r--src/nxt_status.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/nxt_status.c b/src/nxt_status.c
new file mode 100644
index 00000000..f8002e86
--- /dev/null
+++ b/src/nxt_status.c
@@ -0,0 +1,105 @@
+
+/*
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_main.h>
+#include <nxt_conf.h>
+#include <nxt_status.h>
+
+
+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 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");
+ 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, 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(apps == 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(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(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;
+}