1 | (function () {
|
---|
2 | var module = appStatusPlugin.getAngularModule();
|
---|
3 | module.controller('app.status.historyCtrl',
|
---|
4 | ['$scope', '$interval', 'app.status.data.service', '$log',
|
---|
5 | function ($scope, $interval, dataService, $log) {
|
---|
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 | $scope.fromDate = new Date();
|
---|
43 | $scope.toDate = new Date();
|
---|
44 |
|
---|
45 | $scope.fromIsOpen = false;
|
---|
46 | $scope.toIsOpen = false;
|
---|
47 |
|
---|
48 | $scope.quickSelectionList = [
|
---|
49 | { id: 0, name: 'Custom' },
|
---|
50 | { id: 1, name: 'Today' },
|
---|
51 | { id: 2, name: 'Yesterday' },
|
---|
52 | { id: 3, name: 'Last 7 Days' },
|
---|
53 | { id: 4, name: 'Last 30 Days' },
|
---|
54 | { id: 5, name: 'Last 6 Months' },
|
---|
55 | { id: 6, name: 'Last Year' }
|
---|
56 | ];
|
---|
57 | $scope.changeQuickSelection = function (quickSelection) {
|
---|
58 | var today = new Date();
|
---|
59 | var oneDayInMs = 24 * 60 * 60 * 1000;
|
---|
60 | switch (quickSelection.id) {
|
---|
61 | case 1:
|
---|
62 | $scope.fromDate = new Date(today.valueOf());
|
---|
63 | $scope.toDate = new Date(today.valueOf());
|
---|
64 | break;
|
---|
65 | case 2:
|
---|
66 | $scope.fromDate = new Date(today.valueOf() - oneDayInMs);
|
---|
67 | $scope.toDate = new Date(today.valueOf() - oneDayInMs);
|
---|
68 | break;
|
---|
69 | case 3:
|
---|
70 | $scope.fromDate = new Date(today.valueOf() - (7 * oneDayInMs));
|
---|
71 | $scope.toDate = new Date(today.valueOf());
|
---|
72 | break;
|
---|
73 | case 4:
|
---|
74 | $scope.fromDate = new Date(today.valueOf() - (30 * oneDayInMs));
|
---|
75 | $scope.toDate = new Date(today.valueOf());
|
---|
76 | break;
|
---|
77 | case 5:
|
---|
78 | var month = today.getMonth() - 6;
|
---|
79 | if (month < 0) {
|
---|
80 | month += 12;
|
---|
81 | }
|
---|
82 | $scope.fromDate = new Date(today.valueOf());
|
---|
83 | $scope.fromDate.setMonth(month);
|
---|
84 | $scope.toDate = new Date(today.valueOf());
|
---|
85 | break;
|
---|
86 | case 6:
|
---|
87 | $scope.fromDate = new Date(today.valueOf());
|
---|
88 | $scope.fromDate.setFullYear(today.getFullYear()-1);
|
---|
89 | $scope.toDate = new Date(today.valueOf());
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | $scope.curQuickSelection = quickSelection;
|
---|
93 | };
|
---|
94 | // set default 'today'
|
---|
95 | $scope.changeQuickSelection($scope.quickSelectionList[1]);
|
---|
96 |
|
---|
97 | $scope.openFromDateSelection = function ($event) {
|
---|
98 | $event.preventDefault();
|
---|
99 | $event.stopPropagation();
|
---|
100 | $scope.toIsOpen = false;
|
---|
101 | $scope.fromIsOpen = true;
|
---|
102 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
103 | };
|
---|
104 |
|
---|
105 | $scope.openToDateSelection = function ($event) {
|
---|
106 | $event.preventDefault();
|
---|
107 | $event.stopPropagation();
|
---|
108 | $scope.fromIsOpen = false;
|
---|
109 | $scope.toIsOpen = true;
|
---|
110 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
111 | };
|
---|
112 |
|
---|
113 | $scope.dateOptions = {
|
---|
114 | formatYear: 'yy',
|
---|
115 | startingDay: 1
|
---|
116 | };
|
---|
117 |
|
---|
118 | $scope.cpuSeries = [[]];
|
---|
119 | $scope.coreSeries = [[]];
|
---|
120 | $scope.memorySeries = [[]];
|
---|
121 |
|
---|
122 | $scope.updateCharts = function () {
|
---|
123 | dataService.getStatusHistory({ start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
|
---|
124 | var noOfStatus = status.length;
|
---|
125 | var cpuSeries = [];
|
---|
126 | var coreSeries = [[], []];
|
---|
127 | var memorySeries = [[], []];
|
---|
128 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
129 | var curStatus = status[i];
|
---|
130 | var cpuData = Math.round(curStatus.CpuUtilizationStatus.TotalCpuUtilization);
|
---|
131 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
132 | coreSeries[0].push([curStatus.Timestamp, curStatus.CoreStatus.TotalCores]);
|
---|
133 | coreSeries[1].push([curStatus.Timestamp, curStatus.CoreStatus.UsedCores]);
|
---|
134 | memorySeries[0].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.TotalMemory / 1024)]);
|
---|
135 | memorySeries[1].push([curStatus.Timestamp, Math.round(curStatus.MemoryStatus.UsedMemory / 1024)]);
|
---|
136 | }
|
---|
137 | $scope.cpuSeries = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
138 | $scope.coreSeries = [
|
---|
139 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
140 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
141 | ];
|
---|
142 | $scope.memorySeries = [
|
---|
143 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
144 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
145 | ];
|
---|
146 | });
|
---|
147 | };
|
---|
148 | $scope.updateCharts();
|
---|
149 | }]
|
---|
150 | );
|
---|
151 | })(); |
---|