Skip to content

Commit

Permalink
Added unit section to status endpoint nginx#928
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Zavadski <[email protected]>
  • Loading branch information
Pavlusha311245 authored and PaulZavadski committed Dec 12, 2023
1 parent b6216f0 commit 30501e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions docs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ NGINX Unit updated to 1.31.0.
date="2023-08-31" time="18:00:00 +0300"
packager="Nginx Packaging &lt;[email protected]&gt;">

<change type="feature">
<para>
added unit section to /status endpoint.
unit section is about web-server version, control_socket and etc.
</para>
</change>

<change type="change">
<para>
if building with njs, version 0.8.0 or later is now required.
Expand Down
23 changes: 19 additions & 4 deletions src/nxt_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
nxt_status_app_t *app;
nxt_conf_value_t *status, *obj, *apps, *app_obj;

static nxt_str_t about_str = nxt_string("unit");
static nxt_str_t ver_str = nxt_string("version");
static nxt_str_t socket_str = nxt_string("control_socket");
static nxt_str_t cver_str = nxt_string(NXT_VERSION);
static nxt_str_t csocket_str = nxt_string(NXT_CONTROL_SOCK);
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");
Expand All @@ -29,17 +34,27 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
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);
status = nxt_conf_create_object(mp, 4);
if (nxt_slow_path(status == NULL)) {
return NULL;
}

obj = nxt_conf_create_object(mp, 2);
if (nxt_slow_path(obj == NULL)) {
return NULL;
}

nxt_conf_set_member(status, &about_str, obj, 0);

nxt_conf_set_member_string(obj, &ver_str, &cver_str, 0);
nxt_conf_set_member_string(obj, &socket_str, &csocket_str, 1);

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(status, &conns_str, obj, 1);

nxt_conf_set_member_integer(obj, &acc_str, report->accepted_conns, 0);
nxt_conf_set_member_integer(obj, &active_str, report->accepted_conns
Expand All @@ -53,7 +68,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
return NULL;
}

nxt_conf_set_member(status, &reqs_str, obj, 1);
nxt_conf_set_member(status, &reqs_str, obj, 2);

nxt_conf_set_member_integer(obj, &total_str, report->requests, 0);

Expand All @@ -62,7 +77,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
return NULL;
}

nxt_conf_set_member(status, &apps_str, apps, 2);
nxt_conf_set_member(status, &apps_str, apps, 3);

for (i = 0; i < report->apps_count; i++) {
app = &report->apps[i];
Expand Down

0 comments on commit 30501e1

Please sign in to comment.