ServerInfo.cshtml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. 
  2. @{
  3. ViewBag.Title = "ServerHardwareMonitoringIndex";
  4. Layout = "~/Views/Shared/_MainLayoutPage.cshtml";
  5. }
  6. <div class="easyui-panel">
  7. <div class="layui-form-item">
  8. <div class="layui-inline">
  9. <label class="layui-form-label">时间段选择</label>
  10. <div class="layui-input-inline">
  11. <input type="text" id="YJLX" name="YJLX" lay-verify="YJLX" autocomplete="off" class="layui-input" style="height:38px;border-radius:4px" />
  12. </div>
  13. </div>
  14. <div class="layui-inline Custom" style="display:none;">
  15. <label class="layui-form-label">开始时间</label>
  16. <div class="layui-input-inline">
  17. <input type="datetime-local" id="KSSJ" name="KSSJ" lay-verify="KSSJ" autocomplete="off" class="layui-input" style="height:38px;border-radius:4px" />
  18. </div>
  19. </div>
  20. <div class="layui-inline Custom" style="display:none;">
  21. <label class="layui-form-label">结束时间</label>
  22. <div class="layui-input-inline">
  23. <input type="datetime-local" id="JSSJ" name="JSSJ" lay-verify="JSSJ" autocomplete="off" class="layui-input" style="height:38px;border-radius:4px" />
  24. </div>
  25. <button type="button" id="CX" class="layui-btn layui-btn-sm">查询</button>
  26. </div>
  27. </div>
  28. <div style="height: 500px; display: flex;">
  29. <div id="cpu" style="width:500px;" class="myChart"></div>
  30. <div id="nc" style="width:500px;" class="myChart"></div>
  31. <div id="zp" style="width:500px;" class="myChart"></div>
  32. </div>
  33. </div>
  34. <script src="~/Content/Scripts/Common.js"></script>
  35. <script src="~/Content/Scripts/plugins/hcharts/highcharts.js"></script>
  36. <script src="~/Content/Scripts/plugins/hcharts/highcharts-more.js"></script>
  37. <script src="~/Content/Scripts/plugins/hcharts/modules/solid-gauge.js"></script>
  38. <script>
  39. function startTime(time) {
  40. const nowTimeDate = new Date(time);
  41. return nowTimeDate.setHours(0, 0, 0, 0);
  42. }
  43. function endTime(time) {
  44. const nowTimeDate = new Date(time);
  45. return nowTimeDate.setHours(23, 59, 59, 999);
  46. }
  47. function getTodayStartTimeAndEndTime(time) {
  48. time = time ? time : new Date();
  49. return {
  50. startTime: new Date(time.setHours(0, 0, 0, 0)),
  51. endTime: new Date(time.setHours(23, 59, 59, 999)),
  52. };
  53. }
  54. function getCurrentWeekStartTimeAndEndTime(time) {
  55. const current = time ? time : new Date();
  56. // current是本周的第几天
  57. let nowDayOfWeek = current.getDay();
  58. if (nowDayOfWeek === 0) nowDayOfWeek = 7;
  59. const dayNum = 1 * 24 * 60 * 60 * 1000;
  60. // 获取本周星期一的时间,星期一作为一周的第一天
  61. const firstDate = new Date(current.valueOf() - (nowDayOfWeek - 1) * dayNum);
  62. // 获取本周星期天的时间,星期天作为一周的最后一天
  63. const lastDate = new Date(new Date(firstDate).valueOf() + 6 * dayNum);
  64. return {
  65. startTime: new Date(startTime(firstDate)),
  66. endTime: new Date(endTime(lastDate)),
  67. };
  68. }
  69. $(function () {
  70. let serverId = getQueryString("serverId");
  71. //修改图表时间差异
  72. Highcharts.setOptions({ global: { useUTC: false } });
  73. //项目
  74. $("#YJLX").combobox({
  75. data: [{
  76. "ID": 0,
  77. "名称": "当天",
  78. },
  79. {
  80. "ID": 3,
  81. "名称": "昨天",
  82. },
  83. {
  84. "ID": 4,
  85. "名称": "近三天",
  86. }, {
  87. "ID": 1,
  88. "名称": "本周",
  89. },
  90. {
  91. "ID": 2,
  92. "名称": "本月",
  93. },
  94. {
  95. "ID": -1,
  96. "名称": "自定义",
  97. }],
  98. valueField: 'ID',
  99. textField: '名称',
  100. limitToList: true,
  101. value: 0,
  102. onChange: function (value, index) {
  103. if (value == -1) {
  104. //自定义时间
  105. $(".Custom").css("display", "");
  106. } else {
  107. //定时
  108. $(".Custom").css("display", "none");
  109. GetChartData(serverId);
  110. }
  111. }
  112. })
  113. /**查询 */
  114. $("#CX").click(function () {
  115. let sTime = $("#KSSJ").val();
  116. if (sTime === "") {
  117. ZLPMS.Msg("请输入开始时间!");
  118. return;
  119. }
  120. let eTime = $("#JSSJ").val();
  121. if (eTime === "") {
  122. ZLPMS.Msg("请输入结束时间!");
  123. return;
  124. }
  125. if (sTime > eTime) {
  126. ZLPMS.Msg("结束时间不能小于开始时间!");
  127. return;
  128. }
  129. GetChartData(serverId);
  130. })
  131. /**
  132. * 获取服务器数据
  133. */
  134. function GetChartData(serverId) {
  135. let type = $("#YJLX").val();
  136. let sTime = "";
  137. let eTime = "";
  138. switch (type) {
  139. case "0": {
  140. //本日
  141. sTime = new Date().format("yyyy-MM-ddT00:00:00");
  142. eTime = new Date().format("yyyy-MM-ddT23:59:59");
  143. break;
  144. }
  145. case "1": {
  146. //本周
  147. sTime = getCurrentWeekStartTimeAndEndTime().startTime.format("yyyy-MM-ddThh:mm:ss");
  148. eTime = getCurrentWeekStartTimeAndEndTime().endTime.format("yyyy-MM-ddThh:mm:ss");
  149. break;
  150. }
  151. case "2": {
  152. //本月
  153. sTime = new Date().format("yyyy-MM-01T00:00:00");
  154. eTime = new Date().format("yyyy-MM-ddThh:mm:ss");
  155. break;
  156. }
  157. case "3": {
  158. //昨天
  159. var day1 = new Date();
  160. day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000);
  161. sTime = new Date(day1).format("yyyy-MM-ddT00:00:00");
  162. eTime = new Date(day1).format("yyyy-MM-ddT23:59:59");
  163. break;
  164. }
  165. case "4": {
  166. //近三天
  167. var day1 = new Date();
  168. day1.setTime(day1.getTime() - 24 * 60 * 60 * 1000*3);
  169. sTime = new Date(day1).format("yyyy-MM-ddT00:00:00");
  170. eTime = new Date().format("yyyy-MM-ddThh:mm:ss");
  171. break;
  172. }
  173. case "-1": {
  174. //自定义
  175. sTime = $("#KSSJ").val();
  176. eTime = $("#JSSJ").val();
  177. break;
  178. }
  179. }
  180. let data = ZLPMS.GetAPi(`/CloudMonitor/GetServerDetailByServerId?serverId=${serverId}&startTime=${sTime}&endTime=${eTime}`);
  181. let cpudata = [];
  182. let ncdata = [];
  183. let zpdata = [];
  184. data = data.sort((a, b) => {
  185. return b["时间戳创建时间"] - a["时间戳创建时间"];
  186. })
  187. for (var i = 0; i < data.length; i++) {
  188. let d = data[i];
  189. cpudata.push([d["时间戳创建时间"], d["CPU使用率"]]);
  190. ncdata.push([d["时间戳创建时间"], d["内存使用率"]]);
  191. zpdata.push([d["时间戳创建时间"], d["磁盘使用率"]]);
  192. }
  193. let alertConfiguration = ZLPMS.GetAPi(`/CloudMonitor/GetAlertConfiguration`);
  194. InitChart("cpu", "cpu资源", "CPU使用率", "CPU占用", cpudata, alertConfiguration.CPU使用濒危, alertConfiguration.CPU使用高危);
  195. InitChart("nc", "内存资源", "内存使用率", "内存占用", ncdata, alertConfiguration.内存使用濒危, alertConfiguration.内存使用高危);
  196. InitChart("zp", "磁盘资源", "磁盘使用率", "磁盘占用", zpdata, alertConfiguration.磁盘使用濒危, alertConfiguration.磁盘使用高危);
  197. }
  198. function InitChart(id, tltle, yName, showName, data, min, max) {
  199. let chart = Highcharts.chart(id, {
  200. chart: {
  201. zoomType: 'x'
  202. },
  203. title: {
  204. text: tltle
  205. },
  206. subtitle: {
  207. text: ""//副标题
  208. },
  209. credits: {
  210. enabled: false
  211. },
  212. xAxis: {
  213. type: 'datetime',
  214. dateTimeLabelFormats: {
  215. millisecond: '%H:%M:%S.%L',
  216. second: '%H:%M:%S',
  217. minute: '%H:%M',
  218. hour: '%H:%M',
  219. day: '%m-%d',
  220. week: '%m-%d',
  221. month: '%Y-%m',
  222. year: '%Y'
  223. }
  224. },
  225. tooltip: {
  226. formatter: function () {
  227. return Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br>' + `${showName}:${this.y}`;
  228. },
  229. dateTimeLabelFormats: {
  230. millisecond: '%H:%M:%S.%L',
  231. second: '%H:%M:%S',
  232. minute: '%H:%M',
  233. hour: '%H:%M',
  234. day: '%Y-%m-%d',
  235. week: '%m-%d',
  236. month: '%Y-%m',
  237. year: '%Y'
  238. }
  239. },
  240. yAxis: {
  241. min: 0,
  242. max: 100,
  243. title: {
  244. text: yName
  245. },
  246. plotBands: [{
  247. from: 0,
  248. to: min,
  249. color: {
  250. linearGradient: {
  251. x1: 0,
  252. y1: 0,
  253. x2: 0,
  254. y2: 1
  255. },
  256. stops: [
  257. [0, "#ffffff"],
  258. [1, "#ffffff"]
  259. ]
  260. }
  261. }, {
  262. from: min,
  263. to: max,
  264. color: {
  265. linearGradient: {
  266. x1: 0,
  267. y1: 0,
  268. x2: 0,
  269. y2: 1
  270. },
  271. stops: [
  272. [0, "#ffffc2"],
  273. [1, "#ffffff"]
  274. ]
  275. }
  276. }, {
  277. from: max,
  278. to: 100,
  279. color: {
  280. linearGradient: {
  281. x1: 0,
  282. y1: 0,
  283. x2: 0,
  284. y2: 1
  285. },
  286. stops: [
  287. [0, "#ffc2c2"],
  288. [1, "#ffffc2"]
  289. ]
  290. }
  291. }]
  292. },
  293. legend: {
  294. enabled: false
  295. },
  296. plotOptions: {
  297. area: {
  298. fillColor: 'transparent', // 或者设置为 null
  299. marker: {
  300. radius: 1
  301. },
  302. lineWidth: 1,
  303. lineColor: '#63b563', // 将线条颜色设置为黑色
  304. states: {
  305. hover: {
  306. lineWidth: 1
  307. }
  308. }
  309. }
  310. },
  311. series: [{
  312. type: 'area',
  313. name: showName,
  314. data: data
  315. }]
  316. });
  317. }
  318. GetChartData(serverId);
  319. setInterval(function () {
  320. GetChartData(serverId);
  321. }, 60 * 1000);
  322. })
  323. </script>