The following script can be used to export historical metrics from the Foglight Management Server (FMS) repository.
import java.sql.Timestamp;
/***********************************************************************************************/
/***************************** Please enter agent name *********************************/
/***********************************************************************************************/
agentName = "AGENTNAME";
/***********************************************************************************************/
/******************** Metric details should be in the format of: ************************/
/*************** ",;," **************/
/***********************************************************************************************/
StringBuilder metrics = new StringBuilder();
metrics.append("DBSS_Latches_Locks,lock_timeouts;DBSS_Usability,availability");
metricTypeIDs = metrics.toString();
/***********************************************************************************************/
/***********************************************************************************************/
def printMetricData(agentName, topologyName, metricName) {
queryService = server.get("QueryService");
dataService = server.get("DataService");
query = topologyName + " where monitoringAgent.name = '" + agentName + "' ";
topologies = queryService.queryTopologyObjects(query);
if (topologies == null || topologies.size() == 0) {
return "-1";
}
def fileName = "logs/" + agentName + "-" + topologyName + "-" + metricName + '_history_data.csv';
//specificTimeRange = functionHelper.getSpecificTimeRange();
now = System.currentTimeMillis();
spStart = new Timestamp(now - 30L*24L*60L*60L*1000L); //30 days back
spEnd = new Timestamp(now);
def buffer = new StringBuffer("\n");
try {
for (aColl in topologies) {
buffer.append("name = ");
buffer.append(aColl.name);
buffer.append("\n\n");
buffer.append(" Start Time, End Time, Sampled Period, Count , Min , Max , Average , Sum , \n");
mHistory = dataService.retrieve(aColl , metricName , spStart , spEnd );
for(i=0 ; i <mHistory.size(); i++ ) {
dao = mHistory.get(i);
periodStart = (new Date(dao.getPeriodStart())).toString();
periodEnd = (new Date(dao.getPeriodEnd())).toString();
sPeriod = dao.getSampledPeriod();
count = dao.getValue().getCount();
avg = dao.getValue().getAvg();
sum = dao.getValue().getSum();
min = dao.getValue().getMin();
max = dao.getValue().getMax();
buffer.append(periodStart).append(",").append(periodEnd).append(",").append(sPeriod).append(",").append(count).append(",").append(min).append(",").append(max).append(",").append(avg).append(",").append(sum).append(",\n");
}
buffer.append("---------------------------------------------------------\n\n");
}
BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
out.write("----- Metric's [" + metricName );
out.write("] row history data ---------------------------------\n");
out.write("\nFrom : "+spStart);
out.write("\nTo : "+spEnd);
out.write("\n---------------------------------------------------------\n");
out.write(buffer.toString());
out.close();
return "0";
} catch (Exception e) {
return "Failed to get metric history " + e;
}
}
def retValue = new StringBuffer();
metricTypeIDsArr = metricTypeIDs.split(";");
for (String metricTypeID in metricTypeIDsArr) {
metricTypeArr = metricTypeID.split(",");
retValue.append('[');
retValue.append(printMetricData(agentName, metricTypeArr[0], metricTypeArr[1]));
retValue.append(']');
}
return retValue.toString();
DISCLAIMER
The information in the script(s) provided is known to work successfully; however, they have not been officially tested by our Quality Control. If any of these instructions are changed and/or incorrectly used, intentionally or unintentionally, this script becomes unsupported by our Support and Development. Support and Development recommend always making a backup of the current database prior to execution of any script(s) that may modify it. For customization of Foglight, please contact our Professional Services Organization.