Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Services.WebApp.Status/3.3/WebApp/status/statusCtrl.js @ 12563

Last change on this file since 12563 was 12563, checked in by ascheibe, 9 years ago

#2394 merged r12428, r12429, r12430, r12435, r12442, r12443, r12445, r12514, r12517, r12519, r12520, r12521, r12523, r12532, r12542, r12546, r12552, r12553, r12556, r12557, r12559, r12561, r12146, r12457 into stable

File size: 8.9 KB
Line 
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            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.UsedMemory / 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                    // charts are currently filled with old total/used data
130                    // start temporary
131                    var usedCores = status.CoreStatus.TotalCores - status.CoreStatus.FreeCores;
132                    var usedMemory = status.MemoryStatus.TotalMemory - status.MemoryStatus.FreeMemory;
133                    // end temporary
134                    coreSeries[0].push([$scope.status.Timestamp, status.CoreStatus.TotalCores]);
135                    coreSeries[1].push([$scope.status.Timestamp, usedCores]);
136                    memorySeries[0].push([$scope.status.Timestamp, Math.round(status.MemoryStatus.TotalMemory / 1024)]);
137                    memorySeries[1].push([$scope.status.Timestamp, Math.round(usedMemory / 1024)]);
138                    $scope.cpu.series = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
139                    $scope.core.series = [
140                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
141                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
142                    ];
143                    $scope.memory.series = [
144                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
145                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
146                    ];
147                });
148            };
149
150            var init = function () {
151                // load the chart history of the last 24 hours
152                var nowDate = new Date();
153                var startDate = new Date();
154                startDate.setTime(nowDate.getTime() - (24 * 60 * 60 * 1000));
155                dataService.getStatusHistory({ start: ConvertDate(startDate), end: ConvertDate(nowDate) }, function (status) {
156                    var noOfStatus = status.length;
157                    var cpuSeries = [];
158                    var coreSeries = [[], []];
159                    var memorySeries = [[], []];
160                    for (var i = 0; i < noOfStatus; ++i) {
161                        var curStatus = status[i];
162                        var cpuData = Math.round(curStatus.CpuUtilizationStatus.ActiveCpuUtilization);
163                        cpuSeries.push([curStatus.Timestamp, cpuData]);
164                        coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.ActiveCores]);
165                        coreSeries[1].push([curStatus.Timestamp, curStatus.CoreStatus.CalculatingCores]);
166                        memorySeries[0].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.ActiveMemory / 1024)]);
167                        memorySeries[1].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.UsedMemory / 1024)]);
168                    }
169                    $scope.cpu.series = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
170                    $scope.core.series = [
171                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
172                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
173                    ];
174                    $scope.memory.series = [
175                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
176                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
177                    ];
178                    updateStatus();
179                });
180            };
181            init();
182            // set interval and stop updating when changing location
183            $scope.updateInterval = $interval(updateStatus, $scope.interval);
184            var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
185                $interval.cancel($scope.updateInterval);
186                cancelInterval();
187            });
188        }]
189    );
190})();
Note: See TracBrowser for help on using the repository browser.