| 1 |
/* |
| 2 |
* Copyright 2009-2013 Roland Huss |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
var j4p = new Jolokia({url: "http://jolokia.org/jolokia", fetchInterval: 1000}); |
| 18 |
|
| 19 |
var context = cubism.context() |
| 20 |
.serverDelay(0) |
| 21 |
.clientDelay(0) |
| 22 |
.step(1000) |
| 23 |
.size(594); |
| 24 |
var jolokia = context.jolokia(j4p); |
| 25 |
|
| 26 |
// ============================================================================= |
| 27 |
// Various metrics used |
| 28 |
|
| 29 |
var memory = jolokia.metric( |
| 30 |
function (resp1, resp2) { |
| 31 |
return Number(resp1.value) / Number(resp2.value); |
| 32 |
}, |
| 33 |
{type:"read", mbean:"java.lang:type=Memory", attribute:"HeapMemoryUsage", path:"used"}, |
| 34 |
{type:"read", mbean:"java.lang:type=Memory", attribute:"HeapMemoryUsage", path:"max"}, "Heap-Memory" |
| 35 |
); |
| 36 |
var gcCount = jolokia.metric( |
| 37 |
{type:"read", mbean:"java.lang:name=PS MarkSweep,type=GarbageCollector", attribute:"CollectionCount"}, |
| 38 |
{delta:1000, name:"GC Old"} |
| 39 |
); |
| 40 |
var gcCount2 = jolokia.metric( |
| 41 |
{type:"read", mbean:"java.lang:name=PS Scavenge,type=GarbageCollector", attribute:"CollectionCount"}, |
| 42 |
{delta:1000, name:"GC Young"} |
| 43 |
); |
| 44 |
|
| 45 |
var agentRequest = jolokia.metric( |
| 46 |
{type: "read", mbean:"Jolokia:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/jolokia,j2eeType=Servlet,name=jolokia-agent", |
| 47 |
attribute:"requestCount"}, {name:"Jolokia", delta:10 * 1000}); |
| 48 |
var jenkinsRequest = jolokia.metric( |
| 49 |
{type: "read", mbean:"Catalina:J2EEApplication=none,J2EEServer=none,WebModule=//localhost/jenkins,j2eeType=Servlet,name=Stapler", |
| 50 |
attribute:"requestCount"}, {name:"Jenkins", delta:10 * 1000}); |
| 51 |
var allRequests = jolokia.metric( |
| 52 |
function (resp) { |
| 53 |
var attrs = resp.value; |
| 54 |
var sum = 0; |
| 55 |
for (var key in attrs) { |
| 56 |
sum += attrs[key].requestCount; |
| 57 |
} |
| 58 |
return sum; |
| 59 |
}, |
| 60 |
{type: "read", mbean:"Catalina:j2eeType=Servlet,*", |
| 61 |
attribute:"requestCount"}, {name:"All", delta:10 * 1000}); |
| 62 |
|
| 63 |
//j4p.start(1000); |
| 64 |
|
| 65 |
var colorsRed = ["#FDBE85", "#FEEDDE", "#FD8D3C", "#E6550D", "#A63603", "#FDBE85", "#FEEDDE", "#FD8D3C", "#E6550D", "#A63603" ], |
| 66 |
colorsGreen = [ "#E5F5F9", "#99D8C9", "#2CA25F", "#E5F5F9", "#99D8C9", "#2CA25F"], |
| 67 |
colorsBlue = [ "#ECE7F2", "#A6BDDB", "#2B8CBE", "#ECE7F2", "#A6BDDB", "#2B8CBE"]; |
| 68 |
|
| 69 |
// Created graphs |
| 70 |
$(function () { |
| 71 |
d3.select("#memory").call(function (div) { |
| 72 |
|
| 73 |
div.append("div") |
| 74 |
.attr("class", "axis") |
| 75 |
.call(context.axis().orient("top")); |
| 76 |
|
| 77 |
div.selectAll(".horizon") |
| 78 |
.data([memory]) |
| 79 |
.enter().append("div") |
| 80 |
.attr("class", "horizon") |
| 81 |
.call( |
| 82 |
context.horizon() |
| 83 |
.colors(colorsRed) |
| 84 |
.format(d3.format(".4p")) |
| 85 |
); |
| 86 |
div.selectAll(".horizon-gc") |
| 87 |
.data([gcCount2, gcCount]) |
| 88 |
.enter().append("div") |
| 89 |
.attr("class", "horizon horizon-gc") |
| 90 |
.call( |
| 91 |
context.horizon().colors(colorsRed).height(10) |
| 92 |
); |
| 93 |
div.append("div") |
| 94 |
.attr("class", "rule") |
| 95 |
.call(context.rule()); |
| 96 |
|
| 97 |
}); |
| 98 |
|
| 99 |
d3.select("#request").call(function (div) { |
| 100 |
|
| 101 |
div.append("div") |
| 102 |
.attr("class", "axis") |
| 103 |
.call(context.axis().orient("top")); |
| 104 |
|
| 105 |
|
| 106 |
div.selectAll(".horizon") |
| 107 |
.data([agentRequest, jenkinsRequest, allRequests]) |
| 108 |
.enter() |
| 109 |
.append("div") |
| 110 |
.attr("class", "horizon") |
| 111 |
.call(context.horizon() |
| 112 |
.format(d3.format("10d")) |
| 113 |
.colors(function (d, i) { |
| 114 |
return i == 3 ? colorsBlue : colorsGreen |
| 115 |
})); |
| 116 |
|
| 117 |
div.append("div") |
| 118 |
.attr("class", "rule") |
| 119 |
.call(context.rule()); |
| 120 |
|
| 121 |
}); |
| 122 |
|
| 123 |
// On mousemove, reposition the chart values to match the rule. |
| 124 |
context.on("focus", function (i) { |
| 125 |
d3.selectAll("#memory .value").style("right", i == null ? null : context.size() - i + "px"); |
| 126 |
d3.selectAll("#request .value").style("right", i == null ? null : context.size() - i + "px"); |
| 127 |
}); |
| 128 |
|
| 129 |
}); |
| 130 |
|
| 131 |
function gc() { |
| 132 |
j4p.request({type:"exec", mbean:"java.lang:type=Memory", operation:"gc"}) |
| 133 |
} |