-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17fe082
commit 427f512
Showing
9 changed files
with
829 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,211 @@ | |||
(function (angular, smi2) { | |||
'use strict'; | |||
|
|||
angular.module(smi2.app.name).controller('ClusterController', ClusterController); | |||
ClusterController.$inject = [ | |||
'$scope', | |||
'API', | |||
'ThemeService', | |||
'$interval', | |||
'localStorageService', | |||
'$mdDialog', | |||
'hotRegisterer' | |||
]; | |||
|
|||
/** | |||
* @ngdoc controller | |||
*/ | |||
function ClusterController($scope, API, ThemeService, $interval, localStorageService,$mdDialog,hotRegisterer) { | |||
|
|||
const LS_INTERVAL_KEY = 'proc.interval'; | |||
const LS_SORT_KEY = 'proc.key'; | |||
|
|||
|
|||
$scope.widgets=[]; | |||
|
|||
$scope.staticGrid=true; | |||
$scope.gridStackOptions = { | |||
cellHeight: 200, | |||
verticalMargin: 0, | |||
disableDrag:true, | |||
disableResize:true, | |||
staticGrid:true | |||
}; | |||
$scope.logData={}; | |||
|
|||
$scope.vars = { | |||
readOnlyRows : true, | |||
canShowTable : false, | |||
WidgetTable : false, | |||
queryesToKill:{}, | |||
clusterMode: true, | |||
logMode : true, | |||
loading: false, | |||
|
|||
isClusterLoad: false, | |||
clusterList: false, | |||
isDark: ThemeService.isDark(), | |||
sort: /^[a-z0-9_]+$/.test(localStorageService.get(LS_SORT_KEY)) ? localStorageService.get(LS_SORT_KEY) : null, | |||
interval: localStorageService.get(LS_INTERVAL_KEY) || -1, | |||
|
|||
}; | |||
|
|||
|
|||
|
|||
|
|||
|
|||
let intervalHandle = null; | |||
|
|||
// ------------------------------------------------------------------------------ | |||
$scope.initClusterConfig = () => { | |||
// | |||
|
|||
let sql = 'SELECT host_address,port FROM system.clusters GROUP BY host_address,port LIMIT 10'; | |||
$scope.vars.clusterList = []; | |||
API.fetchQuery(sql).then(function (data) { | |||
data.data.forEach((cell) => { | |||
$scope.vars.clusterList.push(cell.host_address + ':' + cell.port); | |||
|
|||
}); | |||
$scope.vars.isClusterLoad = true; | |||
console.log("Cluster nodes list", $scope.vars.clusterList.join(",")); | |||
// then cluster load config | |||
$scope.load(); | |||
}, function (response) { | |||
$scope.vars.isClusterLoad = true; | |||
console.error('Error ' + response); | |||
}); | |||
}; | |||
// ------------------------------------------------------------------------------ | |||
$scope.flush = () => { | |||
$scope.logData={}; | |||
}; | |||
|
|||
// ------------------------------------------------------------------------------ | |||
$scope.megreProcessData = ($new) => { | |||
|
|||
// @todo : logData ???? need merge and update `++count` | |||
$new.forEach((cell) => { | |||
if ($scope.logData[cell.hash]) | |||
{ | |||
|
|||
let c=$scope.logData[cell.hash].count; | |||
|
|||
if ($scope.logData[cell.hash].initial_query_id!=cell.initial_query_id) | |||
{ | |||
c=c+1; | |||
} | |||
cell.count=c; | |||
$scope.logData[cell.hash]=cell; | |||
} else | |||
{ | |||
cell.count=1; | |||
$scope.logData[cell.hash]=cell; | |||
|
|||
} | |||
|
|||
|
|||
|
|||
}); | |||
// let array = $.map($scope.logData, function(value, index) { | |||
// return [value]; | |||
// }); | |||
|
|||
return _.values($scope.logData); | |||
|
|||
} ; | |||
|
|||
// ------------------------------------------------------------------------------ | |||
$scope.load = () => { | |||
console.info("Call load processes"); | |||
let sql = `SELECT *,cityHash64(*) as hash,hostName()`; | |||
|
|||
|
|||
if ($scope.vars.isClusterLoad && $scope.vars.clusterList ) { | |||
sql = sql + ` FROM remote('` + $scope.vars.clusterList.join(",") + `',system.replication_queue, '` + API.getLogin() + `','` + API.getPassword() + `') `; | |||
} | |||
else { | |||
sql = sql + ` FROM system.replication_queue `; | |||
} | |||
|
|||
API.fetchQuery(sql).then(function ( queryResult ) { | |||
|
|||
console.log('queryResult',queryResult); | |||
let $_dataProvider=new DataProvider(queryResult); | |||
if (!$scope.widgets[0]) | |||
{ | |||
// make new WidgetTable | |||
|
|||
$_dataProvider.setColumnsHumanSort(['bytes','memory_usage','bytes_read','bytes_written']); | |||
$_dataProvider.setSort('rows',-1); | |||
|
|||
$scope.widgets[0]=new WidgetTable($_dataProvider,false,12,9); | |||
$_dataProvider.data.forEach((cell) => { | |||
$scope.logData[cell.hash]=cell; | |||
}); | |||
} | |||
else { | |||
// on update exists | |||
|
|||
|
|||
if ($scope.vars.logMode) { | |||
// if need merge data | |||
$scope.widgets[0].updateData($scope.megreProcessData($_dataProvider.data)); | |||
} else { | |||
// force reset data, no merge | |||
$scope.widgets[0].updateData($_dataProvider.data); | |||
} | |||
|
|||
|
|||
|
|||
} | |||
|
|||
|
|||
$scope.vars.canShowTable=true; | |||
$scope.vars.data = true; | |||
$scope.vars.loading = false; | |||
|
|||
$scope.$applyAsync(); | |||
|
|||
}, function ( response ) { | |||
$scope.vars.loading = false; | |||
console.error( 'Error ' + response ); | |||
}); | |||
}; | |||
|
|||
// ------------------------------------------------------------------------------ | |||
$scope.setInterval = () => { | |||
|
|||
localStorageService.set(LS_INTERVAL_KEY, $scope.vars.interval); | |||
|
|||
if (intervalHandle) { | |||
$interval.cancel(intervalHandle); | |||
intervalHandle = null; | |||
} | |||
if ($scope.vars.interval > -1) { | |||
intervalHandle = $interval($scope.load, $scope.vars.interval * 1000); | |||
} | |||
}; | |||
|
|||
// ------------------------------------------------------------------------------ | |||
$scope.$on('$destroy', function() { | |||
$scope.vars.interval=-1; | |||
$interval.cancel(intervalHandle); | |||
$scope.setInterval(); | |||
}); | |||
|
|||
|
|||
// ------------------------------------------------------------------------------ | |||
// start | |||
$scope.initClusterConfig(); | |||
|
|||
|
|||
|
|||
if ($scope.vars.interval > -1) { | |||
$scope.setInterval(); | |||
} | |||
|
|||
|
|||
} | |||
|
|||
})(angular, smi2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
<div ng-controller="ClusterController as render" style="width: 100%;height: 100%"> | |||
<h1 class="md-title">Cluster & Replicas (system.replication_queue)</h1> | |||
<md-card-content> | |||
<div layout="row"> | |||
<md-input-container class="md-block" flex-gt-sm> | |||
|
|||
<label>Frequency</label> | |||
<md-select ng-model="vars.interval" ng-change="setInterval()" > | |||
<md-option ng-repeat="interval in [-1, 0.2 , 0.5, 1, 5, 10, 20, 30]" ng-value="interval"> | |||
{{interval == -1 ? ('Refresh is disabled') : interval +' '+'sec'}} | |||
</md-option> | |||
</md-select> | |||
</md-input-container> | |||
|
|||
<md-input-container class="md-block" flex-gt-sm ng-click="load()"> | |||
<md-button class="md-raised md-primary">Refresh</md-button> | |||
</md-input-container> | |||
|
|||
<md-input-container class="md-block" flex-gt-sm ng-click="flush()"> | |||
<md-button class="md-raised">Reset</md-button> | |||
</md-input-container> | |||
|
|||
</div> | |||
|
|||
</md-card-content> | |||
|
|||
|
|||
<div class="row" flex> | |||
<div class="row"> | |||
<div class="col-md-12"> | |||
|
|||
<div class="WidgetsListResult"> | |||
<div gridstack class="grid-stack grid1" options="gridStackOptions" staticGrid="staticGrid"> | |||
|
|||
|
|||
|
|||
<div gridstack-item ng-repeat="w in widgets" class="grid-stack-item WidgetsListItem" | |||
gs-item-x="w.x" gs-item-y="w.y" | |||
gs-item-width="w.sizeX" gs-item-height="w.sizeY" > | |||
|
|||
<div class="widget-grid-stack grid-stack-item-content "> | |||
<draw-widget | |||
widget="w" ng-if="w.init && !w.error" | |||
isdark="vars.isDark" class="widget widget-grid-stack-item widget-{{w.type}} widget-selector" events="events"> | |||
</draw-widget> | |||
</div> | |||
</div> | |||
</div> | |||
|
|||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
|
|||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
<h1 class="md-title">DB Size</h1> | |||
|
|||
|
|||
|
|||
<div ng-controller="DBSizeController as render"> | |||
<!--<md-button class="md-raised md-primary" ng-click="dumpStaticGridSizes()">dumpStaticGridSizes</md-button>--> | |||
<div class="row"> | |||
<div class="col-md-12"> | |||
|
|||
<div class="WidgetsListResult"> | |||
<div gridstack class="grid-stack grid1" options="gridStackOptions" staticGrid="staticGrid"> | |||
<div gridstack-item ng-repeat="w in widgets" class="grid-stack-item WidgetsListItem" | |||
gs-item-x="w.x" gs-item-y="w.y" | |||
gs-item-width="w.sizeX" gs-item-height="w.sizeY" > | |||
|
|||
<div class="widget-grid-stack grid-stack-item-content "> | |||
<draw-widget | |||
widget="w" ng-if="w.init && !w.error" | |||
isdark="vars.isDark" class="widget widget-grid-stack-item widget-{{w.type}} widget-selector" events="events"> | |||
</draw-widget> | |||
</div> | |||
</div> | |||
</div> | |||
|
|||
</div> | |||
|
|||
</div> | |||
</div> | |||
</div> |
Oops, something went wrong.