// ensure that there is a 'monitoring' directory
SnapshotConfigXMLBuilder.ensureMonitorDir();
// get any saved mbean names from snapshot-config.xml
ArrayList<String> mbeanNames = SnapshotConfigXMLBuilder.getMBeanNames();
// get a handle on the mrc
MasterRemoteControlJMX mrc = getMRC(/*username, password*/);
// 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(int i = 0; i < mbeanNames.size(); i++) {
String mbeanName = mbeanNames.get(i);
HashMap<String, Long> stats = (HashMap<String, Long>)mrc.getStats(mbeanName);
aggregateStats.put(mbeanName, stats);
}
// store the data in a DB
(new SnapshotDBHelper()).addSnapshotToDB(aggregateStats);