use of org.jrobin.core.RrdException in project opennms by OpenNMS.
the class RrdConvertUtils method restoreRrd.
/**
* Restores a RRD.
*
* @param rrd the RRD object
* @param targetFile the target file
* @throws IOException Signals that an I/O exception has occurred.
* @throws RrdException the RRD exception
*/
public static void restoreRrd(RRDv3 rrd, File targetFile) throws IOException, RrdException {
String rrdBinary = System.getProperty("rrd.binary");
if (rrdBinary == null) {
throw new IllegalArgumentException("rrd.binary property must be set");
}
try {
File xmlDest = new File(targetFile + ".xml");
JaxbUtils.marshal(rrd, new FileWriter(xmlDest));
Process process = Runtime.getRuntime().exec(new String[] { rrdBinary, "restore", xmlDest.getAbsolutePath(), targetFile.getAbsolutePath() });
process.waitFor();
if (!xmlDest.delete()) {
LOG.warn("Could not delete file: {}", xmlDest.getPath());
}
} catch (Exception e) {
throw new RrdException("Can't restore RRD", e);
}
}
use of org.jrobin.core.RrdException in project opennms by OpenNMS.
the class SpikeHunter method replaceInArchive.
private static void replaceInArchive(org.jrobin.core.Archive arc) {
String consolFun = "";
int arcSteps = 0;
long startTime = 0;
long endTime = 0;
FetchData data = null;
Robin robin = null;
try {
consolFun = arc.getConsolFun();
arcSteps = arc.getSteps();
startTime = arc.getStartTime();
endTime = arc.getEndTime();
} catch (IOException e) {
System.out.println("IO Exception trying to get archive information from RRD file: " + e.getMessage());
System.exit(-1);
}
printToUser("Operating on archive with CF " + consolFun + ", " + arcSteps + " steps");
try {
data = m_rrdFile.createFetchRequest(consolFun, startTime, endTime).fetchData();
} catch (RrdException rrde) {
System.out.println("RRD Exception trying to create fetch request: " + rrde.getMessage());
System.exit(-1);
} catch (IOException ioe) {
System.out.println("IO Exception trying to create fetch request: " + ioe.getMessage());
System.exit(-1);
}
String[] dsNames;
if (m_dsNames == null) {
dsNames = data.getDsNames();
} else {
dsNames = m_dsNames.split(",");
}
for (String dsName : dsNames) {
replaceInDs(arc, data, dsName);
}
}
use of org.jrobin.core.RrdException in project opennms by OpenNMS.
the class RrdGraphController method parseTimes.
public long[] parseTimes(HttpServletRequest request) {
String startTime = request.getParameter("start");
String endTime = request.getParameter("end");
if (startTime == null || "".equals(startTime)) {
startTime = "now - 1day";
}
if (endTime == null || "".equals(endTime)) {
endTime = "now";
}
boolean startIsInteger = false;
boolean endIsInteger = false;
long start = 0, end = 0;
try {
start = Long.valueOf(startTime);
startIsInteger = true;
} catch (NumberFormatException e) {
}
try {
end = Long.valueOf(endTime);
endIsInteger = true;
} catch (NumberFormatException e) {
}
if (endIsInteger && startIsInteger) {
return new long[] { start, end };
}
// is expected for epoch times by TimeParser
if (startIsInteger) {
//Convert to seconds
startTime = "" + (start / 1000);
}
if (endIsInteger) {
endTime = "" + (end / 1000);
}
TimeParser startParser = new TimeParser(startTime);
TimeParser endParser = new TimeParser(endTime);
try {
TimeSpec specStart = startParser.parse();
TimeSpec specEnd = endParser.parse();
long[] results = TimeSpec.getTimestamps(specStart, specEnd);
//Multiply by 1000. TimeSpec returns timestamps in Seconds, not Milliseconds. Gah.
results[0] = results[0] * 1000;
results[1] = results[1] * 1000;
return results;
} catch (RrdException e) {
throw new IllegalArgumentException("Could not parse start '" + startTime + "' and end '" + endTime + "' as valid time specifications", e);
}
}
Aggregations