Skip to content

Commit

Permalink
Added unit section to status endpoint nginx#928
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlusha311245 committed Dec 30, 2023
1 parent 49aee67 commit 786e55a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
15 changes: 15 additions & 0 deletions docs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ NGINX Unit updated to 1.32.0.
</para>
</change>

<change type="feature">
<para>
added unit section to /status endpoint.
unit section is about web-server version, config last load time and config update generation
</para>
</change>


<change type="feature">
<para>
$request_id variable contains a string that is formed using random data and
Expand Down Expand Up @@ -166,6 +174,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
8 changes: 5 additions & 3 deletions src/nxt_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <nxt_conf.h>
#include <nxt_status.h>
#include <nxt_cert.h>
#include <nxt_script.h>


typedef struct {
nxt_conf_value_t *root;
Expand Down Expand Up @@ -1633,7 +1631,7 @@ nxt_controller_status_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
req = data;

if (msg->port_msg.type == NXT_PORT_MSG_RPC_READY) {
status = nxt_status_get((nxt_status_report_t *) msg->buf->mem.pos,
status = nxt_status_get(task, (nxt_status_report_t *) msg->buf->mem.pos,
req->conn->mem_pool);
} else {
status = NULL;
Expand Down Expand Up @@ -2239,8 +2237,10 @@ nxt_controller_conf_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
{
nxt_controller_request_t *req;
nxt_controller_response_t resp;
nxt_runtime_t *rt;

req = data;
rt = task->thread->runtime;

nxt_debug(task, "controller conf ready: %*s",
nxt_buf_mem_used_size(&msg->buf->mem), msg->buf->mem.pos);
Expand All @@ -2256,6 +2256,8 @@ nxt_controller_conf_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,

nxt_controller_conf_store(task, req->conf.root);

rt->conf_gen++;

resp.status = 200;
resp.title = (u_char *) "Reconfiguration done.";

Expand Down
1 change: 1 addition & 0 deletions src/nxt_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt)
rt->state = NXT_STATEDIR;
rt->control = NXT_CONTROL_SOCK;
rt->tmp = NXT_TMPDIR;
rt->conf_gen = 0;

nxt_memzero(&rt->capabilities, sizeof(nxt_capabilities_t));

Expand Down
3 changes: 3 additions & 0 deletions src/nxt_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct nxt_runtime_s {
const char *control;
const char *tmp;

nxt_int_t conf_gen;
nxt_time_t conf_ltime;

nxt_str_t certs;
nxt_str_t scripts;

Expand Down
30 changes: 25 additions & 5 deletions src/nxt_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@


nxt_conf_value_t *
nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
nxt_status_get(nxt_task_t *task, nxt_status_report_t *report, nxt_mp_t *mp)
{
size_t i;
nxt_str_t name;
nxt_str_t version;
nxt_int_t ret;
nxt_status_app_t *app;
nxt_conf_value_t *status, *obj, *apps, *app_obj;
nxt_runtime_t *rt;

rt = task->thread->runtime;

static nxt_str_t unit_str = nxt_string("unit");
static nxt_str_t ver_str = nxt_string("version");
static nxt_str_t gen_str = nxt_string("generation");
// static nxt_str_t ltime_str = nxt_string("load_time");
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 +37,29 @@ 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, 3);
if (nxt_slow_path(obj == NULL)) {
return NULL;
}

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

nxt_str_set(&version, NXT_VERSION);
nxt_conf_set_member_string(obj, &ver_str, &version, 0);
nxt_conf_set_member_integer(obj, &gen_str, rt->conf_gen, 1);
// nxt_conf_set_member_string(obj, &gen_str, rt->conf_gen, 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 +73,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 +82,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
2 changes: 1 addition & 1 deletion src/nxt_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct {
} nxt_status_report_t;


nxt_conf_value_t *nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp);
nxt_conf_value_t *nxt_status_get(nxt_task_t *task, nxt_status_report_t *report, nxt_mp_t *mp);


#endif /* _NXT_STATUS_H_INCLUDED_ */

0 comments on commit 786e55a

Please sign in to comment.