geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akulshresh...@apache.org
Subject svn commit: r586231 - 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/
Date Fri, 19 Oct 2007 02:21:27 GMT
Author: akulshreshtha
Date: Thu Oct 18 19:21:26 2007
New Revision: 586231

URL: http://svn.apache.org/viewvc?rev=586231&view=rev
Log:
GERONIMO-3537 Monitoring Plugin : 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/MasterRemoteControl.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/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=586231&r1=586230&r2=586231&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 Thu
Oct 18 19:21:26 2007
@@ -22,10 +22,10 @@
             <connection-definition>
                 <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                 <connectiondefinition-instance>
-                    <name>ActiveDBPool</name>
+                    <name>ActiveDS</name>
                     <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:ActiveDB;create=true</config-property-setting>
+                    <config-property-setting name="ConnectionURL">jdbc:derby:ActiveMRCDB;create=true</config-property-setting>
                     <connectionmanager>
                         <local-transaction/>
                         <single-pool>
@@ -41,9 +41,9 @@
             <connection-definition>
                 <connectionfactory-interface>javax.sql.DataSource</connectionfactory-interface>
                 <connectiondefinition-instance>
-                    <name>ArchiveDBPool</name>
+                    <name>ArchiveDS</name>
                     <config-property-setting name="Password">monitor</config-property-setting>
-                    <config-property-setting name="ConnectionURL">jdbc:derby:ArchiveDB;create=true</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>
                     <connectionmanager>
                         <local-transaction/>

Modified: geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java?rev=586231&r1=586230&r2=586231&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
(original)
+++ geronimo/sandbox/monitoring/mrc-server/mrc-ejb/src/main/java/org/apache/geronimo/monitor/MasterRemoteControl.java
Thu Oct 18 19:21:26 2007
@@ -16,12 +16,21 @@
  */
 package org.apache.geronimo.monitor;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.SQLException;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
 
+import javax.annotation.Resource;
 import javax.annotation.security.RolesAllowed;
 import javax.annotation.security.RunAs;
 import javax.ejb.Remote;
@@ -85,6 +94,8 @@
     // use this to call utility functions pertaining to mbeans
     private static MBeanHelper mbeanHelper;
 
+    @Resource(name="ActiveDS") private DataSource ds;
+
     public MasterRemoteControl() {
         // retrieve the mbean server
         ArrayList mbServerList = MBeanServerFactory.findMBeanServer(null);
@@ -104,6 +115,56 @@
         }
         // instantiate teh mbean helper to query mbean names
         mbeanHelper = new MBeanHelper();
