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 = defaultPageUpdateInterval;
|
---|
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 | yaxis: {
|
---|
57 | min: 0
|
---|
58 | }
|
---|
59 | };
|
---|
60 |
|
---|
61 | $scope.cpu = {
|
---|
62 | series: [{ data: [], label: " CPU Utilization", color: "#f7921d" }],
|
---|
63 | knobData: 0
|
---|
64 | };
|
---|
65 |
|
---|
66 | $scope.core = {
|
---|
67 | series: [
|
---|
68 | { data: [], label: " Total Cores", color: "LightGreen" },
|
---|
69 | { data: [], label: " Used Cores", color: "LightPink" }
|
---|
70 | ],
|
---|
71 | knobData: 0
|
---|
72 | };
|
---|
73 |
|
---|
74 | $scope.memory = {
|
---|
75 | series: [
|
---|
76 | { data: [], label: " Total Memory", color: "LightGreen" },
|
---|
77 | { data: [], label: " Used Memory", color: "LightPink" }
|
---|
78 | ],
|
---|
79 | knobData: 0
|
---|
80 | };
|
---|
81 |
|
---|
82 | $scope.tasks = {
|
---|
83 | WaitingTasks: 0,
|
---|
84 | CalculatingTasks: 0
|
---|
85 | };
|
---|
86 |
|
---|
87 | var updateStatus = function () {
|
---|
88 | // update status data
|
---|
89 | dataService.getStatus({}, function (status) {
|
---|
90 | var oneDayInMs = 24 * 60 * 60 * 1000;
|
---|
91 | var today = new Date().getTime() - oneDayInMs;
|
---|
92 | // raw status data
|
---|
93 | $scope.status = status;
|
---|
94 | // tasks data
|
---|
95 | $scope.tasks.WaitingTasks = 0;
|
---|
96 | $scope.tasks.CalculatingTasks = 0;
|
---|
97 | for (var i = 0; i < status.TasksStatus.length; ++i) {
|
---|
98 | var task = status.TasksStatus[i];
|
---|
99 | $scope.tasks.WaitingTasks += task.WaitingTasks;
|
---|
100 | $scope.tasks.CalculatingTasks += task.CalculatingTasks;
|
---|
101 | }
|
---|
102 | // knobs
|
---|
103 | $scope.cpu.knobData = Math.round(status.CpuUtilizationStatus.ActiveCpuUtilization);
|
---|
104 | $scope.core.knobData = Math.round(status.CoreStatus.CalculatingCores / status.CoreStatus.ActiveCores * 100);
|
---|
105 | $scope.memory.knobData = Math.round(status.MemoryStatus.CalculatingMemory / status.MemoryStatus.ActiveMemory * 100);
|
---|
106 | // chart series
|
---|
107 | var cpuSeries = $scope.cpu.series[0].data.splice(0);
|
---|
108 | var coreSeries = [$scope.core.series[0].data, $scope.core.series[1].data];
|
---|
109 | var memorySeries = [$scope.memory.series[0].data, $scope.memory.series[1].data];
|
---|
110 | if ($scope.status.Timestamp < today) {
|
---|
111 | if (cpuSeries.length > 2) {
|
---|
112 | cpuSeries.splice(0, 1);
|
---|
113 | }
|
---|
114 | if (coreSeries[0].length > 2) {
|
---|
115 | coreSeries[0].splice(0, 1);
|
---|
116 | }
|
---|
117 | if (coreSeries[1].length > 2) {
|
---|
118 | coreSeries[1].splice(0, 1);
|
---|
119 | }
|
---|
120 | if (memorySeries[0].length > 2) {
|
---|
121 | memorySeries[0].splice(0, 1);
|
---|
122 | }
|
---|
123 | if (memorySeries[1].length > 2) {
|
---|
124 | memorySeries[1].splice(0, 1);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | cpuSeries.push([$scope.status.Timestamp, Math.round(status.CpuUtilizationStatus.TotalCpuUtilization)]);
|
---|
129 | coreSeries[0].push([$scope.status.Timestamp, status.CoreStatus.TotalCores]);
|
---|
130 | coreSeries[1].push([$scope.status.Timestamp, status.CoreStatus.UsedCores]);
|
---|
131 | memorySeries[0].push([$scope.status.Timestamp, Math.round(status.MemoryStatus.TotalMemory / 1024)]);
|
---|
132 | memorySeries[1].push([$scope.status.Timestamp, Math.round(status.MemoryStatus.UsedMemory / 1024)]);
|
---|
133 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
134 | $scope.core.series = [
|
---|
135 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
136 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
137 | ];
|
---|
138 | $scope.memory.series = [
|
---|
139 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
140 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
141 | ];
|
---|
142 | });
|
---|
143 | };
|
---|
144 |
|
---|
145 | var init = function () {
|
---|
146 | // load the chart history of the last 24 hours
|
---|
147 | var nowDate = new Date();
|
---|
148 | var startDate = new Date();
|
---|
149 | startDate.setTime(nowDate.getTime() - (24 * 60 * 60 * 1000));
|
---|
150 | dataService.getStatusHistory({ start: ConvertDate(startDate), end: ConvertDate(nowDate) }, function (status) {
|
---|
151 | var noOfStatus = status.length;
|
---|
152 | var cpuSeries = [];
|
---|
153 | var coreSeries = [[], []];
|
---|
154 | var memorySeries = [[], []];
|
---|
155 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
156 | var curStatus = status[i];
|
---|
157 | var cpuData = Math.round(curStatus.CpuUtilizationStatus.TotalCpuUtilization);
|
---|
158 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
159 | coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.TotalCores]);
|
---|
160 | coreSeries[1].push([curStatus.Timestamp, curStatus.CoreStatus.UsedCores]);
|
---|
161 | memorySeries[0].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.TotalMemory / 1024)]);
|
---|
162 | memorySeries[1].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.UsedMemory / 1024)]);
|
---|
163 | }
|
---|
164 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
165 | $scope.core.series = [
|
---|
166 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
167 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
168 | ];
|
---|
169 | $scope.memory.series = [
|
---|
170 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
171 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
172 | ];
|
---|
173 | updateStatus();
|
---|
174 | });
|
---|
175 | };
|
---|
176 | init();
|
---|
177 | // set interval and stop updating when changing location
|
---|
178 | $scope.updateInterval = $interval(updateStatus, $scope.interval);
|
---|
179 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
180 | $interval.cancel($scope.updateInterval);
|
---|
181 | cancelInterval();
|
---|
182 | });
|
---|
183 | }]
|
---|
184 | );
|
---|
185 | })(); |
---|