@@ -1022,9 +1022,53 @@ btn11info = s:taboption("infos", DummyValue, "btn11info")
10221022btn11info .rawhtml = true
10231023btn11info .cfgvalue = function (self , section )
10241024 local content = nixio .fs .readfile (" /tmp/easytier-cli_stats" ) or " "
1025- content = luci .util .trim (content or " " )
1025+ content = luci .util .trim (content or " " )
1026+
1027+ local translate_map = {
1028+ [" Metric Name" ] = " 指标名称" ,
1029+ [" Value" ] = " 值" ,
1030+ [" Labels" ] = " 标签" ,
1031+ [" compression_bytes_rx_after" ] = " 接收压缩后字节数" ,
1032+ [" compression_bytes_rx_before" ] = " 接收压缩前字节数" ,
1033+ [" compression_bytes_tx_after" ] = " 发送压缩后字节数" ,
1034+ [" compression_bytes_tx_before" ] = " 发送压缩前字节数" ,
1035+ [" peer_rpc_client_rx" ] = " 客户端 RPC 接收数" ,
1036+ [" peer_rpc_client_tx" ] = " 客户端 RPC 发送数" ,
1037+ [" peer_rpc_duration_ms" ] = " RPC 时长 (毫秒)" ,
1038+ [" peer_rpc_server_rx" ] = " 服务端 RPC 接收数" ,
1039+ [" peer_rpc_server_tx" ] = " 服务端 RPC 发送数" ,
1040+ [" traffic_bytes_rx" ] = " 接收字节数" ,
1041+ [" traffic_bytes_self_rx" ] = " 自身接收字节数" ,
1042+ [" traffic_bytes_self_tx" ] = " 自身发送字节数" ,
1043+ [" traffic_bytes_tx" ] = " 发送字节数" ,
1044+ [" traffic_packets_rx" ] = " 接收包数" ,
1045+ [" traffic_packets_self_rx" ] = " 自身接收包数" ,
1046+ [" traffic_packets_self_tx" ] = " 自身发送包数" ,
1047+ [" traffic_packets_tx" ] = " 发送包数" ,
1048+ [" network_name" ] = " 网络名称" ,
1049+ [" dst_peer_id" ] = " 目标节点ID" ,
1050+ [" src_peer_id" ] = " 源节点ID" ,
1051+ [" method_name" ] = " 方法名称" ,
1052+ [" service_name" ] = " 服务名称" ,
1053+ [" status" ] = " 状态" ,
1054+ [" success" ] = " 成功" ,
1055+ [" get_global_peer_map" ] = " 获取全局节点映射" ,
1056+ [" PeerCenterRpc" ] = " 节点中心RPC" ,
1057+ [" report_peers" ] = " 上报节点" ,
1058+ [" sync_route_info" ] = " 同步路由信息" ,
1059+ [" OspfRouteRpc" ] = " OSPF路由RPC"
1060+ }
1061+
1062+ local function escape_lua_pattern (s )
1063+ return s :gsub (" (%W)" ," %%%1" )
1064+ end
1065+
1066+ local html = {}
1067+ table.insert (html , [[
1068+ <div style="overflow:auto; max-width:100%;">
1069+ <table style="border-collapse:collapse;width:100%;font-family:monospace;">
1070+ ]] )
10261071
1027- local html = {}
10281072 local lines = {}
10291073 for line in content :gmatch (" [^\r\n ]+" ) do
10301074 table.insert (lines , line )
@@ -1039,32 +1083,36 @@ btn11info.cfgvalue = function(self, section)
10391083 for cell in line :gmatch (" |%s*([^|]+)%s*" ) do
10401084 local value = luci .util .trim (cell )
10411085 if rowIndex == 1 then
1042- if value == " Metric Name" then
1043- value = " 指标名称"
1044- elseif value == " Value" then
1045- value = " 值"
1046- elseif value == " Labels" then
1047- value = " 标签"
1086+ if translate_map [value ] then
1087+ value = translate_map [value ]
1088+ else
1089+ for k , v in pairs (translate_map ) do
1090+ local k_esc = escape_lua_pattern (k )
1091+ value = value :gsub (k_esc , v )
1092+ end
10481093 end
1094+ else
1095+ for k , v in pairs (translate_map ) do
1096+ local k_esc = escape_lua_pattern (k )
1097+ value = value :gsub (k_esc , v )
1098+ end
10491099 end
1050- table.insert (cells , value )
1100+ table.insert (cells , value )
10511101 end
10521102
10531103 if # cells > 0 then
10541104 parsed = true
10551105 local tr = {}
10561106 for i , c in ipairs (cells ) do
1057- local tag = rowIndex == 1 and " th" or " td"
1107+ local tag = ( rowIndex == 1 ) and " th" or " td"
10581108 local style = " padding:4px;text-align:left;white-space:nowrap;border:1px solid #ccc;"
1059-
10601109 if tag == " th" then
1061- style = " padding:6px;text-align:center;white-space:nowrap;border:1px solid #ccc;background:#f0f0f0;"
1110+ style = " padding:6px;text-align:center;white-space:nowrap;border:1px solid #ccc;background:#f0f0f0;"
10621111 elseif rowIndex % 2 == 0 then
10631112 style = style .. " background:#fafafa;"
1064- else
1113+ else
10651114 style = style .. " background:#ffffff;"
10661115 end
1067-
10681116 table.insert (tr , string.format (" <%s style='%s'>%s</%s>" , tag , style , luci .util .pcdata (c ), tag ))
10691117 end
10701118 table.insert (tableRows , " <tr>" .. table.concat (tr ) .. " </tr>" )
@@ -1073,17 +1121,16 @@ btn11info.cfgvalue = function(self, section)
10731121 end
10741122
10751123 if parsed then
1076- table.insert (html , [[
1077- <div style="overflow:auto; max-width:100%;">
1078- <table style="border-collapse:collapse;width:100%;font-family:monospace;">
1079- ]] )
1080- for _ , row in ipairs (tableRows ) do
1081- table.insert (html , row )
1082- end
1124+ for _ , rowHtml in ipairs (tableRows ) do
1125+ table.insert (html , rowHtml )
1126+ end
10831127 table.insert (html , " </table></div>" )
10841128 return table.concat (html , " \n " )
10851129 else
1086- return string.format (" <pre style='background:#f9f9f9;padding:8px;border:1px solid #ccc;white-space:pre-wrap;'>%s</pre>" , luci .util .pcdata (content ))
1130+ return string.format (
1131+ " <pre style='background:#f9f9f9;border:1px solid #ccc;padding:8px;white-space:pre-wrap;'>%s</pre>" ,
1132+ luci .xml .pcdata (content )
1133+ )
10871134 end
10881135end
10891136
@@ -1202,7 +1249,8 @@ http.setfilehandler(
12021249
12031250 os.execute (" chmod +x /tmp/easytier-core" )
12041251 os.execute (" chmod +x /tmp/easytier-cli" )
1205- os.execute (" chmod +x /tmp/easytier-web-embed" )
1252+ os.execute (" chmod +x /tmp/easytier-web-embed" )
1253+
12061254 end
12071255 end
12081256)
0 commit comments