CLIENT GUI Framework
[vnfsdk/refrepo.git] / portal-resmgr / src / main / webapp / resmgr-nfv / js / vim.js
1 /* Copyright 2016-2017, Huawei Technologies Co., Ltd.\r
2  *\r
3  * Licensed under the Apache License, Version 2.0 (the "License");\r
4  * you may not use this file except in compliance with the License.\r
5  * You may obtain a copy of the License at\r
6  *\r
7  *    http://www.apache.org/licenses/LICENSE-2.0\r
8  *\r
9  * Unless required by applicable law or agreed to in writing, software\r
10  * distributed under the License is distributed on an "AS IS" BASIS,\r
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12  * See the License for the specific language governing permissions and\r
13  * limitations under the License.\r
14  */\r
15 function loadVimData() {\r
16     var requestUrl = app_url+"/v1/resmanage/vim/vimInfo";\r
17     $.ajax({\r
18         type: "GET",\r
19         url: requestUrl,\r
20         contentType: "application/json",\r
21         success: function (jsonobj) {\r
22             printCharts(jsonobj.data[0].used.cpu,\r
23                 jsonobj.data[0].total.cpu, jsonobj.data[0].used.memory, jsonobj.data[0].total.memory, jsonobj.data[0].used.disk, jsonobj.data[0].total.disk);\r
24 \r
25         },\r
26         error: function (xhr, ajaxOptions, thrownError) {\r
27             bootbox.alert("Error on getting data (here display the test data) : " + xhr.responseText);\r
28             printCharts(11, 12, 21, 22, 31, 32);\r
29         }\r
30     });\r
31 }\r
32 function printCharts(v11, v12, v21, v22, v31, v32) {\r
33     var cpuChart = new Chart($("#cpuChart"), {\r
34         type: 'doughnut',\r
35         data: {\r
36             labels: ["used", "available"],\r
37             datasets: [{\r
38                 data: [v11, v12],\r
39                 backgroundColor: ["#FFCE56", "#36A2EB"],\r
40                 hoverBackgroundColor: ["#FFCE56", "#36A2EB"]\r
41             }]\r
42         },\r
43         options: {\r
44             animation: {\r
45                 animateScale: true,\r
46                 animateRotate: true\r
47 \r
48             }\r
49         }\r
50     });\r
51     var memoryChart = new Chart($("#memoryChart"), {\r
52         type: 'doughnut',\r
53         data: {\r
54             labels: ["used", "available"],\r
55             datasets: [{\r
56                 data: [v21, v22],\r
57                 backgroundColor: ["#FF6384", "#36A2EB"],\r
58                 hoverBackgroundColor: ["#FF6384", "#36A2EB"]\r
59             }]\r
60         },\r
61         options: {\r
62 \r
63             animation: {\r
64                 animateScale: true,\r
65                 animateRotate: true\r
66 \r
67             }\r
68         }\r
69     });\r
70     var diskChart = new Chart($("#diskChart"), {\r
71         type: 'doughnut',\r
72         data: {\r
73             labels: ["used", "available"],\r
74             datasets: [{\r
75                 data: [v31, v32],\r
76                 backgroundColor: ["#FF6384", "green"],\r
77                 hoverBackgroundColor: ["#FF6384", "green"]\r
78             }]\r
79         },\r
80         options: {\r
81             animation: {\r
82                 animateScale: true,\r
83                 animateRotate: true\r
84 \r
85             }\r
86         }\r
87     });\r
88 }\r
89 \r
90 $(function () {\r
91     loadVimData();\r
92 \r
93 })