1
2 /*
3 * Copyright (C) NGINX, Inc.
4 */
5
6 #include <nxt_main.h>
7 #include <nxt_conf.h>
8 #include <nxt_status.h>
9
10
11 nxt_conf_value_t *
nxt_status_get(nxt_status_report_t * report,nxt_mp_t * mp)12 nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
13 {
14 size_t i;
15 nxt_str_t name;
16 nxt_int_t ret;
17 nxt_status_app_t *app;
18 nxt_conf_value_t *status, *obj, *apps, *app_obj;
19
20 static nxt_str_t conns_str = nxt_string("connections");
21 static nxt_str_t acc_str = nxt_string("accepted");
22 static nxt_str_t active_str = nxt_string("active");
23 static nxt_str_t idle_str = nxt_string("idle");
24 static nxt_str_t closed_str = nxt_string("closed");
25 static nxt_str_t reqs_str = nxt_string("requests");
26 static nxt_str_t total_str = nxt_string("total");
27 static nxt_str_t apps_str = nxt_string("applications");
28 static nxt_str_t procs_str = nxt_string("processes");
29 static nxt_str_t run_str = nxt_string("running");
30 static nxt_str_t start_str = nxt_string("starting");
31
32 status = nxt_conf_create_object(mp, 3);
33 if (nxt_slow_path(status == NULL)) {
34 return NULL;
35 }
36
37 obj = nxt_conf_create_object(mp, 4);
38 if (nxt_slow_path(obj == NULL)) {
39 return NULL;
40 }
41
42 nxt_conf_set_member(status, &conns_str, obj, 0);
43
44 nxt_conf_set_member_integer(obj, &acc_str, report->accepted_conns, 0);
45 nxt_conf_set_member_integer(obj, &active_str, report->accepted_conns
46 - report->closed_conns
47 - report->idle_conns, 1);
48 nxt_conf_set_member_integer(obj, &idle_str, report->idle_conns, 2);
49 nxt_conf_set_member_integer(obj, &closed_str, report->closed_conns, 3);
50
51 obj = nxt_conf_create_object(mp, 1);
52 if (nxt_slow_path(obj == NULL)) {
53 return NULL;
54 }
55
56 nxt_conf_set_member(status, &reqs_str, obj, 1);
57
58 nxt_conf_set_member_integer(obj, &total_str, report->requests, 0);
59
60 apps = nxt_conf_create_object(mp, report->apps_count);
61 if (nxt_slow_path(apps == NULL)) {
62 return NULL;
63 }
64
65 nxt_conf_set_member(status, &apps_str, apps, 2);
66
67 for (i = 0; i < report->apps_count; i++) {
68 app = &report->apps[i];
69
70 app_obj = nxt_conf_create_object(mp, 2);
71 if (nxt_slow_path(app_obj == NULL)) {
72 return NULL;
73 }
74
75 name.length = app->name.length;
76 name.start = nxt_pointer_to(report, (uintptr_t) app->name.start);
77
78 ret = nxt_conf_set_member_dup(apps, mp, &name, app_obj, i);
79 if (nxt_slow_path(ret != NXT_OK)) {
80 return NULL;
81 }
82
83 obj = nxt_conf_create_object(mp, 3);
84 if (nxt_slow_path(obj == NULL)) {
85 return NULL;
86 }
87
88 nxt_conf_set_member(app_obj, &procs_str, obj, 0);
89
90 nxt_conf_set_member_integer(obj, &run_str, app->processes, 0);
91 nxt_conf_set_member_integer(obj, &start_str, app->pending_processes, 1);
92 nxt_conf_set_member_integer(obj, &idle_str, app->idle_processes, 2);
93
94 obj = nxt_conf_create_object(mp, 1);
95 if (nxt_slow_path(obj == NULL)) {
96 return NULL;
97 }
98
99 nxt_conf_set_member(app_obj, &reqs_str, obj, 1);
100
101 nxt_conf_set_member_integer(obj, &active_str, app->active_requests, 0);
102 }
103
104 return status;
105 }
106