| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="jq/jquery-3.5.1.min.js"></script>
- <script src="code/highcharts.js"></script>
- <script src="code/modules/exporting.js"></script>
- <script src="code/plugins/highcharts-zh_CN.js"></script>
- <style>
- #content div {
- float: left;
- }
- </style>
- <script>
- var apiUrl = "http://iaun.cn:18088/api"
- var id = ""
- var cpuLast = 0, memLast = 0;
- window.onload = function () {
- var search = window.location.search.substr(1).split("&")
- for (var i = 0, j = search.length; i < j; i++) {
- var temp = search[i].split('=');
- if (temp.length === 2 && temp[0] === "id") {
- id = temp[1];
- }
- }
- getData();
- loopGetData(5000, id);
- }
- function getData() {
- $.ajax({
- type: 'GET',
- url: apiUrl + '/cpu/get' + `?id=${id}&time=${cpuLast}&limit=50`,
- success: function (data) {
- cpuLast = (data.last !== 0) ? data.last : cpuLast;
- for (var i = 0, j = data["data"].length; i < j; i++) {
- var d = data["data"][i];
- var x = d["time"] * 1000, y = d["percent"];
- cpuChart.series[0].addPoint([x, y], true, true, true);
- }
- }
- });
- $.ajax({
- type: 'GET',
- url: apiUrl + '/memory/get' + `?id=${id}&time=${memLast}&limit=50`,
- success: function (data) {
- console.log(data);
- memLast = (data.last !== 0) ? data.last : memLast;
- for (var i = 0, j = data["data"].length; i < j; i++) {
- var d = data["data"][i];
- var x = d["time"] * 1000, y = d["used_percent"];
- memChart.series[0].addPoint([x, y], true, true, true);
- }
- }
- });
- }
- function loopGetData(time, id) {
- setInterval(function () {
- getData();
- }, time);
- }
- </script>
- </head>
- <body>
- <div id="content">
- <div id="container" style="width: 400px; height:200px;"></div>
- <div id="container_mem" style="width: 400px; height:200px;"></div>
- <!--<div style="width: 400px; height:200px;background: gray;"></div>
- <div style="width: 400px; height:200px;background: gray;"></div>
- <div style="width: 400px; height:200px;background: gray;"></div>
- <div style="width: 400px; height:200px;background: gray;"></div>
- <div style="width: 400px; height:200px;background: gray;"></div>-->
- </div>
- <script>
- function getConfig(name, count) {
- return {
- chart: {
- // type: 'spline',
- marginRight: 10
- },
- exporting: {
- buttons: {
- contextButton: {
- menuItems: null,
- onclick: function () {
- this.fullscreen.toggle();
- }
- }
- }
- },
- title: {
- text: name
- },
- xAxis: {
- type: 'datetime',
- tickPixelInterval: 150
- },
- credits: {
- enabled: false
- },
- yAxis: {
- title: {
- text: null
- }
- },
- tooltip: {
- formatter: function () {
- return '<b>' + this.series.name + '</b><br/>' +
- Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
- Highcharts.numberFormat(this.y, 2);
- }
- },
- legend: {
- enabled: false
- },
- plotOptions: {
- series: {
- marker: {
- enabled: false
- }
- }
- },
- series: [{
- name: name,
- data: (function () {
- var data = [], i;
- for (i = count * -1; i <= 0; i += 1) {
- data.push({
- x: null,
- y: null
- });
- }
- return data;
- }())
- }]
- };
- }
- /* events
- load: function () {
- var series = this.series[0];
- setInterval(function () {
- time += 1000;
- var x = new Date(time).getTime(), // 当前时间
- y = Math.random() * 100; // 随机值
- series.addPoint([x, y], true, true, true);
- }, 800);
- }
- */
- Highcharts.setOptions({
- global: {
- useUTC: false
- }
- });
- function activeLastPointToolip(chart) {
- var points = chart.series[0].points;
- chart.tooltip.refresh(points[points.length - 1]);
- }
- var time = (new Date()).getTime();
- var cpuChart = Highcharts.chart('container', getConfig('CPU', 20));
- var memChart = Highcharts.chart('container_mem', getConfig('Memory', 20));
- </script>
- </body>
- </html>
|