Search in sources :

Example 11 with RrdException

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);
    }
}
Also used : FileWriter(java.io.FileWriter) RrdException(org.jrobin.core.RrdException) File(java.io.File) IOException(java.io.IOException) RrdException(org.jrobin.core.RrdException)

Example 12 with RrdException

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);
    }
}
Also used : IOException(java.io.IOException) RrdException(org.jrobin.core.RrdException) FetchData(org.jrobin.core.FetchData) Robin(org.jrobin.core.Robin)

Example 13 with RrdException

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);
    }
}
Also used : RrdException(org.jrobin.core.RrdException) TimeParser(org.jrobin.core.timespec.TimeParser) TimeSpec(org.jrobin.core.timespec.TimeSpec)

Aggregations

RrdException (org.jrobin.core.RrdException)13 IOException (java.io.IOException)8 Map (java.util.Map)3 FetchData (org.jrobin.core.FetchData)3 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)3 Source (org.opennms.netmgt.measurements.model.Source)3 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SAXSource (javax.xml.transform.sax.SAXSource)2 RrdDb (org.jrobin.core.RrdDb)2 TimeParser (org.jrobin.core.timespec.TimeParser)2 TimeSpec (org.jrobin.core.timespec.TimeSpec)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 Color (java.awt.Color)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1