Skip to content

Commit

Permalink
Add a little jmx widget repository and define types so that we can de…
Browse files Browse the repository at this point in the history
…fine potential dashboard widgets for JMX attributes
  • Loading branch information
gashcrumb committed Sep 20, 2013
1 parent ab231f4 commit 20c969e
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 3 deletions.
63 changes: 61 additions & 2 deletions hawtio-web/src/main/webapp/app/jmx/js/attributes.ts
@@ -1,7 +1,8 @@
module Jmx {

export var propertiesColumnDefs = [
{field: 'name', displayName: 'Property', width: "27%"},
{field: 'name', displayName: 'Property', width: "27%",
cellTemplate: '<div class="ngCellText"><div class="inline" compile="getDashboardWidgets(row.entity)"></div>{{row.entity.name}}</div>'},
{field: 'value', displayName: 'Value', width: "70%",
cellTemplate: '<div class="ngCellText" ng-click="openDetailView(row.entity)" ng-bind-html-unsafe="row.entity.summary"></div>'
}
Expand All @@ -12,7 +13,7 @@ module Jmx {
cellTemplate: '<div class="ngCellText"><a href="{{folderHref(row)}}"><i class="{{folderIconClass(row)}}"></i> {{row.getProperty("title")}}</a></div>'
}];

export function AttributesController($scope, $location, workspace:Workspace, jolokia) {
export function AttributesController($scope, $location, workspace:Workspace, jolokia, jmxWidgets, jmxWidgetTypes) {
$scope.searchText = '';
$scope.columnDefs = [];
$scope.selectedItems = [];
Expand Down Expand Up @@ -51,6 +52,64 @@ module Jmx {
updateTableContents();
});

$scope.hasWidget = (row) => {
console.log("Row: ", row);
return true;
};

$scope.getDashboardWidgets = (row) => {
var mbean = workspace.getSelectedMBeanName();
if (!mbean) {
return '';
}
var potentialCandidates = jmxWidgets.filter((widget) => {
return mbean === widget.mbean;
});

if (potentialCandidates.isEmpty()) {
return '';
}

potentialCandidates = potentialCandidates.filter((widget) => {
return widget.attribute === row.key || widget.total === row.key;
});

if (potentialCandidates.isEmpty()) {
return '';
}

var rc = [];
potentialCandidates.forEach((widget) => {
var widgetType = Jmx.getWidgetType(widget);
rc.push("<i class=\"" + widgetType.icon + " clickable\" title=\"" + widgetType.title + "\" ng-click=\"addChartToDashboard(row.entity, '" + widgetType.type + "')\"></i>");

});
return rc.join() + "&nbsp;";
};

$scope.addChartToDashboard = (row, widgetType) => {
var mbean = workspace.getSelectedMBeanName();
var candidates = jmxWidgets.filter((widget) => {
return mbean === widget.mbean;
});

candidates = candidates.filter((widget) => {
return widget.attribute === row.key || widget.total === row.key;
});

candidates = candidates.filter((widget) => {
return widget.type === widgetType;
});

// hmmm, we really should only have one result...
var widget = candidates.first();
var type = getWidgetType(widget);

//console.log("widgetType: ", type, " widget: ", widget);

$location.url(Jmx.createDashboardLink(type, widget));
};

/**
* Returns the toolBar template HTML to use for the current selection
*/
Expand Down
7 changes: 6 additions & 1 deletion hawtio-web/src/main/webapp/app/jmx/js/jmxPlugin.ts
Expand Up @@ -13,7 +13,12 @@ module Jmx {
factory('jmxTreeLazyLoadRegistry',function () {
return Jmx.lazyLoaders;
}).

factory('jmxWidgetTypes', () => {
return Jmx.jmxWidgetTypes;
}).
factory('jmxWidgets', () => {
return Jmx.jmxWidgets;
}).
run(($location: ng.ILocationService, workspace:Workspace, viewRegistry, layoutTree, jolokia, pageTitle:Core.PageTitle) => {

viewRegistry['jmx'] = layoutTree;
Expand Down
84 changes: 84 additions & 0 deletions hawtio-web/src/main/webapp/app/jmx/js/widgetRepository.ts
@@ -0,0 +1,84 @@
module Jmx {

export function createDashboardLink(widgetType, widget) {
var href = "#" + widgetType.route;
var routeParams = angular.toJson(widget);
var title = widget.title;
var size = angular.toJson({
size_x: widgetType.size_x,
size_y: widgetType.size_y
});

return "/dashboard/add?tab=dashboard" +
"&href=" + encodeURIComponent(href) +
"&size=" + encodeURIComponent(size) +
"&title=" + encodeURIComponent(title) +
"&routeParams=" + encodeURIComponent(routeParams);
}

export function getWidgetType(widget) {
return jmxWidgetTypes.find((type) => {
return type.type === widget.type;
});
}

export var jmxWidgetTypes = [
{
type: "donut",
icon: "icon-smile",
route: "/jmx/widget/donut",
size_x: 1,
size_y: 1,
title: "Add Donut chart to Dashboard"
}
];

export var jmxWidgets = [
{
type: "donut",
title: "Java Heap Memory",
mbean: "java.lang:type=Memory",
attribute: "HeapMemoryUsage",
total: "Max",
terms: "Used"
},
{
type: "donut",
title: "Java Non Heap Memory",
mbean: "java.lang:type=Memory",
attribute: "NonHeapMemoryUsage",
total: "Max",
terms: "Used"
},
{
type: "donut",
title: "File Descriptor Usage",
mbean: "java.lang:type=OperatingSystem",
total: "MaxFileDescriptorCount",
terms: "OpenFileDescriptorCount"
},
{
type: "donut",
title: "Loaded Clases",
mbean: "java.lang:type=ClassLoading",
total: "TotalLoadedClassCount",
terms: "LoadedClassCount,UnloadedClassCount"
},
{
type: "donut",
title: "Free Memory",
mbean: "java.lang:type=OperatingSystem",
total: "TotalPhysicalMemorySize",
terms: "FreePhysicalMemorySize"
},
{
type: "donut",
title: "Swap Size",
mbean: "java.lang:type=OperatingSystem",
total: "TotalSwapSpaceSize",
terms: "FreeSwapSpaceSize"
}
];


}

0 comments on commit 20c969e

Please sign in to comment.