1 | (function () {
|
---|
2 | var module = appStatusPlugin.getAngularModule();
|
---|
3 | module.controller('app.status.historyCtrl',
|
---|
4 | ['$scope', '$interval', 'app.status.data.service',
|
---|
5 | function ($scope, $interval, dataService) {
|
---|
6 | $scope.chartOptions = {
|
---|
7 | grid: {
|
---|
8 | borderWidth: 1,
|
---|
9 | labelMargin: 15
|
---|
10 | },
|
---|
11 | series: {
|
---|
12 | shadowSize: 0
|
---|
13 | },
|
---|
14 | yaxis: {
|
---|
15 | min: 0,
|
---|
16 | max: 100
|
---|
17 | },
|
---|
18 | xaxis: {
|
---|
19 | mode: "time",
|
---|
20 | twelveHourClock: false
|
---|
21 | }
|
---|
22 | };
|
---|
23 |
|
---|
24 | $scope.fillChartOptions = {
|
---|
25 | grid: {
|
---|
26 | borderWidth: 1,
|
---|
27 | labelMargin: 15
|
---|
28 | },
|
---|
29 | series: {
|
---|
30 | shadowSize: 0,
|
---|
31 | lines: {
|
---|
32 | show: true,
|
---|
33 | fill: true
|
---|
34 | }
|
---|
35 | },
|
---|
36 | xaxis: {
|
---|
37 | mode: "time",
|
---|
38 | twelveHourClock: false
|
---|
39 | }
|
---|
40 | };
|
---|
41 |
|
---|
42 |
|
---|
43 | $scope.fromDate = new Date();
|
---|
44 | $scope.toDate = new Date();
|
---|
45 |
|
---|
46 | $scope.fromIsOpen = false;
|
---|
47 | $scope.toIsOpen = false;
|
---|
48 |
|
---|
49 | $scope.quickSelectionList = [
|
---|
50 | { id: 0, name: 'Custom' },
|
---|
51 | { id: 1, name: 'Today' },
|
---|
52 | { id: 2, name: 'Yesterday' },
|
---|
53 | { id: 3, name: 'Last 7 Days' },
|
---|
54 | { id: 4, name: 'Last 30 Days' }
|
---|
55 | ];
|
---|
56 | $scope.changeQuickSelection = function (quickSelection) {
|
---|
57 | var today = new Date();
|
---|
58 | var oneDayInMs = 24 * 60 * 60 * 1000;
|
---|
59 | switch (quickSelection.id) {
|
---|
60 | case 1:
|
---|
61 | $scope.fromDate = new Date(today.valueOf());
|
---|
62 | $scope.toDate = new Date(today.valueOf());
|
---|
63 | break;
|
---|
64 | case 2:
|
---|
65 | $scope.fromDate = new Date(today.valueOf() - oneDayInMs);
|
---|
66 | $scope.toDate = new Date(today.valueOf() - oneDayInMs);
|
---|
67 | break;
|
---|
68 | case 3:
|
---|
69 | $scope.fromDate = new Date(today.valueOf() - (7 * oneDayInMs));
|
---|
70 | $scope.toDate = new Date(today.valueOf());
|
---|
71 | break;
|
---|
72 | case 4:
|
---|
73 | $scope.fromDate = new Date(today.valueOf() - (30 * oneDayInMs));
|
---|
74 | $scope.toDate = new Date(today.valueOf());
|
---|
75 | break;
|
---|
76 | }
|
---|
77 | $scope.curQuickSelection = quickSelection;
|
---|
78 | };
|
---|
79 | // set default 'today'
|
---|
80 | $scope.changeQuickSelection($scope.quickSelectionList[1]);
|
---|
81 |
|
---|
82 | $scope.openFromDateSelection = function ($event) {
|
---|
83 | $event.preventDefault();
|
---|
84 | $event.stopPropagation();
|
---|
85 | $scope.toIsOpen = false;
|
---|
86 | $scope.fromIsOpen = true;
|
---|
87 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
88 | };
|
---|
89 |
|
---|
90 | $scope.openToDateSelection = function ($event) {
|
---|
91 | $event.preventDefault();
|
---|
92 | $event.stopPropagation();
|
---|
93 | $scope.fromIsOpen = false;
|
---|
94 | $scope.toIsOpen = true;
|
---|
95 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
96 | };
|
---|
97 |
|
---|
98 | $scope.dateOptions = {
|
---|
99 | formatYear: 'yy',
|
---|
100 | startingDay: 1
|
---|
101 | };
|
---|
102 |
|
---|
103 | $scope.cpuSeries = [[]];
|
---|
104 | $scope.coreSeries = [[]];
|
---|
105 | $scope.memorySeries = [[]];
|
---|
106 |
|
---|
107 | $scope.updateCharts = function () {
|
---|
108 | dataService.getStatusHistory({ start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
|
---|
109 | var noOfStatus = status.length;
|
---|
110 | var cpuSeries = [];
|
---|
111 | var coreSeries = [[], []];
|
---|
112 | var memorySeries = [[], []];
|
---|
113 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
114 | var curStatus = status[i];
|
---|
115 | var cpuData = Math.round(curStatus.CpuUtilizationStatus.ActiveCpuUtilization);
|
---|
116 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
117 | coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.ActiveCores]);
|
---|
118 | coreSeries[1].push([curStatus.Timestamp, curStatus.CoreStatus.CalculatingCores]);
|
---|
119 | memorySeries[0].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.ActiveMemory / 1024)]);
|
---|
120 | memorySeries[1].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.UsedMemory / 1024)]);
|
---|
121 | }
|
---|
122 | $scope.cpuSeries = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
123 | $scope.coreSeries = [
|
---|
124 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
125 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
126 | ];
|
---|
127 | $scope.memorySeries = [
|
---|
128 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
129 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
130 | ];
|
---|
131 |
|
---|
132 | });
|
---|
133 | };
|
---|
134 | $scope.updateCharts();
|
---|
135 | }]
|
---|
136 | );
|
---|
137 | })(); |
---|