You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ak...@apache.org on 2007/10/25 05:12:46 UTC
svn commit: r588121 - in /geronimo/sandbox/monitoring/mrc-server:
mrc-ear/src/main/resources/
mrc-ejb/src/main/java/org/apache/geronimo/monitor/
mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/
Author: akulshreshtha
Date: Wed Oct 24 20:12:43 2007
New Revision: 588121
URL: http://svn.apache.org/viewvc?rev=588121&view=rev
Log:
GERONIMO-3535 Monitoring Plugin : Use DataSource, Patch by Viet H. Nguyen
Modified:
geronimo/sandbox/monitoring/mrc-server/mrc-ear/src/main/resources/MonitorDBPool.xml
geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControlRemote.java
geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotConfigXMLBuilder.java
geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotDBHelper.java
geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ear/src/main/resources/MonitorDBPool.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ear/src/main/resources/MonitorDBPool.xml?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ear/src/main/resources/MonitorDBPool.xml (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ear/src/main/resources/MonitorDBPool.xml Wed Oct 24 20:12:43 2007
@@ -23,6 +23,7 @@
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
<connectiondefinition-instance>
<name>ActiveDS</name>
+ <config-property-setting name="Driver">org.apache.derby.jdbc.EmbeddedDriver</config-property-setting>
<config-property-setting name="Password">monitor</config-property-setting>
<config-property-setting name="UserName">monitor</config-property-setting>
<config-property-setting name="ConnectionURL">jdbc:derby:ActiveMRCDB;create=true</config-property-setting>
@@ -42,6 +43,7 @@
<connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
<connectiondefinition-instance>
<name>ArchiveDS</name>
+ <config-property-setting name="Driver">org.apache.derby.jdbc.EmbeddedDriver</config-property-setting>
<config-property-setting name="Password">monitor</config-property-setting>
<config-property-setting name="ConnectionURL">jdbc:derby:ArchiveMRCDB;create=true</config-property-setting>
<config-property-setting name="UserName">monitor</config-property-setting>
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControlRemote.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControlRemote.java?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControlRemote.java (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControlRemote.java Wed Oct 24 20:12:43 2007
@@ -32,44 +32,44 @@
*/
@Remote
public interface MasterRemoteControlRemote {
-
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public HashMap getStats(String s) throws Exception;
@RolesAllowed("mejbadmin")
public void setAttribute(String s, String ss, Object o) throws Exception;
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public boolean startSnapshot(Long l);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public boolean stopSnapshot();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public ArrayList fetchSnapshotData(Integer i, Integer ii);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public HashMap fetchMaxSnapshotData(Integer i);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public HashMap fetchMinSnapshotData(Integer i);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public Long getSnapshotDuration();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public Long getSnapshotCount();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public void setSnapshotDuration(Long l);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public Set getStatisticsProviderMBeanNames();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public Set getAllMBeanNames();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public HashMap getAllSnapshotStatAttributes();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public void addMBeanForSnapshot(String s);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public void removeMBeanForSnapshot(String s);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public boolean isSnapshotRunning();
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public void setUpMEJB(String username, String password);
@RolesAllowed("mejbadmin")
public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature);
- @RolesAllowed("mejbadmin")
+ @RolesAllowed("mejbuser")
public TreeMap<Long, Long> getSpecificStatistics(String mbeanName, String statsName, int numberOfSnapshots, int everyNthSnapshot);
-
+ @RolesAllowed("mejbuser")
+ public Set getTrackedMBeans();
}
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/SMP.java Wed Oct 24 20:12:43 2007
@@ -61,6 +61,7 @@
MasterRemoteControlRemote mrc = (MasterRemoteControlRemote)ic.lookup("ejb/mgmt/MRCRemote");
System.out.println("Success: look up MRCRemote");
mrc.setUpMEJB(username, password);
+ mrc.startSnapshot(new Long(300000));
System.out.println("Success: setUpMEJB");
/*
JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/JMXConnector");
@@ -110,15 +111,23 @@
// MasterRemoteControl mrc;
//System.out.println(m.getDefaultDomain());
testPrintStatisticsProviderMBeans(mrc);
-// testPrintStats(mrc);
+ testPrintStats(mrc);
testFetchSnapshot(mrc, 2, 2);
testFetchMinSnapshot(mrc, 2);
testFetchMaxSnapshot(mrc, 2);
testFetchSnapshotCount(mrc);
testGetAllSnapshotAttributes(mrc);
testGetSpecificStats(mrc, "geronimo:J2EEServer=geronimo,j2eeType=JVM,name=JVM", "JVM Heap Size Current", 5, 2);
+ testGetMBeansTracked(mrc);
} catch (Exception e) {
e.printStackTrace();
+ }
+ }
+
+ private static void testGetMBeansTracked(MasterRemoteControlRemote mrc) {
+ Set<String> set = mrc.getTrackedMBeans();
+ for(Iterator it = set.iterator(); it.hasNext(); ) {
+ System.out.println((String)it.next());
}
}
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotConfigXMLBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotConfigXMLBuilder.java?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotConfigXMLBuilder.java (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotConfigXMLBuilder.java Wed Oct 24 20:12:43 2007
@@ -43,6 +43,7 @@
private static final String SNAPSHOT_CONFIG = "snapshot-config";
private static final String DURATION = "duration";
+ private static final String RETENTION = "retention";
private static final String MBEAN = "mbean";
/**
@@ -114,6 +115,11 @@
mbeanElement.setTextContent(mbeanName);
// add <mbean> element to the rootElement
rootElement.appendChild(mbeanElement);
+ try {
+ Thread.sleep(1000);
+ } catch(Exception e) {
+
+ }
// save the document
saveDocument(doc, pathToXML);
}
@@ -123,33 +129,52 @@
* Saves the duration of the snapshot as a configuration attribute
* @param duration
*/
- public static void save(long duration) {
+ public static void saveDuration(long duration) {
+ saveAttribute(DURATION, duration);
+ }
+
+ /**
+ * Saves the retention of the snapshot as a configuration attribute
+ * @param retention
+ */
+ public static void saveRetention(int retention) {
+ saveAttribute(RETENTION, retention);
+ }
+
+ /**
+ * Saves a generic attribute value into the node with text = attribute name.
+ * Creates one if there is not an instance of one.
+ * @param attrName
+ * @param attributeValue
+ */
+ private static void saveAttribute(String attrName, long attributeValue) {
Document doc = openDocument();
// get the root node
Element rootElement = doc.getDocumentElement();
// get all children in the root node (i.e. all config properties)
NodeList configNodes = rootElement.getChildNodes();
// find the duration node and save it
- boolean foundDurationNode = false;
- for(int i = 0; i < configNodes.getLength() && !foundDurationNode; i++) {
+ boolean foundNode = false;
+ for(int i = 0; i < configNodes.getLength() && !foundNode; i++) {
Node configNode = configNodes.item(i);
- if(DURATION.equals(configNode.getNodeName())) {
+ if(attrName.equals(configNode.getNodeName())) {
// found a match
- configNode.setTextContent(duration + "");
- foundDurationNode = true;
+ configNode.setTextContent(attributeValue + "");
+ foundNode = true;
}
}
// if there was not a duration node, make one
- if(!foundDurationNode) {
- Element durationElement = doc.createElement(DURATION);
- durationElement.setTextContent(duration + "");
- rootElement.appendChild(durationElement);
+ if(!foundNode) {
+ Element element = doc.createElement(attrName);
+ element.setTextContent(attributeValue + "");
+ rootElement.appendChild(element);
}
try {
- Thread.sleep(10000);
+ Thread.sleep(1000);
} catch(Exception e) {
}
+ System.out.println("***saving: " + attrName + " = " + attributeValue);
// save the document to file
saveDocument(doc, pathToXML);
}
@@ -175,7 +200,7 @@
return configNodes.item(i).getTextContent();
}
}
- throw new Exception("[WARNING] " + key + " is no found in " + SNAPSHOT_CONFIG);
+ throw new Exception("[WARNING] " + key + " is not found in " + SNAPSHOT_CONFIG);
}
/**
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotDBHelper.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotDBHelper.java?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotDBHelper.java (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotDBHelper.java Wed Oct 24 20:12:43 2007
@@ -39,12 +39,15 @@
private static final String STATSNAME = "statsName";
// Connection object used for DB interaction
private static Connection conn = null;
+ // Data Sources
+ private static DataSource activeDS = null;
+ private static DataSource archiveDS = null;
/**
* @return A map: mbeanName --> ArrayList of statistic attributes for that mbean
*/
public static HashMap<String, ArrayList<String>> getAllSnapshotStatAttributes() {
- openConnection();
+ openActiveConnection();
HashMap<String, ArrayList<String>> retval = new HashMap<String, ArrayList<String>>();
try {
Statement stmt = conn.createStatement();
@@ -76,7 +79,7 @@
public static Long getSnapshotCount() {
long retval = 0;
try {
- openConnection();
+ openActiveConnection();
Statement stmt = conn.createStatement();
String query = "SELECT COUNT(DISTINCT snapshot_time) FROM Snapshots";
ResultSet rs = stmt.executeQuery(query);
@@ -112,6 +115,7 @@
* or max, depending on the isMax parameter.
*/
private static HashMap<String, HashMap<String, Long>> fetchMaxOrMinSnapshotData(Integer numberOfSnapshots, boolean isMax) {
+ openActiveConnection();
ResultSet snapshotTimeTable = fetchSnapshotTimesFromDB();
HashMap<String, HashMap<String, Long>> stats = new HashMap<String, HashMap<String, Long>>();
try {
@@ -170,11 +174,10 @@
* @return Returns a boolean if the snapshot statistics were successfully added
* to the DB.
*/
- public static boolean addSnapshotToDB( DataSource ds,
- HashMap<String, HashMap> aggregateStats) {
+ public static boolean addSnapshotToDB(HashMap<String, HashMap> aggregateStats) {
boolean success = true;
try {
- openConnection();
+ openActiveConnection();
Statement stmt = conn.createStatement();
// get the current date
@@ -226,6 +229,8 @@
closeConnection();
}
+
+
return success;
}
@@ -299,6 +304,7 @@
public static ArrayList<HashMap<String, HashMap<String, Object>>> fetchData(Integer numberOfSnapshot,
Integer everyNthSnapshot) {
ArrayList<HashMap<String, HashMap<String, Object>>> stats = new ArrayList<HashMap<String, HashMap<String, Object>>>();
+ openActiveConnection();
// get all records in the database grouped and ordered by time
ResultSet table = fetchSnapshotTimesFromDB();
// iterate through the table and finds the times (which uniquely IDs a snapshot)
@@ -338,6 +344,7 @@
*/
private static HashMap<String, HashMap<String, Object>> packageSnapshotData(Long snapshotTime) {
HashMap<String, HashMap<String, Object>> snapshotPkg = new HashMap<String, HashMap<String, Object>>();
+ openActiveConnection();
ResultSet snapshotData = fetchSnapshotDataFromDB(snapshotTime);
String snapshotDate = null;
try {
@@ -381,7 +388,6 @@
query += " AND S.snapshotId=SN.id AND S.mbeanId=M.id";
ResultSet retval = null;
try {
- openConnection();
Statement stmt = conn.createStatement();
retval = stmt.executeQuery(query);
} catch(Exception e) {
@@ -397,7 +403,6 @@
String query = "SELECT DISTINCT snapshot_time FROM Snapshots ORDER BY snapshot_time DESC";
ResultSet retval = null;
try {
- openConnection();
Statement stmt = conn.createStatement();
retval = stmt.executeQuery(query);
} catch(Exception e) {
@@ -407,25 +412,40 @@
}
/**
- * Opens the global connection to db
+ * Opens the global connection to activeDB
*/
- private static void openConnection() {
+ private static void openActiveConnection() {
try {
- conn = DriverManager.getConnection("jdbc:derby:ActiveMRCDB;create=true", "monitor", "monitor");
+ if(conn == null || conn.isClosed()) {
+ conn = activeDS.getConnection();
+ }
} catch(Exception e) {
e.printStackTrace();
}
}
/**
- * Closes teh global connection to DB
+ * Opens the global connection to archiveDB
+ */
+ private static void openArchiveConnection() {
+ try {
+ if(conn == null || conn.isClosed()) {
+ conn = archiveDS.getConnection();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Closes the global connection to a DB
*/
private static void closeConnection() {
if(conn != null) {
try {
conn.close();
} catch(Exception e) {
-// e.printStackTrace();
+ e.printStackTrace();
}
}
}
@@ -438,7 +458,7 @@
* @return HashMap which maps from a snapshot_time --> value of the mbean.statsName at that time
*/
public static TreeMap<Long, Long> getSpecificStatistics(String mbeanName, String statsName, int numberOfSnapshots, int everyNthSnapshot) {
- openConnection();
+ openActiveConnection();
TreeMap<Long, Long> stats = new TreeMap<Long, Long>();
try {
Statement stmt = conn.createStatement();
@@ -451,7 +471,6 @@
int nthSnapshot = 0;
// iterator through the table paying attention to those at everyNthSnapshot-th position
while(rs.next()) {
- System.out.println(nthSnapshot);
// every nth snapshot I save the information into my returning hashmap
if(nthSnapshot % everyNthSnapshot == 0) {
stats.put(rs.getLong(SNAPSHOT_TIME), rs.getLong(STATSVALUE));
@@ -471,5 +490,15 @@
closeConnection();
}
return stats;
+ }
+
+ /**
+ * Sets the necessary data sources for this helper to talk to the db
+ * @param activeDS
+ * @param archiveDS
+ */
+ public static void setDataSources(DataSource active, DataSource archive) {
+ activeDS = active;
+ archiveDS = archive;
}
}
Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java?rev=588121&r1=588120&r2=588121&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java (original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/snapshot/SnapshotThread.java Wed Oct 24 20:12:43 2007
@@ -25,6 +25,7 @@
import javax.naming.Context;
import javax.naming.InitialContext;
+import javax.sql.DataSource;
import javax.management.j2ee.Management;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
@@ -40,8 +41,8 @@
public class SnapshotThread extends Thread {
private long SNAPSHOT_DURATION;
+ private int SNAPSHOT_RETENTION;
private MBeanServer mbServer = null;
- private SnapshotXMLBuilder snapshotXMLBuilder = null;
private Set<ObjectName> allMBeans = null;
// list of mbean names that we will be taking snapshots of
private ArrayList<String> mbeanNames;
@@ -51,15 +52,19 @@
private boolean end = false;
- public SnapshotThread(long snapshot_length, MBeanServer mbServer, Set<ObjectName> allMBeans, final String username, final String password) {
+ public SnapshotThread( long snapshot_length,
+ int snapshot_retention,
+ MBeanServer mbServer,
+ Set<ObjectName> allMBeans,
+ final String username,
+ final String password) {
SNAPSHOT_DURATION = snapshot_length;
this.mbServer = mbServer;
- snapshotXMLBuilder = new SnapshotXMLBuilder();
- snapshotXMLBuilder.checkXMLExists();
- mbeanNames = new ArrayList<String>();
+ this.mbeanNames = new ArrayList<String>();
this.allMBeans = allMBeans;
this.username = username;
this.password = password;
+ SNAPSHOT_RETENTION = snapshot_retention;
}
/**
@@ -71,15 +76,28 @@
}
/**
- * Gets the elapsed time in milliseconds between each snapshot.
- *
- * @return long
+ * @return Gets the elapsed time in milliseconds between each snapshot.
*/
public long getSnapshotDuration() {
return SNAPSHOT_DURATION;
}
/**
+ * @return Gets the elapsed time in days before archiving
+ */
+ public int getSnapshotRetention() {
+ return SNAPSHOT_RETENTION;
+ }
+
+ /**
+ * Sets the elapsed time in days before archiving
+ * @param retention
+ */
+ public void setSnapshotRetention(int retention) {
+ SNAPSHOT_RETENTION = retention;
+ }
+
+ /**
* Adds the mbean name to list in memory. To update the snapshot-config.xml
* coder must use SnapshotConfigXMLBuilder class.
* @param mbeanName
@@ -132,13 +150,9 @@
HashMap stats = (HashMap)mrc.getStats(mbeanName);
aggregateStats.put(mbeanName, stats);
}
- // store the data in XML
- snapshotXMLBuilder.openDocument();
- snapshotXMLBuilder.addNewSnapshot(aggregateStats);
- snapshotXMLBuilder.saveDocument( snapshotXMLBuilder.getDocument() );
// store the data in a DB
- SnapshotDBHelper.addSnapshotToDB(null, aggregateStats);
+ SnapshotDBHelper.addSnapshotToDB(aggregateStats);
for(Iterator itt = aggregateStats.keySet().iterator(); itt.hasNext(); ) {
String mbean = (String)itt.next();
@@ -225,7 +239,7 @@
// make a directory
if(dir.mkdir()) {
// directory was successfully created
- System.out.println("[INFO] /var/monitoring direction created.");
+ System.out.println("[INFO] /var/monitoring directory created.");
return;
} else {
System.out.println("Could not make the directory " + pathToDir);