From 7bf7abbc5734361340622f4ecbc9bbb0c280bfa2 Mon Sep 17 00:00:00 2001 From: aaajiulong <525763728@qq.com> Date: Fri, 20 Nov 2020 16:47:52 +0800 Subject: [PATCH] feature: Issue a pop-up window for abnormal requests --- examples/static/initial.js | 1 + packages/cjs/flask-state.js | 1 + packages/cjs/flask-state.min.js | 2 +- packages/umd/flask-state.js | 1 + packages/umd/flask-state.min.js | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/static/initial.js b/examples/static/initial.js index 64edcae..79f42f4 100644 --- a/examples/static/initial.js +++ b/examples/static/initial.js @@ -248,6 +248,7 @@ class MachineStatus { data: {'timeQuantum': days}, success: response => { if (response.code !== 200) { + window.alert(response.msg); return; } diff --git a/packages/cjs/flask-state.js b/packages/cjs/flask-state.js index 190c36f..2c5f7a9 100644 --- a/packages/cjs/flask-state.js +++ b/packages/cjs/flask-state.js @@ -261,6 +261,7 @@ data: {'timeQuantum': days}, success: response => { if (response.code !== 200) { + window.alert(response.msg); return; } diff --git a/packages/cjs/flask-state.min.js b/packages/cjs/flask-state.min.js index 0e1f3fa..22f035d 100644 --- a/packages/cjs/flask-state.min.js +++ b/packages/cjs/flask-state.min.js @@ -10,4 +10,4 @@ 'use strict'; -module.exports=function(e){var t={};function s(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,a){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(s.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(a,i,function(t){return e[t]}.bind(null,i));return a},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";const a=85,i=75,n=10,o=5,l=1048576;class r{constructor(e){this.language=e,this.mobile=r.isMobile(),this.index=0,this.ajax=new d,this.initFlaskStateContainer(this.mobile),this.setEventListener(),this.initFlaskStateLanguage(this.language),this.setInitParams(),this.mobile&&this.setTagChangeEventListener(this.consoleCpuChart,this.consoleMemoryChart,this.consoleLoadavgChart,this.consoleDiskusageChart),window.addEventListener("resize",(()=>{r.resizeChartTimer([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])}))}setFlaskStateData(){document.getElementById("fs-background").style.display="block",document.getElementById("fs-info-container").style.display="block",document.getElementsByTagName("body")[0].style.overflowX="hidden",document.getElementsByTagName("body")[0].style.overflowY="hidden",document.getElementById("fs-select-days").value="1",this.setCharts("1")}initFlaskStateContainer(){let e='

days

Host Status

Memory
CPU
Disk Usage
Load Avg
Uptime

Redis Status

Used Mem
Used Mem Rss
Mem Fragmentation Ratio
Cache Hits Ratio
24h Hits Ratio
Uptime
Connections
';this.mobile?e+='
':e+="
",document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend",e)}setEventListener(){if(window.addEventListener){document.getElementById("fs-info-close").addEventListener("click",(function(){document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out")})),document.getElementById("fs-background").addEventListener("click",(function(e){"fs-background"===String(e.target.id)&&(document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out"))}));let e=document.getElementById("fs-select-days");e.addEventListener("change",(()=>{this.setCharts(e.value)}))}}setTagChangeEventListener(...e){if(document.getElementById("fs-info-tab")){let t=document.getElementById("fs-info-tab").getElementsByTagName("li"),s=document.getElementById("fs-info-tab-memory"),a=t[0],i=0;const n={0:"fs-info-tab-memory",1:"fs-info-tab-cpu",2:"fs-info-tab-disk-usage",3:"fs-info-tab-loadavg"};for(let o of t){let t=document.getElementById(n[i]);o.children[0].addEventListener("click",(()=>{o.classList.add("active"),a.classList.remove("active"),s.classList.remove("fs-show"),t.classList.add("fs-show"),r.resizeChart(e),s=t,a=o})),i++}}}initFlaskStateLanguage(){0!==Object.keys(this.language).length&&(document.getElementById("fs-host-status-title").innerHTML=this.language.host_status,document.getElementById("fs-redis-status-title").innerHTML=this.language.redis_status,document.getElementById("fs-cpu").innerHTML=this.language.cpu,document.getElementById("fs-memory").innerHTML=this.language.memory,document.getElementById("fs-disk-usage").innerHTML=this.language.disk_usage,document.getElementById("fs-load-avg").innerHTML=this.language.load_avg,document.getElementById("fs-boot-seconds").innerHTML=this.language.boot_seconds,document.getElementById("fs-used-memory").innerHTML=this.language.used_memory,document.getElementById("fs-used-memory-rss").innerHTML=this.language.used_memory_rss,document.getElementById("fs-mem-fragmentation-ratio").innerHTML=this.language.mem_fragmentation_ratio,document.getElementById("fs-hits-ratio").innerHTML=this.language.hits_ratio,document.getElementById("fs-delta-hits-ratio").innerHTML=this.language.delta_hits_ratio,document.getElementById("fs-uptime-in-seconds").innerHTML=this.language.uptime_in_seconds,document.getElementById("fs-connected-clients").innerHTML=this.language.connected_clients,document.getElementById("fs-days").innerHTML=this.language.days)}setInitParams(){this.consoleCpuChart=echarts.init(document.getElementById("fs-info-cpu-chart"),null,{renderer:"svg"}),this.consoleMemoryChart=echarts.init(document.getElementById("fs-info-memory-chart"),null,{renderer:"svg"}),this.consoleLoadavgChart=echarts.init(document.getElementById("fs-info-loadavg-chart"),null,{renderer:"svg"}),this.consoleDiskusageChart=echarts.init(document.getElementById("fs-info-diskusage-chart"),null,{renderer:"svg"}),this.cpuOption=r.generateChatOption(this.mobile,this.language.cpu||"CPU","",this.language.today||"Today"),this.memoryOption=r.generateChatOption(this.mobile,this.language.memory||"Memory","",this.language.today||"Today"),this.diskUsageOption=r.generateChatOption(this.mobile,this.language.disk_usage||"Disk Usage","",this.language.today||"Today"),this.loadavgOption=r.generateChatOption(this.mobile,"Load Avg","loadavg",this.language.minutes||"min")}setCharts(e){this.consoleCpuChart.showLoading(),this.consoleMemoryChart.showLoading(),this.consoleLoadavgChart.showLoading(),this.consoleDiskusageChart.showLoading(),this.ajax.send({type:"POST",url:"/v0/state/hoststatus",data:{timeQuantum:e},success:e=>{if(200!==e.code)return;const t=["ts","cpu","memory","load_avg","disk_usage"],s=e.data;s.items=s.items.map((e=>{let s={};return t.forEach(((t,a)=>{if("ts"===t)return s[t]=1e3*e[a];s[t]=e[a]})),s}));let d=s.currentStatistic;if(Object.keys(d).length){let e=document.getElementById("fs-host-status").getElementsByClassName("fs-badge-style");e[0].innerHTML=d.memory+"%",e[1].innerHTML=d.cpu+"%",e[2].innerHTML=d.disk_usage+"%",e[3].innerHTML=d.load_avg[0]+","+d.load_avg[1]+","+d.load_avg[2],e[4].innerHTML=r.getFormatSeconds(d.boot_seconds||0,this.language.days,this.language.hours,this.language.minutes,this.language.seconds);["memory","cpu","disk_usage","load_avg"].forEach((function(t,s){let l="";if("load_avg"===t){let e=(d.load_avg[0]+d.load_avg[1]+d.load_avg[2])/3;l=e>=o?e>=n?"background-red":"background-orange":"background-green"}else l=d[t]>=i?d.memory>=a?"background-red":"background-orange":"background-green";let r=e[s].classList;r.remove("background-green","background-orange","background-red"),r.add(l)}));let t=document.getElementById("fs-redis-status").getElementsByClassName("fs-badge-style"),s=["used_memory","used_memory_rss","mem_fragmentation_ratio","hits_ratio","delta_hits_ratio","uptime_in_seconds","connected_clients"],c=!0;for(let e of s)if(d[e]){c=!1;break}c?(document.getElementById("fs-redis-status-title").innerHTML="",document.getElementById("fs-redis-status-title").style.marginTop="0",document.getElementById("fs-redis-status").style.display="none"):s.forEach(((e,s)=>{switch(e){case"used_memory":case"used_memory_rss":t[s].innerHTML=Math.ceil(d[e]/l)+" M";break;case"mem_fragmentation_ratio":let a=d[e];if(t[s].innerHTML=d[e],null!=a&&a>1){let e=t[s].classList;e.remove("background-green"),e.add("background-red")}break;case"hits_ratio":case"delta_hits_ratio":t[s].innerHTML=d[e]+"%";break;case"uptime_in_seconds":t[s].innerHTML=r.getFormatSeconds(d[e],this.language.days,this.language.hours,this.language.minutes,this.language.seconds);break;case"connected_clients":t[s].innerHTML=d[e]}}))}s.items.reverse();let c=r.getChartsData(s.items),g=c.ts_list,m=c.cpu_list,u=c.memory_list,f=c.load_avg_list[0],h=c.load_avg_list[1],y=c.load_avg_list[2],v=c.disk_usage_list;this.memoryOption.xAxis.data=g,this.cpuOption.xAxis.data=g,this.loadavgOption.xAxis.data=g,this.diskUsageOption.xAxis.data=g,this.memoryOption.series[0].data=u,this.cpuOption.series[0].data=m,this.diskUsageOption.series[0].data=v,this.loadavgOption.series[0].data=f,this.loadavgOption.series[1].data=h,this.loadavgOption.series[2].data=y,this.consoleMemoryChart.setOption(this.memoryOption),this.consoleCpuChart.setOption(this.cpuOption),this.consoleLoadavgChart.setOption(this.loadavgOption),this.consoleDiskusageChart.setOption(this.diskUsageOption),r.resizeChart([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])},complete:()=>{this.consoleMemoryChart.hideLoading(),this.consoleCpuChart.hideLoading(),this.consoleLoadavgChart.hideLoading(),this.consoleDiskusageChart.hideLoading()}}).then()}static isMobile(){let e=navigator.userAgent,t={trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:e.match(/AppleWebKit.*Mobile.*/)&&!0,ios:e.match(/\(i[^;]+;( U;)? CPU.Mac OS X/)&&!0,android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),wechat:e.indexOf("MicroMessenger")>-1,qq:e.match(/\sQQ/i)&&" qq"===e.match(/\sQQ/i)[0]};return t.iPhone||t.iPad||t.webApp||t.wechat||t.qq||t.ios||t.mobile||!1}static resizeChartTimer(e,t){clearTimeout(this.clearId),this.clearId=setTimeout((function(){r.resizeChart(e)}),t||200)}static resizeChart(e){e.forEach((e=>e.resize()))}static generateChatOption(e,t,s="",a=""){let i={color:"loadavg"===s?["#ffa726","#42a5f5","#66bb6a"]:["#42a5f5"],title:{show:!e,text:t},tooltip:{trigger:"axis",formatter:e=>{let t=echarts.format.formatTime("yyyy-MM-dd hh:mm:ss",new Date(parseInt(e[0].axisValue)),!1)+"
";for(let a=0;a";return t}},legend:{data:[a],textStyle:{fontSize:14}},grid:{left:"3%",right:"4%",bottom:"3%",top:e?30:60,containLabel:!0},toolbox:{show:!e,feature:{saveAsImage:{}}},xAxis:{type:"category",boundaryGap:!1,axisLabel:{formatter:function(e){return echarts.format.formatTime("hh:mm",new Date(parseInt(e)),!1)}}},yAxis:{type:"value"},series:[{name:a,type:"line",symbol:"none",hoverAnimation:!1}]};return"loadavg"===s&&(i.legend.data=["1 "+a,"5 "+a,"15 "+a],i.series=[],i.legend.data.forEach((e=>{i.series.push({name:e,type:"line",symbol:"none",hoverAnimation:!1})}))),i}static getChartsData(e){let t=[],s=[],a=[],i=[],n=[],o=[],l=[];for(let r=0;r=60?(o=n/60,o>=60&&(l=o/60,o%=60),l>=24&&(r=l/24,l%=24)):d=n+i,o>0&&(d=Math.floor(o)+" "+a),l>0&&(d=Math.floor(l)+" "+s),r>0&&(d=Math.floor(r)+" "+t),d}}class d{constructor(e){e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),this.xhr=e}send(e){let t=this.xhr,s={type:e.type||"get",url:e.url||"",async:e.async||!0,data:JSON.stringify(e.data),dataType:e.dataType||"json",contentType:"application/json",success:e.success||null,complete:e.complete||null};return new Promise(((e,a)=>{t.open(s.type,s.url,s.async),t.onreadystatechange=()=>{if(4===t.readyState)if("json"===s.dataType){const i=JSON.parse(t.responseText);e(i),null!==s.success?s.success(i):a(new Error(String(t.status)||"No callback function."))}else a(new Error(String(t.status)||"Error data type."))},t.onerror=()=>{a(new Error(String(t.status)||"Server is fail."))},t.setRequestHeader("Content-type",s.contentType),t.send(s.data),t.onloadend=()=>{null!=s.complete&&s.complete()}}))}}const c=function(){let e=null;return function(t){return e||(e=new r(t))}}();t.init=function(e){let t=null,s={};if(null!==e&&"object"==typeof e&&(t=e.hasOwnProperty("dom")?e.dom:null,s=e.hasOwnProperty("lang")&&e.lang.hasOwnProperty("language")?e.lang:{}),t instanceof HTMLElement){if(t.getAttribute("flaskState"))return;t.setAttribute("flaskState","true"),t.addEventListener("click",(()=>c(s).setFlaskStateData()))}else{if(document.getElementById("fs-state-circular"))return;let e="
",t=document.getElementsByTagName("body")[0];t.insertAdjacentHTML("beforeend",e);let a,i,n=document.getElementById("fs-state-circular");n.onclick=function(){this.classList.add("fs-circular-out"),c(s).setFlaskStateData()},n.onmousedown=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.onmousemove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.onmouseup=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.onmousemove=null,this.style.cursor="default",clearTimeout(a)},n.ontouchstart=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.ontouchmove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.ontouchend=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.ontouchmove=null,this.style.cursor="default",clearTimeout(a)}}}}]); \ No newline at end of file +module.exports=function(e){var t={};function s(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,a){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(s.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(a,i,function(t){return e[t]}.bind(null,i));return a},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";const a=85,i=75,n=10,o=5,l=1048576;class r{constructor(e){this.language=e,this.mobile=r.isMobile(),this.index=0,this.ajax=new d,this.initFlaskStateContainer(this.mobile),this.setEventListener(),this.initFlaskStateLanguage(this.language),this.setInitParams(),this.mobile&&this.setTagChangeEventListener(this.consoleCpuChart,this.consoleMemoryChart,this.consoleLoadavgChart,this.consoleDiskusageChart),window.addEventListener("resize",(()=>{r.resizeChartTimer([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])}))}setFlaskStateData(){document.getElementById("fs-background").style.display="block",document.getElementById("fs-info-container").style.display="block",document.getElementsByTagName("body")[0].style.overflowX="hidden",document.getElementsByTagName("body")[0].style.overflowY="hidden",document.getElementById("fs-select-days").value="1",this.setCharts("1")}initFlaskStateContainer(){let e='

days

Host Status

Memory
CPU
Disk Usage
Load Avg
Uptime

Redis Status

Used Mem
Used Mem Rss
Mem Fragmentation Ratio
Cache Hits Ratio
24h Hits Ratio
Uptime
Connections
';this.mobile?e+='
':e+="
",document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend",e)}setEventListener(){if(window.addEventListener){document.getElementById("fs-info-close").addEventListener("click",(function(){document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out")})),document.getElementById("fs-background").addEventListener("click",(function(e){"fs-background"===String(e.target.id)&&(document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out"))}));let e=document.getElementById("fs-select-days");e.addEventListener("change",(()=>{this.setCharts(e.value)}))}}setTagChangeEventListener(...e){if(document.getElementById("fs-info-tab")){let t=document.getElementById("fs-info-tab").getElementsByTagName("li"),s=document.getElementById("fs-info-tab-memory"),a=t[0],i=0;const n={0:"fs-info-tab-memory",1:"fs-info-tab-cpu",2:"fs-info-tab-disk-usage",3:"fs-info-tab-loadavg"};for(let o of t){let t=document.getElementById(n[i]);o.children[0].addEventListener("click",(()=>{o.classList.add("active"),a.classList.remove("active"),s.classList.remove("fs-show"),t.classList.add("fs-show"),r.resizeChart(e),s=t,a=o})),i++}}}initFlaskStateLanguage(){0!==Object.keys(this.language).length&&(document.getElementById("fs-host-status-title").innerHTML=this.language.host_status,document.getElementById("fs-redis-status-title").innerHTML=this.language.redis_status,document.getElementById("fs-cpu").innerHTML=this.language.cpu,document.getElementById("fs-memory").innerHTML=this.language.memory,document.getElementById("fs-disk-usage").innerHTML=this.language.disk_usage,document.getElementById("fs-load-avg").innerHTML=this.language.load_avg,document.getElementById("fs-boot-seconds").innerHTML=this.language.boot_seconds,document.getElementById("fs-used-memory").innerHTML=this.language.used_memory,document.getElementById("fs-used-memory-rss").innerHTML=this.language.used_memory_rss,document.getElementById("fs-mem-fragmentation-ratio").innerHTML=this.language.mem_fragmentation_ratio,document.getElementById("fs-hits-ratio").innerHTML=this.language.hits_ratio,document.getElementById("fs-delta-hits-ratio").innerHTML=this.language.delta_hits_ratio,document.getElementById("fs-uptime-in-seconds").innerHTML=this.language.uptime_in_seconds,document.getElementById("fs-connected-clients").innerHTML=this.language.connected_clients,document.getElementById("fs-days").innerHTML=this.language.days)}setInitParams(){this.consoleCpuChart=echarts.init(document.getElementById("fs-info-cpu-chart"),null,{renderer:"svg"}),this.consoleMemoryChart=echarts.init(document.getElementById("fs-info-memory-chart"),null,{renderer:"svg"}),this.consoleLoadavgChart=echarts.init(document.getElementById("fs-info-loadavg-chart"),null,{renderer:"svg"}),this.consoleDiskusageChart=echarts.init(document.getElementById("fs-info-diskusage-chart"),null,{renderer:"svg"}),this.cpuOption=r.generateChatOption(this.mobile,this.language.cpu||"CPU","",this.language.today||"Today"),this.memoryOption=r.generateChatOption(this.mobile,this.language.memory||"Memory","",this.language.today||"Today"),this.diskUsageOption=r.generateChatOption(this.mobile,this.language.disk_usage||"Disk Usage","",this.language.today||"Today"),this.loadavgOption=r.generateChatOption(this.mobile,"Load Avg","loadavg",this.language.minutes||"min")}setCharts(e){this.consoleCpuChart.showLoading(),this.consoleMemoryChart.showLoading(),this.consoleLoadavgChart.showLoading(),this.consoleDiskusageChart.showLoading(),this.ajax.send({type:"POST",url:"/v0/state/hoststatus",data:{timeQuantum:e},success:e=>{if(200!==e.code)return void window.alert(e.msg);const t=["ts","cpu","memory","load_avg","disk_usage"],s=e.data;s.items=s.items.map((e=>{let s={};return t.forEach(((t,a)=>{if("ts"===t)return s[t]=1e3*e[a];s[t]=e[a]})),s}));let d=s.currentStatistic;if(Object.keys(d).length){let e=document.getElementById("fs-host-status").getElementsByClassName("fs-badge-style");e[0].innerHTML=d.memory+"%",e[1].innerHTML=d.cpu+"%",e[2].innerHTML=d.disk_usage+"%",e[3].innerHTML=d.load_avg[0]+","+d.load_avg[1]+","+d.load_avg[2],e[4].innerHTML=r.getFormatSeconds(d.boot_seconds||0,this.language.days,this.language.hours,this.language.minutes,this.language.seconds);["memory","cpu","disk_usage","load_avg"].forEach((function(t,s){let l="";if("load_avg"===t){let e=(d.load_avg[0]+d.load_avg[1]+d.load_avg[2])/3;l=e>=o?e>=n?"background-red":"background-orange":"background-green"}else l=d[t]>=i?d.memory>=a?"background-red":"background-orange":"background-green";let r=e[s].classList;r.remove("background-green","background-orange","background-red"),r.add(l)}));let t=document.getElementById("fs-redis-status").getElementsByClassName("fs-badge-style"),s=["used_memory","used_memory_rss","mem_fragmentation_ratio","hits_ratio","delta_hits_ratio","uptime_in_seconds","connected_clients"],c=!0;for(let e of s)if(d[e]){c=!1;break}c?(document.getElementById("fs-redis-status-title").innerHTML="",document.getElementById("fs-redis-status-title").style.marginTop="0",document.getElementById("fs-redis-status").style.display="none"):s.forEach(((e,s)=>{switch(e){case"used_memory":case"used_memory_rss":t[s].innerHTML=Math.ceil(d[e]/l)+" M";break;case"mem_fragmentation_ratio":let a=d[e];if(t[s].innerHTML=d[e],null!=a&&a>1){let e=t[s].classList;e.remove("background-green"),e.add("background-red")}break;case"hits_ratio":case"delta_hits_ratio":t[s].innerHTML=d[e]+"%";break;case"uptime_in_seconds":t[s].innerHTML=r.getFormatSeconds(d[e],this.language.days,this.language.hours,this.language.minutes,this.language.seconds);break;case"connected_clients":t[s].innerHTML=d[e]}}))}s.items.reverse();let c=r.getChartsData(s.items),g=c.ts_list,m=c.cpu_list,u=c.memory_list,f=c.load_avg_list[0],h=c.load_avg_list[1],y=c.load_avg_list[2],v=c.disk_usage_list;this.memoryOption.xAxis.data=g,this.cpuOption.xAxis.data=g,this.loadavgOption.xAxis.data=g,this.diskUsageOption.xAxis.data=g,this.memoryOption.series[0].data=u,this.cpuOption.series[0].data=m,this.diskUsageOption.series[0].data=v,this.loadavgOption.series[0].data=f,this.loadavgOption.series[1].data=h,this.loadavgOption.series[2].data=y,this.consoleMemoryChart.setOption(this.memoryOption),this.consoleCpuChart.setOption(this.cpuOption),this.consoleLoadavgChart.setOption(this.loadavgOption),this.consoleDiskusageChart.setOption(this.diskUsageOption),r.resizeChart([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])},complete:()=>{this.consoleMemoryChart.hideLoading(),this.consoleCpuChart.hideLoading(),this.consoleLoadavgChart.hideLoading(),this.consoleDiskusageChart.hideLoading()}}).then()}static isMobile(){let e=navigator.userAgent,t={trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:e.match(/AppleWebKit.*Mobile.*/)&&!0,ios:e.match(/\(i[^;]+;( U;)? CPU.Mac OS X/)&&!0,android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),wechat:e.indexOf("MicroMessenger")>-1,qq:e.match(/\sQQ/i)&&" qq"===e.match(/\sQQ/i)[0]};return t.iPhone||t.iPad||t.webApp||t.wechat||t.qq||t.ios||t.mobile||!1}static resizeChartTimer(e,t){clearTimeout(this.clearId),this.clearId=setTimeout((function(){r.resizeChart(e)}),t||200)}static resizeChart(e){e.forEach((e=>e.resize()))}static generateChatOption(e,t,s="",a=""){let i={color:"loadavg"===s?["#ffa726","#42a5f5","#66bb6a"]:["#42a5f5"],title:{show:!e,text:t},tooltip:{trigger:"axis",formatter:e=>{let t=echarts.format.formatTime("yyyy-MM-dd hh:mm:ss",new Date(parseInt(e[0].axisValue)),!1)+"
";for(let a=0;a";return t}},legend:{data:[a],textStyle:{fontSize:14}},grid:{left:"3%",right:"4%",bottom:"3%",top:e?30:60,containLabel:!0},toolbox:{show:!e,feature:{saveAsImage:{}}},xAxis:{type:"category",boundaryGap:!1,axisLabel:{formatter:function(e){return echarts.format.formatTime("hh:mm",new Date(parseInt(e)),!1)}}},yAxis:{type:"value"},series:[{name:a,type:"line",symbol:"none",hoverAnimation:!1}]};return"loadavg"===s&&(i.legend.data=["1 "+a,"5 "+a,"15 "+a],i.series=[],i.legend.data.forEach((e=>{i.series.push({name:e,type:"line",symbol:"none",hoverAnimation:!1})}))),i}static getChartsData(e){let t=[],s=[],a=[],i=[],n=[],o=[],l=[];for(let r=0;r=60?(o=n/60,o>=60&&(l=o/60,o%=60),l>=24&&(r=l/24,l%=24)):d=n+i,o>0&&(d=Math.floor(o)+" "+a),l>0&&(d=Math.floor(l)+" "+s),r>0&&(d=Math.floor(r)+" "+t),d}}class d{constructor(e){e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),this.xhr=e}send(e){let t=this.xhr,s={type:e.type||"get",url:e.url||"",async:e.async||!0,data:JSON.stringify(e.data),dataType:e.dataType||"json",contentType:"application/json",success:e.success||null,complete:e.complete||null};return new Promise(((e,a)=>{t.open(s.type,s.url,s.async),t.onreadystatechange=()=>{if(4===t.readyState)if("json"===s.dataType){const i=JSON.parse(t.responseText);e(i),null!==s.success?s.success(i):a(new Error(String(t.status)||"No callback function."))}else a(new Error(String(t.status)||"Error data type."))},t.onerror=()=>{a(new Error(String(t.status)||"Server is fail."))},t.setRequestHeader("Content-type",s.contentType),t.send(s.data),t.onloadend=()=>{null!=s.complete&&s.complete()}}))}}const c=function(){let e=null;return function(t){return e||(e=new r(t))}}();t.init=function(e){let t=null,s={};if(null!==e&&"object"==typeof e&&(t=e.hasOwnProperty("dom")?e.dom:null,s=e.hasOwnProperty("lang")&&e.lang.hasOwnProperty("language")?e.lang:{}),t instanceof HTMLElement){if(t.getAttribute("flaskState"))return;t.setAttribute("flaskState","true"),t.addEventListener("click",(()=>c(s).setFlaskStateData()))}else{if(document.getElementById("fs-state-circular"))return;let e="
",t=document.getElementsByTagName("body")[0];t.insertAdjacentHTML("beforeend",e);let a,i,n=document.getElementById("fs-state-circular");n.onclick=function(){this.classList.add("fs-circular-out"),c(s).setFlaskStateData()},n.onmousedown=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.onmousemove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.onmouseup=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.onmousemove=null,this.style.cursor="default",clearTimeout(a)},n.ontouchstart=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.ontouchmove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.ontouchend=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.ontouchmove=null,this.style.cursor="default",clearTimeout(a)}}}}]); \ No newline at end of file diff --git a/packages/umd/flask-state.js b/packages/umd/flask-state.js index 0761a66..7d02dfb 100644 --- a/packages/umd/flask-state.js +++ b/packages/umd/flask-state.js @@ -265,6 +265,7 @@ data: {'timeQuantum': days}, success: response => { if (response.code !== 200) { + window.alert(response.msg); return; } diff --git a/packages/umd/flask-state.min.js b/packages/umd/flask-state.min.js index 6627f21..960139d 100644 --- a/packages/umd/flask-state.min.js +++ b/packages/umd/flask-state.min.js @@ -10,4 +10,4 @@ 'use strict'; -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.flaskState=t():e.flaskState=t()}(window,(function(){return function(e){var t={};function s(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,a){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(s.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(a,i,function(t){return e[t]}.bind(null,i));return a},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";const a=85,i=75,n=10,o=5,l=1048576;class r{constructor(e){this.language=e,this.mobile=r.isMobile(),this.index=0,this.ajax=new d,this.initFlaskStateContainer(this.mobile),this.setEventListener(),this.initFlaskStateLanguage(this.language),this.setInitParams(),this.mobile&&this.setTagChangeEventListener(this.consoleCpuChart,this.consoleMemoryChart,this.consoleLoadavgChart,this.consoleDiskusageChart),window.addEventListener("resize",(()=>{r.resizeChartTimer([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])}))}setFlaskStateData(){document.getElementById("fs-background").style.display="block",document.getElementById("fs-info-container").style.display="block",document.getElementsByTagName("body")[0].style.overflowX="hidden",document.getElementsByTagName("body")[0].style.overflowY="hidden",document.getElementById("fs-select-days").value="1",this.setCharts("1")}initFlaskStateContainer(){let e='

days

Host Status

Memory
CPU
Disk Usage
Load Avg
Uptime

Redis Status

Used Mem
Used Mem Rss
Mem Fragmentation Ratio
Cache Hits Ratio
24h Hits Ratio
Uptime
Connections
';this.mobile?e+='
':e+="
",document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend",e)}setEventListener(){if(window.addEventListener){document.getElementById("fs-info-close").addEventListener("click",(function(){document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out")})),document.getElementById("fs-background").addEventListener("click",(function(e){"fs-background"===String(e.target.id)&&(document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out"))}));let e=document.getElementById("fs-select-days");e.addEventListener("change",(()=>{this.setCharts(e.value)}))}}setTagChangeEventListener(...e){if(document.getElementById("fs-info-tab")){let t=document.getElementById("fs-info-tab").getElementsByTagName("li"),s=document.getElementById("fs-info-tab-memory"),a=t[0],i=0;const n={0:"fs-info-tab-memory",1:"fs-info-tab-cpu",2:"fs-info-tab-disk-usage",3:"fs-info-tab-loadavg"};for(let o of t){let t=document.getElementById(n[i]);o.children[0].addEventListener("click",(()=>{o.classList.add("active"),a.classList.remove("active"),s.classList.remove("fs-show"),t.classList.add("fs-show"),r.resizeChart(e),s=t,a=o})),i++}}}initFlaskStateLanguage(){0!==Object.keys(this.language).length&&(document.getElementById("fs-host-status-title").innerHTML=this.language.host_status,document.getElementById("fs-redis-status-title").innerHTML=this.language.redis_status,document.getElementById("fs-cpu").innerHTML=this.language.cpu,document.getElementById("fs-memory").innerHTML=this.language.memory,document.getElementById("fs-disk-usage").innerHTML=this.language.disk_usage,document.getElementById("fs-load-avg").innerHTML=this.language.load_avg,document.getElementById("fs-boot-seconds").innerHTML=this.language.boot_seconds,document.getElementById("fs-used-memory").innerHTML=this.language.used_memory,document.getElementById("fs-used-memory-rss").innerHTML=this.language.used_memory_rss,document.getElementById("fs-mem-fragmentation-ratio").innerHTML=this.language.mem_fragmentation_ratio,document.getElementById("fs-hits-ratio").innerHTML=this.language.hits_ratio,document.getElementById("fs-delta-hits-ratio").innerHTML=this.language.delta_hits_ratio,document.getElementById("fs-uptime-in-seconds").innerHTML=this.language.uptime_in_seconds,document.getElementById("fs-connected-clients").innerHTML=this.language.connected_clients,document.getElementById("fs-days").innerHTML=this.language.days)}setInitParams(){this.consoleCpuChart=echarts.init(document.getElementById("fs-info-cpu-chart"),null,{renderer:"svg"}),this.consoleMemoryChart=echarts.init(document.getElementById("fs-info-memory-chart"),null,{renderer:"svg"}),this.consoleLoadavgChart=echarts.init(document.getElementById("fs-info-loadavg-chart"),null,{renderer:"svg"}),this.consoleDiskusageChart=echarts.init(document.getElementById("fs-info-diskusage-chart"),null,{renderer:"svg"}),this.cpuOption=r.generateChatOption(this.mobile,this.language.cpu||"CPU","",this.language.today||"Today"),this.memoryOption=r.generateChatOption(this.mobile,this.language.memory||"Memory","",this.language.today||"Today"),this.diskUsageOption=r.generateChatOption(this.mobile,this.language.disk_usage||"Disk Usage","",this.language.today||"Today"),this.loadavgOption=r.generateChatOption(this.mobile,"Load Avg","loadavg",this.language.minutes||"min")}setCharts(e){this.consoleCpuChart.showLoading(),this.consoleMemoryChart.showLoading(),this.consoleLoadavgChart.showLoading(),this.consoleDiskusageChart.showLoading(),this.ajax.send({type:"POST",url:"/v0/state/hoststatus",data:{timeQuantum:e},success:e=>{if(200!==e.code)return;const t=["ts","cpu","memory","load_avg","disk_usage"],s=e.data;s.items=s.items.map((e=>{let s={};return t.forEach(((t,a)=>{if("ts"===t)return s[t]=1e3*e[a];s[t]=e[a]})),s}));let d=s.currentStatistic;if(Object.keys(d).length){let e=document.getElementById("fs-host-status").getElementsByClassName("fs-badge-style");e[0].innerHTML=d.memory+"%",e[1].innerHTML=d.cpu+"%",e[2].innerHTML=d.disk_usage+"%",e[3].innerHTML=d.load_avg[0]+","+d.load_avg[1]+","+d.load_avg[2],e[4].innerHTML=r.getFormatSeconds(d.boot_seconds||0,this.language.days,this.language.hours,this.language.minutes,this.language.seconds);["memory","cpu","disk_usage","load_avg"].forEach((function(t,s){let l="";if("load_avg"===t){let e=(d.load_avg[0]+d.load_avg[1]+d.load_avg[2])/3;l=e>=o?e>=n?"background-red":"background-orange":"background-green"}else l=d[t]>=i?d.memory>=a?"background-red":"background-orange":"background-green";let r=e[s].classList;r.remove("background-green","background-orange","background-red"),r.add(l)}));let t=document.getElementById("fs-redis-status").getElementsByClassName("fs-badge-style"),s=["used_memory","used_memory_rss","mem_fragmentation_ratio","hits_ratio","delta_hits_ratio","uptime_in_seconds","connected_clients"],c=!0;for(let e of s)if(d[e]){c=!1;break}c?(document.getElementById("fs-redis-status-title").innerHTML="",document.getElementById("fs-redis-status-title").style.marginTop="0",document.getElementById("fs-redis-status").style.display="none"):s.forEach(((e,s)=>{switch(e){case"used_memory":case"used_memory_rss":t[s].innerHTML=Math.ceil(d[e]/l)+" M";break;case"mem_fragmentation_ratio":let a=d[e];if(t[s].innerHTML=d[e],null!=a&&a>1){let e=t[s].classList;e.remove("background-green"),e.add("background-red")}break;case"hits_ratio":case"delta_hits_ratio":t[s].innerHTML=d[e]+"%";break;case"uptime_in_seconds":t[s].innerHTML=r.getFormatSeconds(d[e],this.language.days,this.language.hours,this.language.minutes,this.language.seconds);break;case"connected_clients":t[s].innerHTML=d[e]}}))}s.items.reverse();let c=r.getChartsData(s.items),g=c.ts_list,m=c.cpu_list,u=c.memory_list,f=c.load_avg_list[0],h=c.load_avg_list[1],y=c.load_avg_list[2],v=c.disk_usage_list;this.memoryOption.xAxis.data=g,this.cpuOption.xAxis.data=g,this.loadavgOption.xAxis.data=g,this.diskUsageOption.xAxis.data=g,this.memoryOption.series[0].data=u,this.cpuOption.series[0].data=m,this.diskUsageOption.series[0].data=v,this.loadavgOption.series[0].data=f,this.loadavgOption.series[1].data=h,this.loadavgOption.series[2].data=y,this.consoleMemoryChart.setOption(this.memoryOption),this.consoleCpuChart.setOption(this.cpuOption),this.consoleLoadavgChart.setOption(this.loadavgOption),this.consoleDiskusageChart.setOption(this.diskUsageOption),r.resizeChart([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])},complete:()=>{this.consoleMemoryChart.hideLoading(),this.consoleCpuChart.hideLoading(),this.consoleLoadavgChart.hideLoading(),this.consoleDiskusageChart.hideLoading()}}).then()}static isMobile(){let e=navigator.userAgent,t={trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:e.match(/AppleWebKit.*Mobile.*/)&&!0,ios:e.match(/\(i[^;]+;( U;)? CPU.Mac OS X/)&&!0,android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),wechat:e.indexOf("MicroMessenger")>-1,qq:e.match(/\sQQ/i)&&" qq"===e.match(/\sQQ/i)[0]};return t.iPhone||t.iPad||t.webApp||t.wechat||t.qq||t.ios||t.mobile||!1}static resizeChartTimer(e,t){clearTimeout(this.clearId),this.clearId=setTimeout((function(){r.resizeChart(e)}),t||200)}static resizeChart(e){e.forEach((e=>e.resize()))}static generateChatOption(e,t,s="",a=""){let i={color:"loadavg"===s?["#ffa726","#42a5f5","#66bb6a"]:["#42a5f5"],title:{show:!e,text:t},tooltip:{trigger:"axis",formatter:e=>{let t=echarts.format.formatTime("yyyy-MM-dd hh:mm:ss",new Date(parseInt(e[0].axisValue)),!1)+"
";for(let a=0;a";return t}},legend:{data:[a],textStyle:{fontSize:14}},grid:{left:"3%",right:"4%",bottom:"3%",top:e?30:60,containLabel:!0},toolbox:{show:!e,feature:{saveAsImage:{}}},xAxis:{type:"category",boundaryGap:!1,axisLabel:{formatter:function(e){return echarts.format.formatTime("hh:mm",new Date(parseInt(e)),!1)}}},yAxis:{type:"value"},series:[{name:a,type:"line",symbol:"none",hoverAnimation:!1}]};return"loadavg"===s&&(i.legend.data=["1 "+a,"5 "+a,"15 "+a],i.series=[],i.legend.data.forEach((e=>{i.series.push({name:e,type:"line",symbol:"none",hoverAnimation:!1})}))),i}static getChartsData(e){let t=[],s=[],a=[],i=[],n=[],o=[],l=[];for(let r=0;r=60?(o=n/60,o>=60&&(l=o/60,o%=60),l>=24&&(r=l/24,l%=24)):d=n+i,o>0&&(d=Math.floor(o)+" "+a),l>0&&(d=Math.floor(l)+" "+s),r>0&&(d=Math.floor(r)+" "+t),d}}class d{constructor(e){e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),this.xhr=e}send(e){let t=this.xhr,s={type:e.type||"get",url:e.url||"",async:e.async||!0,data:JSON.stringify(e.data),dataType:e.dataType||"json",contentType:"application/json",success:e.success||null,complete:e.complete||null};return new Promise(((e,a)=>{t.open(s.type,s.url,s.async),t.onreadystatechange=()=>{if(4===t.readyState)if("json"===s.dataType){const i=JSON.parse(t.responseText);e(i),null!==s.success?s.success(i):a(new Error(String(t.status)||"No callback function."))}else a(new Error(String(t.status)||"Error data type."))},t.onerror=()=>{a(new Error(String(t.status)||"Server is fail."))},t.setRequestHeader("Content-type",s.contentType),t.send(s.data),t.onloadend=()=>{null!=s.complete&&s.complete()}}))}}const c=function(){let e=null;return function(t){return e||(e=new r(t))}}();t.init=function(e){let t=null,s={};if(null!==e&&"object"==typeof e&&(t=e.hasOwnProperty("dom")?e.dom:null,s=e.hasOwnProperty("lang")&&e.lang.hasOwnProperty("language")?e.lang:{}),t instanceof HTMLElement){if(t.getAttribute("flaskState"))return;t.setAttribute("flaskState","true"),t.addEventListener("click",(()=>c(s).setFlaskStateData()))}else{if(document.getElementById("fs-state-circular"))return;let e="
",t=document.getElementsByTagName("body")[0];t.insertAdjacentHTML("beforeend",e);let a,i,n=document.getElementById("fs-state-circular");n.onclick=function(){this.classList.add("fs-circular-out"),c(s).setFlaskStateData()},n.onmousedown=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.onmousemove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.onmouseup=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.onmousemove=null,this.style.cursor="default",clearTimeout(a)},n.ontouchstart=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.ontouchmove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.ontouchend=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.ontouchmove=null,this.style.cursor="default",clearTimeout(a)}}}}])})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.flaskState=t():e.flaskState=t()}(window,(function(){return function(e){var t={};function s(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,a){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(s.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(a,i,function(t){return e[t]}.bind(null,i));return a},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=0)}([function(e,t,s){"use strict";const a=85,i=75,n=10,o=5,l=1048576;class r{constructor(e){this.language=e,this.mobile=r.isMobile(),this.index=0,this.ajax=new d,this.initFlaskStateContainer(this.mobile),this.setEventListener(),this.initFlaskStateLanguage(this.language),this.setInitParams(),this.mobile&&this.setTagChangeEventListener(this.consoleCpuChart,this.consoleMemoryChart,this.consoleLoadavgChart,this.consoleDiskusageChart),window.addEventListener("resize",(()=>{r.resizeChartTimer([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])}))}setFlaskStateData(){document.getElementById("fs-background").style.display="block",document.getElementById("fs-info-container").style.display="block",document.getElementsByTagName("body")[0].style.overflowX="hidden",document.getElementsByTagName("body")[0].style.overflowY="hidden",document.getElementById("fs-select-days").value="1",this.setCharts("1")}initFlaskStateContainer(){let e='

days

Host Status

Memory
CPU
Disk Usage
Load Avg
Uptime

Redis Status

Used Mem
Used Mem Rss
Mem Fragmentation Ratio
Cache Hits Ratio
24h Hits Ratio
Uptime
Connections
';this.mobile?e+='
':e+="
",document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend",e)}setEventListener(){if(window.addEventListener){document.getElementById("fs-info-close").addEventListener("click",(function(){document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out")})),document.getElementById("fs-background").addEventListener("click",(function(e){"fs-background"===String(e.target.id)&&(document.getElementById("fs-background").style.display="none",document.getElementById("fs-info-container").style.display="none",document.getElementsByTagName("body")[0].style.overflowX="auto",document.getElementsByTagName("body")[0].style.overflowY="auto",document.getElementById("fs-state-circular")&&document.getElementById("fs-state-circular").classList.remove("fs-circular-out"))}));let e=document.getElementById("fs-select-days");e.addEventListener("change",(()=>{this.setCharts(e.value)}))}}setTagChangeEventListener(...e){if(document.getElementById("fs-info-tab")){let t=document.getElementById("fs-info-tab").getElementsByTagName("li"),s=document.getElementById("fs-info-tab-memory"),a=t[0],i=0;const n={0:"fs-info-tab-memory",1:"fs-info-tab-cpu",2:"fs-info-tab-disk-usage",3:"fs-info-tab-loadavg"};for(let o of t){let t=document.getElementById(n[i]);o.children[0].addEventListener("click",(()=>{o.classList.add("active"),a.classList.remove("active"),s.classList.remove("fs-show"),t.classList.add("fs-show"),r.resizeChart(e),s=t,a=o})),i++}}}initFlaskStateLanguage(){0!==Object.keys(this.language).length&&(document.getElementById("fs-host-status-title").innerHTML=this.language.host_status,document.getElementById("fs-redis-status-title").innerHTML=this.language.redis_status,document.getElementById("fs-cpu").innerHTML=this.language.cpu,document.getElementById("fs-memory").innerHTML=this.language.memory,document.getElementById("fs-disk-usage").innerHTML=this.language.disk_usage,document.getElementById("fs-load-avg").innerHTML=this.language.load_avg,document.getElementById("fs-boot-seconds").innerHTML=this.language.boot_seconds,document.getElementById("fs-used-memory").innerHTML=this.language.used_memory,document.getElementById("fs-used-memory-rss").innerHTML=this.language.used_memory_rss,document.getElementById("fs-mem-fragmentation-ratio").innerHTML=this.language.mem_fragmentation_ratio,document.getElementById("fs-hits-ratio").innerHTML=this.language.hits_ratio,document.getElementById("fs-delta-hits-ratio").innerHTML=this.language.delta_hits_ratio,document.getElementById("fs-uptime-in-seconds").innerHTML=this.language.uptime_in_seconds,document.getElementById("fs-connected-clients").innerHTML=this.language.connected_clients,document.getElementById("fs-days").innerHTML=this.language.days)}setInitParams(){this.consoleCpuChart=echarts.init(document.getElementById("fs-info-cpu-chart"),null,{renderer:"svg"}),this.consoleMemoryChart=echarts.init(document.getElementById("fs-info-memory-chart"),null,{renderer:"svg"}),this.consoleLoadavgChart=echarts.init(document.getElementById("fs-info-loadavg-chart"),null,{renderer:"svg"}),this.consoleDiskusageChart=echarts.init(document.getElementById("fs-info-diskusage-chart"),null,{renderer:"svg"}),this.cpuOption=r.generateChatOption(this.mobile,this.language.cpu||"CPU","",this.language.today||"Today"),this.memoryOption=r.generateChatOption(this.mobile,this.language.memory||"Memory","",this.language.today||"Today"),this.diskUsageOption=r.generateChatOption(this.mobile,this.language.disk_usage||"Disk Usage","",this.language.today||"Today"),this.loadavgOption=r.generateChatOption(this.mobile,"Load Avg","loadavg",this.language.minutes||"min")}setCharts(e){this.consoleCpuChart.showLoading(),this.consoleMemoryChart.showLoading(),this.consoleLoadavgChart.showLoading(),this.consoleDiskusageChart.showLoading(),this.ajax.send({type:"POST",url:"/v0/state/hoststatus",data:{timeQuantum:e},success:e=>{if(200!==e.code)return void window.alert(e.msg);const t=["ts","cpu","memory","load_avg","disk_usage"],s=e.data;s.items=s.items.map((e=>{let s={};return t.forEach(((t,a)=>{if("ts"===t)return s[t]=1e3*e[a];s[t]=e[a]})),s}));let d=s.currentStatistic;if(Object.keys(d).length){let e=document.getElementById("fs-host-status").getElementsByClassName("fs-badge-style");e[0].innerHTML=d.memory+"%",e[1].innerHTML=d.cpu+"%",e[2].innerHTML=d.disk_usage+"%",e[3].innerHTML=d.load_avg[0]+","+d.load_avg[1]+","+d.load_avg[2],e[4].innerHTML=r.getFormatSeconds(d.boot_seconds||0,this.language.days,this.language.hours,this.language.minutes,this.language.seconds);["memory","cpu","disk_usage","load_avg"].forEach((function(t,s){let l="";if("load_avg"===t){let e=(d.load_avg[0]+d.load_avg[1]+d.load_avg[2])/3;l=e>=o?e>=n?"background-red":"background-orange":"background-green"}else l=d[t]>=i?d.memory>=a?"background-red":"background-orange":"background-green";let r=e[s].classList;r.remove("background-green","background-orange","background-red"),r.add(l)}));let t=document.getElementById("fs-redis-status").getElementsByClassName("fs-badge-style"),s=["used_memory","used_memory_rss","mem_fragmentation_ratio","hits_ratio","delta_hits_ratio","uptime_in_seconds","connected_clients"],c=!0;for(let e of s)if(d[e]){c=!1;break}c?(document.getElementById("fs-redis-status-title").innerHTML="",document.getElementById("fs-redis-status-title").style.marginTop="0",document.getElementById("fs-redis-status").style.display="none"):s.forEach(((e,s)=>{switch(e){case"used_memory":case"used_memory_rss":t[s].innerHTML=Math.ceil(d[e]/l)+" M";break;case"mem_fragmentation_ratio":let a=d[e];if(t[s].innerHTML=d[e],null!=a&&a>1){let e=t[s].classList;e.remove("background-green"),e.add("background-red")}break;case"hits_ratio":case"delta_hits_ratio":t[s].innerHTML=d[e]+"%";break;case"uptime_in_seconds":t[s].innerHTML=r.getFormatSeconds(d[e],this.language.days,this.language.hours,this.language.minutes,this.language.seconds);break;case"connected_clients":t[s].innerHTML=d[e]}}))}s.items.reverse();let c=r.getChartsData(s.items),g=c.ts_list,m=c.cpu_list,u=c.memory_list,f=c.load_avg_list[0],h=c.load_avg_list[1],y=c.load_avg_list[2],v=c.disk_usage_list;this.memoryOption.xAxis.data=g,this.cpuOption.xAxis.data=g,this.loadavgOption.xAxis.data=g,this.diskUsageOption.xAxis.data=g,this.memoryOption.series[0].data=u,this.cpuOption.series[0].data=m,this.diskUsageOption.series[0].data=v,this.loadavgOption.series[0].data=f,this.loadavgOption.series[1].data=h,this.loadavgOption.series[2].data=y,this.consoleMemoryChart.setOption(this.memoryOption),this.consoleCpuChart.setOption(this.cpuOption),this.consoleLoadavgChart.setOption(this.loadavgOption),this.consoleDiskusageChart.setOption(this.diskUsageOption),r.resizeChart([this.consoleMemoryChart,this.consoleCpuChart,this.consoleLoadavgChart,this.consoleDiskusageChart])},complete:()=>{this.consoleMemoryChart.hideLoading(),this.consoleCpuChart.hideLoading(),this.consoleLoadavgChart.hideLoading(),this.consoleDiskusageChart.hideLoading()}}).then()}static isMobile(){let e=navigator.userAgent,t={trident:e.indexOf("Trident")>-1,presto:e.indexOf("Presto")>-1,webKit:e.indexOf("AppleWebKit")>-1,gecko:e.indexOf("Gecko")>-1&&-1===e.indexOf("KHTML"),mobile:e.match(/AppleWebKit.*Mobile.*/)&&!0,ios:e.match(/\(i[^;]+;( U;)? CPU.Mac OS X/)&&!0,android:e.indexOf("Android")>-1||e.indexOf("Linux")>-1,iPhone:e.indexOf("iPhone")>-1,iPad:e.indexOf("iPad")>-1,webApp:-1===e.indexOf("Safari"),wechat:e.indexOf("MicroMessenger")>-1,qq:e.match(/\sQQ/i)&&" qq"===e.match(/\sQQ/i)[0]};return t.iPhone||t.iPad||t.webApp||t.wechat||t.qq||t.ios||t.mobile||!1}static resizeChartTimer(e,t){clearTimeout(this.clearId),this.clearId=setTimeout((function(){r.resizeChart(e)}),t||200)}static resizeChart(e){e.forEach((e=>e.resize()))}static generateChatOption(e,t,s="",a=""){let i={color:"loadavg"===s?["#ffa726","#42a5f5","#66bb6a"]:["#42a5f5"],title:{show:!e,text:t},tooltip:{trigger:"axis",formatter:e=>{let t=echarts.format.formatTime("yyyy-MM-dd hh:mm:ss",new Date(parseInt(e[0].axisValue)),!1)+"
";for(let a=0;a";return t}},legend:{data:[a],textStyle:{fontSize:14}},grid:{left:"3%",right:"4%",bottom:"3%",top:e?30:60,containLabel:!0},toolbox:{show:!e,feature:{saveAsImage:{}}},xAxis:{type:"category",boundaryGap:!1,axisLabel:{formatter:function(e){return echarts.format.formatTime("hh:mm",new Date(parseInt(e)),!1)}}},yAxis:{type:"value"},series:[{name:a,type:"line",symbol:"none",hoverAnimation:!1}]};return"loadavg"===s&&(i.legend.data=["1 "+a,"5 "+a,"15 "+a],i.series=[],i.legend.data.forEach((e=>{i.series.push({name:e,type:"line",symbol:"none",hoverAnimation:!1})}))),i}static getChartsData(e){let t=[],s=[],a=[],i=[],n=[],o=[],l=[];for(let r=0;r=60?(o=n/60,o>=60&&(l=o/60,o%=60),l>=24&&(r=l/24,l%=24)):d=n+i,o>0&&(d=Math.floor(o)+" "+a),l>0&&(d=Math.floor(l)+" "+s),r>0&&(d=Math.floor(r)+" "+t),d}}class d{constructor(e){e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),this.xhr=e}send(e){let t=this.xhr,s={type:e.type||"get",url:e.url||"",async:e.async||!0,data:JSON.stringify(e.data),dataType:e.dataType||"json",contentType:"application/json",success:e.success||null,complete:e.complete||null};return new Promise(((e,a)=>{t.open(s.type,s.url,s.async),t.onreadystatechange=()=>{if(4===t.readyState)if("json"===s.dataType){const i=JSON.parse(t.responseText);e(i),null!==s.success?s.success(i):a(new Error(String(t.status)||"No callback function."))}else a(new Error(String(t.status)||"Error data type."))},t.onerror=()=>{a(new Error(String(t.status)||"Server is fail."))},t.setRequestHeader("Content-type",s.contentType),t.send(s.data),t.onloadend=()=>{null!=s.complete&&s.complete()}}))}}const c=function(){let e=null;return function(t){return e||(e=new r(t))}}();t.init=function(e){let t=null,s={};if(null!==e&&"object"==typeof e&&(t=e.hasOwnProperty("dom")?e.dom:null,s=e.hasOwnProperty("lang")&&e.lang.hasOwnProperty("language")?e.lang:{}),t instanceof HTMLElement){if(t.getAttribute("flaskState"))return;t.setAttribute("flaskState","true"),t.addEventListener("click",(()=>c(s).setFlaskStateData()))}else{if(document.getElementById("fs-state-circular"))return;let e="
",t=document.getElementsByTagName("body")[0];t.insertAdjacentHTML("beforeend",e);let a,i,n=document.getElementById("fs-state-circular");n.onclick=function(){this.classList.add("fs-circular-out"),c(s).setFlaskStateData()},n.onmousedown=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.onmousemove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.onmouseup=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.onmousemove=null,this.style.cursor="default",clearTimeout(a)},n.ontouchstart=function(e){i=i||e.clientY,n.classList.remove("fs-circular-animation"),a=setTimeout((function(){n.style.cursor="move",t.style.cursor="move",t.ontouchmove=function(e){n.style.top=Math.max(e.clientY-i+300,20)+"px"}}),1500)},t.ontouchend=function(){n.style.cursor="pointer",n.classList.add("fs-circular-animation"),t.ontouchmove=null,this.style.cursor="default",clearTimeout(a)}}}}])})); \ No newline at end of file