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 | 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 | $scope.activeIdleSlaveFilter = function (slave) {
|
---|
88 | return (slave.IsAllowedToCalculate == true) && (slave.State == 'Idle');
|
---|
89 | };
|
---|
90 |
|
---|
91 | $scope.activeCalculatingSlavesReverseSort = false;
|
---|
92 | $scope.activeCalculatingSlavesOrderColumn = 'slave.Slave.Name';
|
---|
93 |
|
---|
94 | $scope.activeIdleSlavesReverseSort = false;
|
---|
95 | $scope.activeIdleSlavesOrderColumn = 'slave.Slave.Name';
|
---|
96 |
|
---|
97 | $scope.inactiveSlavesReverseSort = false;
|
---|
98 | $scope.inactiveSlavesOrderColumn = 'slave.Slave.Name';
|
---|
99 |
|
---|
100 |
|
---|
101 | var updateStatus = function () {
|
---|
102 | // update status data
|
---|
103 | dataService.getStatus({}, function (status) {
|
---|
104 | var oneDayInMs = 24 * 60 * 60 * 1000;
|
---|
105 | var today = new Date().getTime() - oneDayInMs;
|
---|
106 | // raw status data
|
---|
107 | $scope.status = status;
|
---|
108 | // tasks data
|
---|
109 | $scope.tasks.WaitingTasks = 0;
|
---|
110 | $scope.tasks.CalculatingTasks = 0;
|
---|
111 | for (var i = 0; i < status.TasksStatus.length; ++i) {
|
---|
112 | var task = status.TasksStatus[i];
|
---|
113 | $scope.tasks.WaitingTasks += task.WaitingTasks;
|
---|
114 | $scope.tasks.CalculatingTasks += task.CalculatingTasks;
|
---|
115 | }
|
---|
116 | // knobs
|
---|
117 | $scope.cpu.knobData = Math.round(status.CpuUtilizationStatus.ActiveCpuUtilization);
|
---|
118 | $scope.core.knobData = Math.round(status.CoreStatus.CalculatingCores / status.CoreStatus.ActiveCores * 100);
|
---|
119 | $scope.memory.knobData = Math.round(status.MemoryStatus.UsedMemory / status.MemoryStatus.ActiveMemory * 100);
|
---|
120 | // chart series
|
---|
121 | var cpuSeries = $scope.cpu.series[0].data.splice(0);
|
---|
122 | var coreSeries = [$scope.core.series[0].data, $scope.core.series[1].data];
|
---|
123 | var memorySeries = [$scope.memory.series[0].data, $scope.memory.series[1].data];
|
---|
124 | if ($scope.status.Timestamp < today) {
|
---|
125 | if (cpuSeries.length > 2) {
|
---|
126 | cpuSeries.splice(0, 1);
|
---|
127 | }
|
---|
128 | if (coreSeries[0].length > 2) {
|
---|
129 | coreSeries[0].splice(0, 1);
|
---|
130 | }
|
---|
131 | if (coreSeries[1].length > 2) {
|
---|
132 | coreSeries[1].splice(0, 1);
|
---|
133 | }
|
---|
134 | if (memorySeries[0].length > 2) {
|
---|
135 | memorySeries[0].splice(0, 1);
|
---|
136 | }
|
---|
137 | if (memorySeries[1].length > 2) {
|
---|
138 | memorySeries[1].splice(0, 1);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | cpuSeries.push([$scope.status.Timestamp, $scope.cpu.knobData]);
|
---|
142 |
|
---|
143 | // charts are currently filled with old total/used data
|
---|
144 | // start temporary
|
---|
145 | var usedCores = status.CoreStatus.TotalCores - status.CoreStatus.FreeCores;
|
---|
146 | var usedMemory = status.MemoryStatus.TotalMemory - status.MemoryStatus.FreeMemory;
|
---|
147 | // end temporary
|
---|
148 | coreSeries[0].push([$scope.status.Timestamp, status.CoreStatus.TotalCores]);
|
---|
149 | coreSeries[1].push([$scope.status.Timestamp, usedCores]);
|
---|
150 | memorySeries[0].push([$scope.status.Timestamp, status.MemoryStatus.TotalMemory]);
|
---|
151 | memorySeries[1].push([$scope.status.Timestamp, usedMemory]);
|
---|
152 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
153 | $scope.core.series = [
|
---|
154 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
155 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
156 | ];
|
---|
157 | $scope.memory.series = [
|
---|
158 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
159 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
160 | ];
|
---|
161 | });
|
---|
162 | };
|
---|
163 |
|
---|
164 | var init = function () {
|
---|
165 | // load the chart history of the last 24 hours
|
---|
166 | var nowDate = new Date();
|
---|
167 | var startDate = new Date();
|
---|
168 | startDate.setTime(nowDate.getTime() - (24 * 60 * 60 * 1000));
|
---|
169 | dataService.getStatusHistory({ start: ConvertDate(startDate), end: ConvertDate(nowDate) }, function (status) {
|
---|
170 | var noOfStatus = status.length;
|
---|
171 | var cpuSeries = [];
|
---|
172 | var coreSeries = [[],[]];
|
---|
173 | var memorySeries = [[],[]];
|
---|
174 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
175 | var curStatus = status[i];
|
---|
176 | var cpuData = Math.round(curStatus.CpuUtilizationStatus.ActiveCpuUtilization);
|
---|
177 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
178 | coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.ActiveCores]);
|
---|
179 | coreSeries[1].push([curStatus.Timestamp, curStatus.CoreStatus.CalculatingCores]);
|
---|
180 | memorySeries[0].push([curStatus.Timestamp, curStatus.MemoryStatus.ActiveMemory]);
|
---|
181 | memorySeries[1].push([curStatus.Timestamp, curStatus.MemoryStatus.UsedMemory]);
|
---|
182 | }
|
---|
183 | $scope.cpu.series = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
184 | $scope.core.series = [
|
---|
185 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
186 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
187 | ];
|
---|
188 | $scope.memory.series = [
|
---|
189 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
190 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
191 | ];
|
---|
192 | updateStatus();
|
---|
193 | });
|
---|
194 | };
|
---|
195 | init();
|
---|
196 | // set interval and stop updating when changing location
|
---|
197 | $scope.updateInterval = $interval(updateStatus, $scope.interval);
|
---|
198 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
199 | $interval.cancel($scope.updateInterval);
|
---|
200 | cancelInterval();
|
---|
201 | });
|
---|
202 | }]
|
---|
203 | );
|
---|
204 | })(); |
---|