This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
jmx.js
157 lines (145 loc) · 3.58 KB
/
jmx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
$(document).ready(function() {
var factory = new JmxChartsFactory();
factory.create([
{
name: 'java.lang:type=Memory',
attribute: 'HeapMemoryUsage',
path: 'committed'
},
{
name: 'java.lang:type=Memory',
attribute: 'HeapMemoryUsage',
path: 'used'
}
]);
factory.create([
{
name: 'java.lang:type=OperatingSystem',
attribute: 'SystemLoadAverage'
}
]);
factory.create({
name: 'java.lang:type=Threading',
attribute: 'ThreadCount'
});
factory.create([
{
name: 'Catalina:name="http-bio-8080",type=ThreadPool',
attribute: 'currentThreadsBusy'
},
{
name: 'Catalina:name=executor,type=Executor',
attribute: 'queueSize'
}
]);
factory.create([
{
name: 'com.rayo:Type=Calls',
attribute: 'ActiveCallsCount'
},
{
name: 'com.rayo:Type=Calls',
attribute: 'ActiveVerbsCount'
}
]);
});
function JmxChartsFactory(keepHistorySec, pollInterval, columnsCount) {
var jolokia = new Jolokia("jolokia");
var series = [];
var monitoredMbeans = [];
var chartsCount = 0;
columnsCount = columnsCount || 3;
pollInterval = pollInterval || 1000;
var keepPoints = (keepHistorySec || 600) / (pollInterval / 1000);
setupPortletsContainer(columnsCount);
setInterval(function() {
pollAndUpdateCharts();
}, pollInterval);
this.create = function(mbeans) {
mbeans = $.makeArray(mbeans);
series = series.concat(createChart(mbeans).series);
monitoredMbeans = monitoredMbeans.concat(mbeans);
};
function pollAndUpdateCharts() {
var requests = prepareBatchRequest();
var responses = jolokia.request(requests);
updateCharts(responses);
}
function createNewPortlet(name) {
return $('#portlet-template')
.clone(true)
.appendTo($('.column')[chartsCount++ % columnsCount])
.removeAttr('id')
.find('.title').text((name.length > 50? '...' : '') + name.substring(name.length - 50, name.length)).end()
.find('.portlet-content')[0];
}
function setupPortletsContainer() {
var column = $('.column');
for(var i = 1; i < columnsCount; ++i){
column.clone().appendTo(column.parent());
}
$(".column").sortable({
connectWith: ".column"
});
$(".portlet-header .ui-icon").click(function() {
$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
$(this).parents(".portlet:first").find(".portlet-content").toggle();
});
$(".column").disableSelection();
}
function prepareBatchRequest() {
return $.map(monitoredMbeans, function(mbean) {
return {
type: "read",
mbean: mbean.name,
attribute: mbean.attribute,
path: mbean.path
};
});
}
function updateCharts(responses) {
var curChart = 0;
$.each(responses, function() {
var point = {
x: this.timestamp * 1000,
y: parseFloat(this.value)
};
var curSeries = series[curChart++];
curSeries.addPoint(point, true, curSeries.data.length >= keepPoints);
});
}
function createChart(mbeans) {
return new Highcharts.Chart({
chart: {
renderTo: createNewPortlet(mbeans[0].name),
animation: false,
defaultSeriesType: 'area',
shadow: false
},
title: { text: null },
xAxis: { type: 'datetime' },
yAxis: {
title: { text: mbeans[0].attribute }
},
legend: {
enabled: true,
borderWidth: 0
},
credits: {enabled: false},
exporting: { enabled: false },
plotOptions: {
area: {
marker: {
enabled: false
}
}
},
series: $.map(mbeans, function(mbean) {
return {
data: [],
name: mbean.path || mbean.attribute
}
})
})
}
}