1 | (function () {
|
---|
2 | var module = appStatusPlugin.getAngularModule();
|
---|
3 | module.controller('app.status.ctrl',
|
---|
4 | ['$scope', '$interval', 'app.status.data.service',
|
---|
5 | function ($scope, $interval, dataService) {
|
---|
6 | $scope.interval = 10000; // update interval in ms
|
---|
7 | $scope.knobOptions = {
|
---|
8 | 'fgColor': "#f7921d",
|
---|
9 | 'angleOffset': -125,
|
---|
10 | 'angleArc': 250,
|
---|
11 | 'readOnly': true,
|
---|
12 | 'width': "80%",
|
---|
13 | 'targetvalue': "100",
|
---|
14 | 'format': function (value) {
|
---|
15 | return value;
|
---|
16 | },
|
---|
17 | draw: function () {
|
---|
18 | $(this.i).val(this.cv + '%');
|
---|
19 | }
|
---|
20 | };
|
---|
21 |
|
---|
22 | $scope.chartOptions = {
|
---|
23 | grid: {
|
---|
24 | borderWidth: 1,
|
---|
25 | labelMargin: 15
|
---|
26 | },
|
---|
27 | series: {
|
---|
28 | shadowSize: 0
|
---|
29 | },
|
---|
30 | yaxis: {
|
---|
31 | min: 0,
|
---|
32 | max: 100
|
---|
33 | },
|
---|
34 | xaxis: {
|
---|
35 | mode: "time",
|
---|
36 | twelveHourClock: false
|
---|
37 | }
|
---|
38 | };
|
---|
39 |
|
---|
40 | $scope.fillChartOptions = {
|
---|
41 | grid: {
|
---|
42 | borderWidth: 1,
|
---|
43 | labelMargin: 15
|
---|
44 | },
|
---|
45 | series: {
|
---|
46 | shadowSize: 0,
|
---|
47 | lines: {
|
---|
48 | show: true,
|
---|
49 | fill: true
|
---|
50 | }
|
---|
51 | },
|
---|
52 | xaxis: {
|
---|
53 | mode: "time",
|
---|
54 | twelveHourClock: false
|
---|
55 | }
|
---|
56 | };
|
---|
57 |
|
---|
58 | $scope.cpu = {
|
---|
59 | series: [{ data: [], label: " CPU Utilization", color: "#f7921d" }],
|
---|
60 | knobData: 0
|
---|
61 | };
|
---|
62 |
|
---|
63 | $scope.core = {
|
---|
64 | series: [
|
---|
65 | { data: [], label: " Total Cores", color: "LightGreen" },
|
---|
66 | { data: [], label: " Used Cores", color: "LightPink" }
|
---|
67 | ],
|
---|
68 | knobData: 0
|
---|
69 | };
|
---|
70 |
|
---|
71 | $scope.memory = {
|
---|
72 | series: [
|
---|
73 | { data: [], label: " Total Memory", color: "LightGreen" },
|
---|
74 | { data: [], label: " Used Memory", color: "LightPink" }
|
---|
75 | ],
|
---|
76 | knobData: 0
|
---|
77 | };
|
---|
78 |
|
---|
79 | $scope.tasks = {
|
---|
80 | WaitingTasks: 0,
|
---|
81 | CalculatingTasks: 0
|
---|
82 | };
|
---|
83 |
|
---|
84 | var updateStatus = function () {
|
---|
85 | // update status data
|
---|
86 | dataService.getStatus({}, function (status) {
|
---|
87 | // raw status data
|
---|
88 | $scope.status = status;
|
---|
89 | // tasks data
|
---|
90 | $scope.tasks.WaitingTasks = 0;
|
---|
91 | $scope.tasks.CalculatingTasks = 0;
|
---|
92 | for (var i = 0; i < status.TasksStatus.length; ++i) {
|
---|
93 | var task = status.TasksStatus[i];
|
---|
94 | $scope.tasks.WaitingTasks += task.WaitingTasks;
|
---|
95 | $scope.tasks.CalculatingTasks += task.CalculatingTasks;
|
---|
96 | }
|
---|
97 | // knobs
|
---|
98 | $scope.cpu.knobData = Math.round(status.CpuUtilizationStatus.UsedCpuUtilization);
|
---|
99 | var usedCores = status.CoreStatus.TotalCores - status.CoreStatus.FreeCores;
|
---|
100 | $scope.core.knobData = Math.round(usedCores / status.CoreStatus.TotalCores * 100);
|
---|
101 | var usedMemory = status.MemoryStatus.TotalMemory - status.MemoryStatus.FreeMemory;
|
---|
102 | $scope.memory.knobData = Math.round(usedMemory / status.MemoryStatus.TotalMemory * 100);
|
---|
103 | // chart series
|
---|
104 | var cpuSeries = $scope.cpu.series[0].data.splice(0);
|
---|
105 | if (cpuSeries.length > 2) {
|
---|
106 | cpuSeries.splice(0, 1);
|
---|
107 | }
|
---|
108 | var coreSeries = [$scope.core.series[0].data, $scope.core.series[1].data];
|
---|
109 | if (coreSeries[0].length > 2) {
|
---|
110 | coreSeries[0].splice(0, 1);
|
---|
111 | }
|
---|
112 | if (coreSeries[1].length > 2) {
|
---|
113 | coreSeries[1].splice(0, 1);
|
---|
114 | }
|
---|
115 | var memorySeries = [$scope.memory.series[0].data, $scope.memory.series[1].data];
|
---|
116 | if (memorySeries[0].length > 2) {
|
---|
117 | memorySeries[0].splice(0, 1);
|
---|
118 | }
|
---|
119 | if (memorySeries[1].length > 2) {
|
---|
120 | memorySeries[1].splice(0, 1);
|
---|
121 | }
|
---|
122 | cpuSeries.push([$scope.status.Timestamp, $scope.cpu.knobData]);
|
---|
123 | coreSeries[0].push([$scope.status.Timestamp, status.CoreStatus.TotalCores]);
|
---|
124 | coreSeries[1].push([$scope.status.Timestamp, usedCores]);
|
---|
125 | memorySeries[0].push([$scope.status.Timestamp, status.MemoryStatus.TotalMemory]);
|
---|
126 | memorySeries[1].push([$scope.status.Timestamp, usedMemory]);
|
---|
127 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
128 | $scope.core.series = [
|
---|
129 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
130 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
131 | ];
|
---|
132 | $scope.memory.series = [
|
---|
133 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
134 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
135 | ];
|
---|
136 | });
|
---|
137 | };
|
---|
138 |
|
---|
139 | var init = function () {
|
---|
140 | // load the chart history of the last 24 hours
|
---|
141 | var nowDate = new Date();
|
---|
142 | var startDate = new Date();
|
---|
143 | startDate.setTime(nowDate.getTime() - (24 * 60 * 60 * 1000));
|
---|
144 | dataService.getStatusHistory({ start: ConvertDate(startDate), end: ConvertDate(nowDate) }, function (status) {
|
---|
145 | var noOfStatus = status.length;
|
---|
146 | var cpuSeries = [];
|
---|
147 | var coreSeries = [[],[]];
|
---|
148 | var memorySeries = [[],[]];
|
---|
149 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
150 | var curStatus = status[i];
|
---|
151 | var cpuData = Math.round(curStatus.CpuUtilizationStatus.UsedCpuUtilization);
|
---|
152 | var usedCores = curStatus.CoreStatus.TotalCores - curStatus.CoreStatus.FreeCores;
|
---|
153 | var usedMemory = curStatus.MemoryStatus.TotalMemory - curStatus.MemoryStatus.FreeMemory;
|
---|
154 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
155 | coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.TotalCores]);
|
---|
156 | coreSeries[1].push([curStatus.Timestamp, usedCores]);
|
---|
157 | memorySeries[0].push([curStatus.Timestamp, curStatus.MemoryStatus.TotalMemory]);
|
---|
158 | memorySeries[1].push([curStatus.Timestamp, usedMemory]);
|
---|
159 | }
|
---|
160 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
161 | $scope.core.series = [
|
---|
162 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
163 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
164 | ];
|
---|
165 | $scope.memory.series = [
|
---|
166 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
167 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
168 | ];
|
---|
169 | updateStatus();
|
---|
170 | });
|
---|
171 | };
|
---|
172 | init();
|
---|
173 | // set interval and stop updating when changing location
|
---|
174 | $scope.updateInterval = $interval(updateStatus, $scope.interval);
|
---|
175 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
176 | $interval.cancel($scope.updateInterval);
|
---|
177 | cancelInterval();
|
---|
178 | });
|
---|
179 | }]
|
---|
180 | );
|
---|
181 | })(); |
---|