1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.swingmonitor;
22
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.util.HashMap;
26 import java.util.Iterator;
27
28 import net.sf.jour.statistic.Accumulation;
29 import net.sf.jour.statistic.MillisecondsPeriod;
30 import net.sf.jour.statistic.TimeBaseAccumulationList;
31
32 import org.apache.log4j.Logger;
33 import org.jfree.chart.ChartFactory;
34 import org.jfree.chart.ChartPanel;
35 import org.jfree.chart.JFreeChart;
36 import org.jfree.data.time.TimeSeries;
37 import org.jfree.data.time.TimeSeriesCollection;
38
39 /***
40 * TODO Add docs
41 *
42 * Created on 15.12.2004
43 * Contributing Author(s):
44 *
45 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
46 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
47 *
48 * @author vlads
49 * @version $Revision: 1.1 $ ($Author: vlads $) $Date: 2004/12/16 05:35:51 $
50 */
51 public class JVMRuntimeChartPanel extends MonitoringJPanel {
52
53 protected static final Logger log = Logger.getLogger(JVMRuntimeChartPanel.class);
54
55 private JMVRuntimeStatistics jvms;
56
57 private HashMap hostTimeSeries = new HashMap();
58
59 private TimeSeriesCollection timeseriescollection;
60
61 public JVMRuntimeChartPanel(JMVRuntimeStatistics jvms) {
62 setLayout(new BorderLayout());
63
64 this.jvms = jvms;
65
66 createChart();
67 updateData();
68 }
69
70 public boolean canCloseTab() {
71 return false;
72 }
73
74 public void updateData() {
75 Iterator iter = this.jvms.getHostsJVM().iterator();
76 while (iter.hasNext()) {
77 TimeBaseAccumulationList j = (TimeBaseAccumulationList) iter.next();
78 String host = (String)j.getAttribute(JMVRuntimeStatistics.ATTRIBUTE_HOST_NAME);
79 TimeSeries series = timeseriescollection.getSeries(host);
80
81 if (series == null) {
82 series = new TimeSeries(host, MillisecondsPeriod.class);
83 timeseriescollection.addSeries(series);
84 } else {
85 series.clear();
86 }
87
88 for (Iterator i = j.getKeys().iterator(); i.hasNext();) {
89 Object time = i.next();
90 Accumulation acc = j.getItem(time);
91 long mem = new Double(acc.getMean() / (1024 * 1024)).longValue();
92 MillisecondsPeriod p = j.getPeriod(time);
93 series.add(p, new Long(mem));
94 }
95 }
96 }
97
98 protected void createChart() {
99 timeseriescollection = new TimeSeriesCollection();
100 JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("JVM Runtime", "Time", "Memory usage (MB)", timeseriescollection, true, true, false);
101 jfreechart.setBackgroundPaint(Color.white);
102 ChartPanel chartpanel = new ChartPanel(jfreechart);
103 chartpanel.setMouseZoomable(true, false);
104 add(chartpanel);
105 }
106
107 }