Skip to content

Commit

Permalink
upgrade to 1.3.8beta
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoBao committed Jan 25, 2024
1 parent dba9e70 commit 22c3ad4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 格式流量监测接口
Expand Down
15 changes: 14 additions & 1 deletion nginx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() + ")"
}
Expand Down
38 changes: 37 additions & 1 deletion templates/dashboard/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h3 class="box-title">系统状态</h3>
<tbody>
<tr>
<td class="pull-right"><strong>Nginx 版本</strong></td>
<td>{{ sysinfo.nginx }} <span id="sp_nginx_status"></span> <span id="sp_nginx_config_status"></span></td>
<td>{{ sysinfo.nginx }} <span id="sp_nginx_status"></span> <span id="sp_nginx_config_status"></span><span id="sp_uptime"></span></td>
</tr>
<tr>
<td class="pull-right"><strong>主机名</strong></td>
Expand Down Expand Up @@ -292,6 +292,39 @@ <h3 class="box-title">请求统计</h3>
}
}

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',
Expand All @@ -308,6 +341,8 @@ <h3 class="box-title">请求统计</h3>
$('#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')
Expand Down Expand Up @@ -359,6 +394,7 @@ <h3 class="box-title">请求统计</h3>
add_data(true, 0, 0, 0);
}
get_status_info()
get_uptime()
window.setInterval(get_status_info, 10000);
</script>
{% endblock %}

0 comments on commit 22c3ad4

Please sign in to comment.