+
+        // set up databases
+        setUpDatabase();
+
+        if(ds == null) {
+            System.out.println("DataSource is NOT GOOD");
+        } else {
+            System.out.println("DataSource is GOOD");
+        }
+
+    }
+
+    private void setUpDatabase() {
+        try {
+            // TODO: 
+            //      Use a DataSource instead.
+            Connection conn = DriverManager.getConnection("jdbc:derby:ActiveMRCDB;create=true",
"monitor", "monitor");
+            Statement stmt = conn.createStatement();
+            try {
+                // fetch all tables in the db
+                ResultSet allTablesResult = stmt.executeQuery("SELECT t.tablename FROM SYS.SYSTABLES
t WHERE t.tablename NOT LIKE 'SYS%'");
+                boolean hasTables = false;
+                // determine if there are any tables in the db
+                while(allTablesResult.next()) {
+                    hasTables = true;
+                    break;
+                }
+                // create the tables if there aren't any tables in the db
+                if( !hasTables ) {
+                    createTables(stmt);
+                }
+            } catch(Exception e) {
+                e.printStackTrace();
+            }
+        } catch(SQLException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void createTables(Statement stmt) {
+        try {
+            String tableStatisticsCreate = "CREATE TABLE Statistics( id BIGINT NOT NULL GENERATED
ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), mbeanId INT NOT NULL, statsValue BIGINT
NOT NULL, statsName VARCHAR(100) NOT NULL, snapshot_time VARCHAR(20) NOT NULL, snapshot_date
DATE NOT NULL, PRIMARY KEY(id))";
+            String tableMBeanCreate = "CREATE TABLE MBeans( id INT NOT NULL GENERATED ALWAYS
AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(256) NOT NULL, PRIMARY KEY(id) )";
+            stmt.executeUpdate(tableMBeanCreate);
+            System.out.println("MBean Table Created");
+            stmt.executeUpdate(tableStatisticsCreate);
+            System.out.println("Statistics Table Created");
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
     }
 
     @RolesAllowed("mejbadmin")
@@ -116,6 +177,10 @@
 
             ManagementHome mejbHome = (ManagementHome)ctx.lookup("ejb/mgmt/MEJBRemoteHome");
             mejb = mejbHome.create();
+
+            // start the snapshot process
+            startSnapshot(DEFAULT_DURATION);
+
             // Uncomment to see if mejb is working well
             //System.out.println("SUCCESS!");
             //System.out.println("MEJB Default Domain: " + mejb.getDefaultDomain());
@@ -201,9 +266,9 @@
     public boolean startSnapshot(Long interval) {
         if((snapshotThread == null || (snapshotThread != null && !snapshotThread.isAlive()))
&&
                 interval.longValue() > 0) {
-            saveDuration(interval.longValue());
-            snapshotThread = new SnapshotThread(interval.longValue(), mbServer);
+            snapshotThread = new SnapshotThread(interval.longValue(), mbServer, getStatisticsProviderMBeanNames());
             snapshotThread.start();
+            saveDuration(interval.longValue());
             return true;
         } else {
             System.out.println("There is already a snapshot thread running; Duration: " +
interval.longValue());

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=586231&r1=586230&r2=586231&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
Thu Oct 18 19:21:26 2007
@@ -44,10 +44,21 @@
 import javax.management.j2ee.Management;
 
 public class SMP {
-    private static final String PATH = "geronimo:ServiceModule=org.apache.geronimo.monitor/MRC/1.0/car,J2EEServer=geronimo,name=MasterRemoteControl,j2eeType=GBean";
-    
+    private static String PATH = "";
     public static void main(String[] args) {
         try {
+            Properties props = new Properties();
+            props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.RemoteInitialContextFactory");
+            props.setProperty(Context.PROVIDER_URL, "127.0.0.1:4201");
+            props.setProperty(Context.SECURITY_PRINCIPAL, "system");
+            props.setProperty(Context.SECURITY_CREDENTIALS, "manager");
+            props.setProperty("openejb.authentication.realmName", "geronimo-admin");
+            Context ic = new InitialContext(props);
+            System.out.println("Success: Initialized InitialContext");
+            MasterRemoteControlRemote mrc = (MasterRemoteControlRemote)ic.lookup("ejb/mgmt/MRCRemote");
+            System.out.println("Success: look up MRCRemote");
+            mrc.setUpMEJB();
+            System.out.println("Success: setUpMEJB");
         /*
             JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/JMXConnector");
             Hashtable env = new Hashtable();
@@ -94,24 +105,29 @@
 //            testGetStatsAttr(mbServerConn);
             */
 //            MasterRemoteControl mrc;
-            Properties props = new Properties();
-            props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.RemoteInitialContextFactory");
-            props.setProperty(Context.PROVIDER_URL, "127.0.0.1:4201");
-            props.setProperty(Context.SECURITY_PRINCIPAL, "system");
-            props.setProperty(Context.SECURITY_CREDENTIALS, "manager");
-            props.setProperty("openejb.authentication.realmName", "geronimo-admin");
-            Context ic = new InitialContext(props);
-            System.out.println("Success: Initialized InitialContext");
-            MasterRemoteControlRemote o = (MasterRemoteControlRemote)ic.lookup("ejb/mgmt/MRCRemote");
-            System.out.println("Success: look up MRCRemote");
-            o.setUpMEJB();
-            System.out.println("Success: setUpMEJB");
-            //nagementHome o = (ManagementHome)ic.lookup("ejb/mgmt/MEJBRemoteHome");
-            //Management m = o.create();
-            System.out.println(o);
             //System.out.println(m.getDefaultDomain());
+            testPrintStatisticsProviderMBeans(mrc);
+            testPrintStats(mrc);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    private static void testPrintStats(MasterRemoteControlRemote mrc) {
+        String mbeanName = "geronimo:J2EEServer=geronimo,ServiceModule=org.apache.geronimo.configs/tomcat6/2.1-SNAPSHOT/car,j2eeType=GBean,name=TomcatWebConnector";
+        try {
+            HashMap stats = mrc.getStats(mbeanName);
+            printStats(stats);
         } catch (Exception e) {
             e.printStackTrace();
+        }
+    }
+
+    private static void testPrintStatisticsProviderMBeans(MasterRemoteControlRemote mrc)
{
+        Set<ObjectName> list = mrc.getStatisticsProviderMBeanNames();
+        for(Iterator<ObjectName> it = list.iterator(); it.hasNext(); ) {
+            String mbeanName = it.next().getCanonicalName();
+            System.out.println(mbeanName);
         }
     }
     

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=586231&r1=586230&r2=586231&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
Thu Oct 18 19:21:26 2007
@@ -20,15 +20,18 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Properties;
 import java.util.Set;
 
+import javax.naming.Context;
+import javax.naming.InitialContext;
 import javax.management.j2ee.Management;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
 import org.apache.geronimo.monitor.snapshot.SnapshotXMLBuilder;
-import org.apache.geronimo.monitor.MasterRemoteControl;
+import org.apache.geronimo.monitor.MasterRemoteControlRemote;
 
 /**
  * Thread that is in charge of executing every x milliseconds. Upon each
@@ -39,17 +42,19 @@
     private long SNAPSHOT_DURATION;
     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;
     
     private boolean end = false;
     
-    public SnapshotThread(long snapshot_length, MBeanServer mbServer) {
+    public SnapshotThread(long snapshot_length, MBeanServer mbServer, Set<ObjectName>
allMBeans) {
         SNAPSHOT_DURATION = snapshot_length;
         this.mbServer = mbServer;
         snapshotXMLBuilder = new SnapshotXMLBuilder();
         snapshotXMLBuilder.checkXMLExists();
         mbeanNames = new ArrayList<String>();
+        this.allMBeans = allMBeans;
     }
     
     /**
@@ -115,10 +120,11 @@
                 System.out.println("======SNAPSHOT======");
                 // instantiate map <mbean name, stats for mbean>
                 HashMap<String, HashMap> aggregateStats = new HashMap<String, HashMap>();
+                MasterRemoteControlRemote mrc = getMRC();
                 // for each mbean name in the list, get its stats
                 for(int i = 0; i < mbeanNames.size(); i++) {
                     String mbeanName = mbeanNames.get(i);
-                    HashMap stats = (HashMap)MasterRemoteControl.getStats(mbeanName);
+                    HashMap stats = (HashMap)mrc.getStats(mbeanName);
                     aggregateStats.put(mbeanName, stats);
                 }
                 // store the data
@@ -142,6 +148,7 @@
                 Thread.sleep(SNAPSHOT_DURATION);
             } catch(Exception e) {
                 e.printStackTrace();
+                break;
             }
         }
         System.out.println("Thread is stopped.");
@@ -153,7 +160,7 @@
      * @param mbeanList
      */
     private void setStatsOn(ArrayList<String> mbeanList) {
-        Management mejb = MasterRemoteControl.getMEJB();
+        MasterRemoteControlRemote mrc = getMRC();
         // for each mbean name in the list
         for(int i = 0; i < mbeanList.size(); i++) {
             // turn the statistics collection on
@@ -162,8 +169,8 @@
             String[] signatures = new String[] { "java.lang.Boolean" };
             try {
                 ObjectName objName = new ObjectName(mbeanList.get(i));
-                mejb.invoke(objName, methodName, params, signatures);
-                System.out.println("Stats for " + mbeanList.get(i) + " was turned on.");
+                //mejb.invoke(objName, methodName, params, signatures);
+                //System.out.println("Stats for " + mbeanList.get(i) + " was turned on.");
             } catch(MalformedObjectNameException e) {
                 e.printStackTrace();
             } catch(Exception e) {
@@ -177,16 +184,16 @@
     /**
      * @return A list of all default mbeans; namely, all connector or container mbean names
      * Prereq: in order to be a connector or container mbean the name must contain "Connector"/"Container"

-     * and "Tomcat"/"Jetty"
+     * and "Tomcat"/"Jetty" or JVM.
      */
     private ArrayList<String> getDefaultMBeanList() {
-        Set<ObjectName> mbeans = (new MasterRemoteControl()).getStatisticsProviderMBeanNames();
+        Set<ObjectName> mbeans = allMBeans;
         ArrayList<String> retval = new ArrayList<String>();
         for(Iterator it = mbeans.iterator(); it.hasNext(); ) {
             String name = ((ObjectName)it.next()).getCanonicalName();
-            if((name.contains("Connector") || name.contains("Container")) &&
-                    (name.contains("Jetty") || name.contains("Tomcat"))) {
-                // this is a connector, so add to the list
+            if(((name.contains("Connector") || name.contains("Container")) && (name.contains("Jetty")
|| name.contains("Tomcat")))
+                                || name.contains("JVM")) {
+                // this is a connector or JVM, so add to the list
                 retval.add(name);
                 // update the snapshot-config.xml to include these
                 SnapshotConfigXMLBuilder.addMBeanName(name);
@@ -210,6 +217,7 @@
             // make a directory
             if(dir.mkdir()) {
                 // directory was successfully created
+                System.out.println("[INFO] /var/monitoring direction created.");
                 return;
             } else {
                 System.out.println("Could not make the directory " + pathToDir);
@@ -219,5 +227,21 @@
     
     public boolean getEnd() {
         return end;
+    }
+
+    public MasterRemoteControlRemote getMRC() {
+        Properties props = new Properties();
+        props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.RemoteInitialContextFactory");
+        props.setProperty(Context.PROVIDER_URL, "127.0.0.1:4201");
+        props.setProperty(Context.SECURITY_PRINCIPAL, "system");
+        props.setProperty(Context.SECURITY_CREDENTIALS, "manager");
+        props.setProperty("openejb.authentication.realmName", "geronimo-admin");
+        try {
+            Context ic = new InitialContext(props);
+            MasterRemoteControlRemote mrc = (MasterRemoteControlRemote)ic.lookup("ejb/mgmt/MRCRemote");
+            return mrc;
+        } catch(Exception e) {
+            return null;
+        }
     }
 }



Mime
View raw message