From 22c3ad4b12cd8f771ea4adcc02776ce6e04d967e Mon Sep 17 00:00:00 2001 From: XiaoBao Date: Thu, 25 Jan 2024 11:19:26 +0800 Subject: [PATCH] upgrade to 1.3.8beta --- README.md | 2 ++ nginx/views.py | 15 +++++++++++++- templates/dashboard/view.html | 38 ++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 164a766..4c9111d 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ ## 更新(2024-01-23) * 新增 [nginx-module-vts](https://github.com/vozlt/nginx-module-vts) 模块,实现更完善的流量监测能力 + * 新增 Dashboard 页面 Nginx 启动时间显示 + > API 中同步增加字段,单位为 ms,可以自行转换 * 新增 Dashboard 页面中 TCP 流量监测功能 * 新增 Dashboard 页面中流量统计 MB/GB 单位自适应显示,单位超过 GB 会加粗显示 * 新增 Prometheus 格式流量监测接口 diff --git a/nginx/views.py b/nginx/views.py index e95dd2c..31060ed 100644 --- a/nginx/views.py +++ b/nginx/views.py @@ -208,13 +208,26 @@ def get_sys_info(): if nic != "lo": nic_info.append({'nic':nic,'address':addrs[0].address}) uname = platform.uname() + uptime = 0 + try: + url = "http://127.0.0.1:9191/req_status_http/format/json" + resp = post_request(url).json() + if resp: + load_msec = resp.get('loadMsec', 0) + now_msec = resp.get('nowMsec', 0) + if load_msec and now_msec: + uptime = now_msec - load_msec + except Exception as e: + logger.error(str(e)) + sysinfo = { 'nic' : nic_info, 'platform' : { 'node' : uname[1], 'system' : uname[0], 'release' : uname[2], - 'processor' : uname[4] + 'processor' : uname[4], + 'uptime': uptime }, 'nginx' : run_shell('nginx -v')['output'].replace('\nnginx version: ','(').split(':')[1].strip() + ")" } diff --git a/templates/dashboard/view.html b/templates/dashboard/view.html index 2183402..79b4573 100644 --- a/templates/dashboard/view.html +++ b/templates/dashboard/view.html @@ -12,7 +12,7 @@

系统状态

Nginx 版本 - {{ sysinfo.nginx }} + {{ sysinfo.nginx }} 主机名 @@ -292,6 +292,39 @@

请求统计

} } +function get_uptime() { + var uptime_ms = {{ sysinfo.platform.uptime }}; + if (uptime_ms != 0 ) { + var seconds = Math.floor(uptime_ms/ 1000); + var minutes = Math.floor(seconds / 60); + var hours = Math.floor(minutes / 60); + var days = Math.floor(hours / 24); + + hours = hours % 24; + minutes = minutes % 60; + seconds = seconds % 60; + + var timeString = ""; + + if (days > 0) { + timeString += days + " 天 "; + } + if (hours > 0) { + timeString += hours + " 时 "; + } + if (minutes > 0) { + timeString += minutes + " 分 "; + } + if (seconds > 0) { + timeString += seconds + " 秒"; + } + + $('#sp_uptime').removeClass() + $('#sp_uptime').addClass('label label-success') + $('#sp_uptime').text(timeString) + } +} + function get_status_info() { jQuery.ajax({ type: 'post', @@ -308,6 +341,8 @@

请求统计

$('#sp_nginx_status').addClass('label label-danger') $('#sp_nginx_status').text('已停止') } + + if (!p.context.sysstatus.nginx_config_status) { $('#sp_nginx_config_status').removeClass() $('#sp_nginx_config_status').addClass('label label-danger') @@ -359,6 +394,7 @@

请求统计

add_data(true, 0, 0, 0); } get_status_info() +get_uptime() window.setInterval(get_status_info, 10000); {% endblock %}