Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
JVM Alerts rafactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Viliam Rockai committed Aug 13, 2015
1 parent 9941254 commit 77410f2
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,77 @@
<h4 class="modal-title">Alert Settings</h4>
</div>
<div class="modal-body alert-settings">
<p>Configure conditions settings for Heap usage alerts and notifications.</p>
<form class="form-horizontal">
<fieldset>
<legend>Threshold Conditions</legend>
<div class="form-group">
<label class="col-sm-3 control-label">Maximum usage</label>
<div class="col-sm-6">
<span class="hk-input-text">{{jas.maxUsage / 1024 / 1024 | number : 2}} MB</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="usage-greater">Usage greater than</label>
<div class="col-sm-5">
<div class="input-group hk-input-small">
<input type="number" min="0" max="100" ng-model="jas.conditionGtPercent" class="form-control" id="usage-greater" ng-disabled="!jas.conditionGtEnabled">
<div class="input-group-addon">%</div>
<tabset>
<tab heading="Heap Usage">
<p>Configure conditions settings for Heap usage alerts and notifications.</p>
<form class="form-horizontal">
<fieldset>
<legend>Threshold Conditions</legend>
<div class="form-group">
<label class="col-sm-3 control-label">Maximum usage</label>
<div class="col-sm-6">
<span class="hk-input-text">{{jas.maxUsage / 1024 / 1024 | number : 2}} MB</span>
</div>
</div>
<span class="input-detail">({{jas.conditionGtEnabled && jas.conditionGtPercent ? (jas.maxUsage * jas.conditionGtPercent / 100/1024/1024 | number:2) : '-'}} MB)</span>
</div>
<div class="col-sm-4">
<div class="onoffswitch pull-right">
<input type="checkbox" id="usage-greater-switch" class="onoffswitch-checkbox" ng-model="jas.conditionGtEnabled" ng-click="jas.enableGt()">
<label class="onoffswitch-label" for="usage-greater-switch">
<div class="form-group">
<label class="col-sm-3 control-label" for="usage-greater">Usage greater than {{jas.adm.heapconditionGtPercent}}</label>
<div class="col-sm-5">
<div class="input-group hk-input-small">
<input type="number" min="0" max="100" ng-model="jas.adm.heap.conditionGtPercent" class="form-control" id="usage-greater" ng-disabled="!jas.adm.heap.conditionGtEnabled">
<div class="input-group-addon">%</div>
</div>
<span class="input-detail">({{jas.adm.heap.conditionGtEnabled && jas.adm.heap.conditionGtPercent ? (jas.maxUsage * jas.adm.heap.conditionGtPercent / 100/1024/1024 | number:2) : '-'}} MB)</span>
</div>
<div class="col-sm-4">
<div class="onoffswitch pull-right">
<input type="checkbox" id="usage-greater-switch" class="onoffswitch-checkbox" ng-model="jas.adm.heap.conditionGtEnabled" ng-click="jas.enableHeapGt()">
<label class="onoffswitch-label" for="usage-greater-switch">
<span class="onoffswitch-inner">
<span class="onoffswitch-active ng-binding">ON</span>
<span class="onoffswitch-inactive ng-binding">OFF</span>
</span>
<span class="onoffswitch-switch"></span>
</label>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="usage-less">Usage less than</label>
<div class="col-sm-5">
<div class="input-group hk-input-small">
<input type="number" min="0" max="100" ng-model="jas.conditionLtPercent" class="form-control" id="usage-less" ng-disabled="!jas.conditionLtEnabled">
<div class="input-group-addon">%</div>
</div>
<span class="input-detail">({{jas.conditionLtEnabled && jas.conditionLtPercent ? (jas.maxUsage * jas.conditionLtPercent / 100/1024/1024 | number:2) : '-'}} MB)</span>
</div>
<div class="col-sm-4">
<div class="onoffswitch pull-right">
<input type="checkbox" id="usage-less-switch" class="onoffswitch-checkbox" ng-model="jas.conditionLtEnabled" ng-click="jas.enableLt()">
<label class="onoffswitch-label" for="usage-less-switch">
<div class="form-group">
<label class="col-sm-3 control-label" for="usage-less">Usage less than {{jas.adm.heap.conditionLtPercent}}</label>
<div class="col-sm-5">
<div class="input-group hk-input-small">
<input type="number" min="0" max="100" ng-model="jas.adm.heap.conditionLtPercent" class="form-control" id="usage-less" ng-disabled="!jas.adm.heap.conditionLtEnabled">
<div class="input-group-addon">%</div>
</div>
<span class="input-detail">({{jas.adm.heap.conditionLtEnabled && jas.adm.heap.conditionLtPercent ? (jas.maxUsage * jas.adm.heap.conditionLtPercent / 100/1024/1024 | number:2) : '-'}} MB)</span>
</div>
<div class="col-sm-4">
<div class="onoffswitch pull-right">
<input type="checkbox" id="usage-less-switch" class="onoffswitch-checkbox" ng-model="jas.adm.heap.conditionLtEnabled" ng-click="jas.enableHeapLt()">
<label class="onoffswitch-label" for="usage-less-switch">
<span class="onoffswitch-inner">
<span class="onoffswitch-active ng-binding">ON</span>
<span class="onoffswitch-inactive ng-binding">OFF</span>
</span>
<span class="onoffswitch-switch"></span>
</label>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
</div>
</div>
</div>
</fieldset>
<hk-fieldset-dampening hk-duration="jas.responseDuration"></hk-fieldset-dampening>
</fieldset>
<hk-fieldset-dampening hk-duration="jas.adm.heap.responseDuration"></hk-fieldset-dampening>

