diff --git a/.gitignore b/.gitignore
index 918757224..c49d2b0c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
Makefile
*.pyc
__pycache__/
+/.idea/
\ No newline at end of file
diff --git a/docs/changes.xml b/docs/changes.xml
index 6b1aaf712..3f0446f03 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -26,6 +26,14 @@ NGINX Unit updated to 1.32.0.
+
+
+added unit section to /status endpoint.
+unit section is about web-server version, config last load time and config update generation
+
+
+
+
$request_id variable contains a string that is formed using random data and
@@ -166,6 +174,13 @@ NGINX Unit updated to 1.31.0.
date="2023-08-31" time="18:00:00 +0300"
packager="Nginx Packaging <nginx-packaging@f5.com>">
+
+
+added unit section to /status endpoint.
+unit section is about web-server version, control_socket and etc.
+
+
+
if building with njs, version 0.8.0 or later is now required.
diff --git a/src/nxt_controller.c b/src/nxt_controller.c
index eb814321d..b7a02ca67 100644
--- a/src/nxt_controller.c
+++ b/src/nxt_controller.c
@@ -11,8 +11,6 @@
#include
#include
#include
-#include
-
typedef struct {
nxt_conf_value_t *root;
@@ -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;
@@ -2432,6 +2430,9 @@ nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf)
nxt_buf_t *b;
nxt_port_t *main_port;
nxt_runtime_t *rt;
+ time_t rawtime;
+ struct tm *timeinfo;
+ u_char buffer[25];
rt = task->thread->runtime;
@@ -2466,6 +2467,17 @@ nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf)
NXT_PORT_MSG_CONF_STORE | NXT_PORT_MSG_CLOSE_FD,
fd, 0, -1, b);
+ rt->conf_gen++;
+
+ time(&rawtime);
+ timeinfo = gmtime(&rawtime); //convert to UTC
+ strftime((char*)buffer, 25, "%Y-%m-%dT%H:%M:%S.000Z", timeinfo);
+
+ rt->conf_ltime.length = strlen((char*)buffer);
+ rt->conf_ltime.start = (u_char*) malloc(rt->conf_ltime.length + 1);
+
+ strcpy((char*)rt->conf_ltime.start, (char*)buffer);
+
return;
fail:
diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c
index 9bfabc750..71ad9c7cf 100644
--- a/src/nxt_runtime.c
+++ b/src/nxt_runtime.c
@@ -777,6 +777,9 @@ nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt)
nxt_sockaddr_t *sa;
nxt_file_name_str_t file_name;
const nxt_event_interface_t *interface;
+ time_t rawtime;
+ struct tm *timeinfo;
+ u_char buffer[25];
rt->daemon = 1;
rt->engine_connections = 256;
@@ -789,6 +792,16 @@ 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;
+
+ time(&rawtime);
+ timeinfo = gmtime(&rawtime); //convert to UTC
+ strftime((char*)buffer, 25, "%Y-%m-%dT%H:%M:%S.000Z", timeinfo);
+
+ rt->conf_ltime.length = strlen((char*)buffer);
+ rt->conf_ltime.start = (u_char*) malloc(rt->conf_ltime.length + 1);
+
+ strcpy((char*)rt->conf_ltime.start, (char*)buffer);
nxt_memzero(&rt->capabilities, sizeof(nxt_capabilities_t));
diff --git a/src/nxt_runtime.h b/src/nxt_runtime.h
index 66ec0106c..a3397bc82 100644
--- a/src/nxt_runtime.h
+++ b/src/nxt_runtime.h
@@ -73,6 +73,9 @@ struct nxt_runtime_s {
const char *control;
const char *tmp;
+ nxt_int_t conf_gen;
+ nxt_str_t conf_ltime;
+
nxt_str_t certs;
nxt_str_t scripts;
diff --git a/src/nxt_status.c b/src/nxt_status.c
index f8002e86e..23101903d 100644
--- a/src/nxt_status.c
+++ b/src/nxt_status.c
@@ -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");
@@ -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_string(obj, <ime_str, &rt->conf_ltime, 1);
+ nxt_conf_set_member_integer(obj, &gen_str, rt->conf_gen, 2);
+
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
@@ -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);
@@ -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];
diff --git a/src/nxt_status.h b/src/nxt_status.h
index a99ac7d0e..32a902fde 100644
--- a/src/nxt_status.h
+++ b/src/nxt_status.h
@@ -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_ */