public static void takeSnapshot(MasterRemoteControl mrc) {
// ensure that there is a 'monitoring' directory
ensureMonitorDir();
// get any saved mbean names from snapshot-config.xml
ArrayList< String > mbeanNames = SnapshotConfigXMLBuilder.getMBeanNames();
// in the case where nothing is present, grab a set of default mbeans
if(mbeanNames.size() < = 0) {
mbeanNames = getDefaultMBeanList(mrc);
}
// turn on all stats in the list
setStatsOn(mbeanNames, mrc);
try {
// take a snapshot
log.info("======SNAPSHOT======");
// instantiate map < mbean name, stats for mbean >
HashMap< String, HashMap< String, Long > > aggregateStats = new HashMap< String, HashMap< String, Long > >();
// for each mbean name in the list, get its stats
for (String mbeanName : mbeanNames) {
HashMap< String, Long > stats = mrc.getStats(mbeanName);
aggregateStats.put(mbeanName, stats);
}
// store the data in a DB
(new SnapshotDBHelper()).addSnapshotToDB(aggregateStats);
for (String mbean : aggregateStats.keySet()) {
HashMap< String, Long > stats = aggregateStats.get(mbean);
log.info(mbean);
for (String key : stats.keySet()) {
Long value = stats.get(key);
log.info(key + ": " + value);
}
}
} catch(Exception e) {
log.error(e.getMessage(), e);
}
}
Collects JSR-77 statistics for all mbeans that have been chosen to
be monitored and stores it in a DB. Will also, archive snapshots
if they have passed their retention period. |