<hk-fieldset-notification hk-alert-email="jas.adm.heap.email"></hk-fieldset-notification>
</form>
</tab>
<tab heading="Non-Heap Usage">
Static content
</tab>
<tab heading="Garbage Collection">
Static content
</tab>
</tabset>


<hk-fieldset-notification hk-alert-email="jas.trigger.actions.email[0]"></hk-fieldset-notification>
</form>
</div>
<div class="modal-footer alert-settings">
<button type="button" class="btn btn-primary" ng-click="jas.save()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,19 @@ module HawkularMetrics {
_module.controller('JvmAlertController', JvmAlertController);

export class JvmAlertSetupController {
public static $inject = ['$scope', 'HawkularAlert', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
'$rootScope', '$routeParams', '$modalInstance', 'HawkularMetric'];

private resourceId: string;
private trigger: any;
private dampening: any;
private conditionGt: any;
public responseDuration: number;
public static $inject = ['$scope', 'HawkularAlertsManager', 'ErrorsManager', '$log', '$q',
'$rootScope', '$routeParams', '$modalInstance'];

private conditionGtEnabled: boolean;
private conditionLtEnabled: boolean;
// Trigger definitions are GET in the constructor. They are used as backup reference to avoid persisting
// non-changed entities.
private triggerDefinition: any = {};

public conditionGtPercent: number;
public conditionLtPercent: number;
// Alert Definition Model, used in the view
public adm: any = {
heap: {},
nheap: {},
gcol: {}
};

// TODO - Get the actual data from backend
public maxUsage: number = AppServerJvmDetailsController.MAX_HEAP;
Expand All @@ -186,84 +185,72 @@ module HawkularMetrics {
public isSettingChange = false;

constructor(public $scope:any,
private HawkularAlert:any,
private HawkularAlertsManager: HawkularMetrics.IHawkularAlertsManager,
private ErrorsManager: HawkularMetrics.IErrorsManager,
private $log: ng.ILogService,
private $q: ng.IQService,
private $rootScope: any,
private $routeParams: any,
private $modalInstance: any,
private HawkularMetric: any) {

this.$log.debug('querying data');
this.$log.debug('$routeParams', $routeParams.resourceId);
private $modalInstance: any) {

this.maxUsage = AppServerJvmDetailsController.MAX_HEAP;

// TODO - update the pfly notification service to support more and category based notifications containers.
this.$rootScope.hkNotifications = {alerts: []};
this.resourceId = $routeParams.resourceId;
this.$log.debug('this.resourceId', this.resourceId);

var triggerId: string = this.resourceId + '_jvm_pheap';
/*
this.HawkularMetric.GaugeMetricData(this.$rootScope.currentPersona.id).queryMetrics({
gaugeId: 'MI~R~[' + this.$routeParams.resourceId + '~/]~MT~WildFly Memory Metrics~Heap Max',
buckets: 1}, (resource) => {
this.maxUsage = resource[0];
}, this);
*/
this.HawkularAlertsManager.getTrigger(triggerId).then((data) => {
this.$log.debug('getTrigger', data);
this.trigger = data;
return HawkularAlert.Dampening.query({triggerId: triggerId}).$promise;
}).then((data) => {
this.dampening = data[0];
this.responseDuration = this.dampening.evalTimeSetting;

this.$log.debug('HawkularAlert.Dampening.query', data);
return HawkularAlert.Condition.query({triggerId: triggerId}).$promise;
}).then((data)=> {
this.conditionGt = data[0];
this.conditionGtEnabled = this.conditionGt.thresholdHigh < this.maxUsage;
this.conditionGtPercent = this.conditionGt.thresholdHigh > 0 ?
this.conditionGt.thresholdHigh * 100 / this.maxUsage : 0;

this.conditionLtEnabled = this.conditionGt.thresholdLow > 0;
this.conditionLtPercent = this.conditionGt.thresholdLow > 0 ?
this.conditionGt.thresholdLow * 100 / this.maxUsage : 0;

this.$log.debug('HawkularAlert.Condition.query', this.conditionGt);
});
}
var triggerId: string = $routeParams.resourceId + '_jvm_pheap';

// Heap Usage trigger definition
this.HawkularAlertsManager.getAlertDefinition(triggerId).then( (alertDefinitionData) => {
this.triggerDefinition['heap'] = alertDefinitionData;

public enableGt(): void {
this.$log.debug('enableGt');
this.adm.heap['trigger'] = alertDefinitionData.trigger;

var triggerId: string = this.trigger.id;
var conditionId: string = this.conditionGt.conditionId;
this.adm.heap['email'] = alertDefinitionData.trigger.actions.email[0];

this.conditionGt.thresholdHigh = this.conditionGtEnabled ? (this.maxUsage / this.conditionGtPercent) :
this.maxUsage;
this.adm.heap['dampening'] = alertDefinitionData.dampenings[0];
this.adm.heap['responseDuration'] = this.adm.heap.dampening.evalTimeSetting;

this.HawkularAlertsManager.updateCondition(triggerId, conditionId, this.conditionGt).then((data:any) => {
this.conditionGt = data[0];
this.$log.debug('this.conditionGt', this.conditionGt);
this.adm.heap['condition'] = alertDefinitionData.conditions[0];
this.adm.heap['conditionGtEnabled'] = this.adm.heap.condition.thresholdHigh < this.maxUsage;
this.adm.heap['conditionGtPercent'] = this.adm.heap.condition.thresholdHigh > 0 ?
this.adm.heap.condition.thresholdHigh * 100 / this.maxUsage : 0;

this.adm.heap['conditionLtEnabled'] = this.adm.heap.condition.thresholdLow > 0;
this.adm.heap['conditionLtPercent'] = this.adm.heap.condition.thresholdLow > 0 ?
this.adm.heap.condition.thresholdLow * 100 / this.maxUsage : 0;
});

// Non-Heap Usage trigger definition

// Garbage Collection trigger definition
}

public enableLt(): void {
this.$log.debug('enableLt');
public enableHeapGt(): void {
var triggerId: string = this.adm.heap.trigger.id;
var conditionId: string = this.adm.heap.condition.conditionId;

this.adm.heap.condition.thresholdHigh = this.adm.heap.conditionGtEnabled ?
(this.maxUsage / this.adm.heap.conditionGtPercent) : this.maxUsage;

var triggerId: string = this.trigger.id;
var conditionId: string = this.conditionGt.conditionId;
this.HawkularAlertsManager.updateCondition(triggerId, conditionId, this.adm.heap.condition).then((data:any) => {
this.triggerDefinition.heap.conditions = data;
this.adm.heap.condition = data[0];
this.$log.debug('this.conditionGt', this.adm.heap.condition);
});
}

this.conditionGt.thresholdLow = this.conditionLtEnabled ? (this.maxUsage / this.conditionLtPercent) : 0;
public enableHeapLt(): void {
var triggerId: string = this.adm.heap.trigger.id;
var conditionId: string = this.adm.heap.condition.conditionId;

this.HawkularAlertsManager.updateCondition(triggerId, conditionId, this.conditionGt).then((data:any) => {
this.conditionGt = data[0];
this.$log.debug('this.conditionGt', this.conditionGt);
this.adm.heap.condition.thresholdLow = this.adm.heap.conditionLtEnabled ?
(this.maxUsage / this.adm.heap.conditionLtPercent) : 0;

this.HawkularAlertsManager.updateCondition(triggerId, conditionId, this.adm.heap.condition).then((data:any) => {
this.triggerDefinition.heap.conditions = data;
this.adm.heap.condition = data[0];
this.$log.debug('this.conditionGt', this.adm.heap.condition);
});
}

Expand All @@ -277,51 +264,47 @@ module HawkularMetrics {
// Clear alerts notifications on save (discard previous success/error list)
this.$rootScope.hkNotifications.alerts = [];

var isError = false;

// Error notification done with callback function on error
var errorCallback = (error: any, msg: string) => {
this.$rootScope.hkNotifications.alerts.push({
type: 'error',
message: msg
});
isError = true;
};

// Field helping to disable the save button while save action is in progress.
this.saveProgress = true;
var isError = false;
// Check if email action exists
this.HawkularAlertsManager.addEmailAction(this.trigger.actions.email[0]).then(()=> {
return this.HawkularAlertsManager.updateTrigger(this.trigger.id, this.trigger);
}, (error)=> {
return this.ErrorsManager.errorHandler(error, 'Error saving email action.', errorCallback);
}).then(()=> {
this.dampening.evalTimeSetting = this.responseDuration;

return this.HawkularAlertsManager.updateDampening(this.trigger.id,this.dampening.dampeningId, this.dampening);
}, (error)=> {
return this.ErrorsManager.errorHandler(error, 'Error updating trigger', errorCallback);
}).then(()=> {
this.conditionGt.thresholdHigh = this.conditionGtEnabled ? this.maxUsage * this.conditionGtPercent / 100 :
this.maxUsage;
this.conditionGt.thresholdLow = this.conditionLtEnabled ? this.maxUsage * this.conditionLtPercent / 100 : 0;
return this.HawkularAlertsManager.updateCondition(this.trigger.id, this.conditionGt.conditionId,
this.conditionGt);
}, (error)=> {
return this.ErrorsManager.errorHandler(error, 'Error updating dampening.', errorCallback);
}).then(angular.noop, (error)=> {
isError = true;
return this.ErrorsManager.errorHandler(error, 'Error updating conditionGt condition.', errorCallback);
}).finally(()=> {
this.saveProgress = false;

if(!isError) {
// notify success
this.$rootScope.hkNotifications.alerts.push({
type: 'success',
message: 'Changes saved successfully.'
});
}

this.cancel();
});

// Create an alert definition objects (trigger, dampening, condition) to
var heapAlertDefinition = angular.copy(this.triggerDefinition.heap);
heapAlertDefinition.trigger.actions.email[0] = this.adm.heap.email;
heapAlertDefinition.dampenings[0].evalTimeSetting = this.adm.heap.responseDuration;

heapAlertDefinition.conditions[0].thresholdHigh = this.adm.heap.conditionGtEnabled ?
this.maxUsage * this.adm.heap.conditionGtPercent / 100 : this.maxUsage;

heapAlertDefinition.conditions[0].thresholdLow = this.adm.heap.conditionLtEnabled ?
this.maxUsage * this.adm.heap.conditionLtPercent / 100 : 0;

// Actual save of the alert definition
this.HawkularAlertsManager.saveAlertDefinition(heapAlertDefinition, errorCallback,
this.triggerDefinition.heap).finally(()=> {

this.saveProgress = false;

if(!isError) {
// notify success
this.$rootScope.hkNotifications.alerts.push({
type: 'success',
message: 'Changes saved successfully.'
});
}

this.cancel();
});
}

public alertSettingTouch(): void {
Expand All @@ -332,4 +315,3 @@ module HawkularMetrics {

_module.controller('JvmAlertSetupController', JvmAlertSetupController);
}

0 comments on commit 77410f2

Please sign in to comment.