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 Aug 28, 2023
1 parent 989e8cd commit cee14dc
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 @@ -33,6 +33,13 @@ NGINX Unit updated to 1.31.0.
date="" time=""
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");

This comment has been minimized.

Copy link
@hongzhidao

hongzhidao Aug 29, 2023

I'd suggest unit_str instead of about_str.

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);

This comment has been minimized.

Copy link
@hongzhidao

hongzhidao Aug 29, 2023

The static variables are used as the object key, I prefer not to introduce cver_str here. And we can use it like this.

nxt_str_t version; // move it together with the name above.

nxt_str_set(&version, NXT_VERSION);
nxt_conf_set_member_string(obj, &ver_str, &version, 0);

It's more readable.

This comment has been minimized.

Copy link
@Pavlusha311245

Pavlusha311245 Aug 29, 2023

Author Owner

For the socket and other variables, do we also remove them from static and define them via nxt_str_set?

This comment has been minimized.

Copy link
@hongzhidao

hongzhidao Aug 29, 2023

Yes, separating them is better.

Actually, your way is ok, and the QPS of the status API is not as high as the http traffic request.
So here code readability is more important.
At the moment, I'd suggest not to introduce control socket information. I'm not sure if we need to export it.

My thought is the status API is to export the runtime information that users can't get through unitd directly like reading source code. Like version, configuration reload time, the total number of configuration reloads, etc, and they are helpful for users to track on Unit runtime phase.

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 cee14dc

Please sign in to comment.