Search in sources :

Example 21 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)

Example 22 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdGraphDefTemplate method getRrdGraphDef.

/**
 * Creates RrdGraphDef object which can be used to create RrdGraph
 * object (actual JRobin graphs). Before this method is called, all template variables (if any)
 * must be resolved (replaced with real values).
 * See {@link XmlTemplate#setVariable(String, String) setVariable()} method information to
 * understand how to supply values for template variables.
 *
 * @return Graph definition which can be used to create RrdGraph object (actual JRobin graphs)
 * @throws RrdException Thrown if parsed XML template contains invalid (unrecognized) tags
 */
public RrdGraphDef getRrdGraphDef() throws RrdException {
    // basic check
    if (!root.getTagName().equals("rrd_graph_def")) {
        throw new RrdException("XML definition must start with <rrd_graph_def>");
    }
    validateTagsOnlyOnce(root, new String[] { "filename", "span", "options", "datasources", "graph" });
    rrdGraphDef = new RrdGraphDef();
    // traverse all nodes
    Node[] childNodes = getChildNodes(root);
    for (Node childNode : childNodes) {
        String nodeName = childNode.getNodeName();
        if (nodeName.equals("filename")) {
            resolveFilename(childNode);
        } else // SPAN
        if (nodeName.equals("span")) {
            resolveSpan(childNode);
        } else // OPTIONS
        if (nodeName.equals("options")) {
            resolveOptions(childNode);
        } else // DATASOURCES
        if (nodeName.equals("datasources")) {
            resolveDatasources(childNode);
        } else // GRAPH ELEMENTS
        if (nodeName.equals("graph")) {
            resolveGraphElements(childNode);
        }
    }
    return rrdGraphDef;
}
Also used : Node(org.w3c.dom.Node) RrdException(org.jrobin.core.RrdException)

Example 23 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdGraphDefTemplate method resolveCDef.

private void resolveCDef(Node parentNode) throws RrdException {
    validateTagsOnlyOnce(parentNode, new String[] { "name", "rpn" });
    String name = null, rpn = null;
    Node[] childNodes = getChildNodes(parentNode);
    for (Node childNode : childNodes) {
        String nodeName = childNode.getNodeName();
        if (nodeName.equals("name")) {
            name = getValue(childNode);
        } else if (nodeName.equals("rpn")) {
            rpn = getValue(childNode);
        }
    }
    if (name != null && rpn != null) {
        rrdGraphDef.datasource(name, rpn);
    } else {
        throw new RrdException("Incomplete CDEF settings");
    }
}
Also used : Node(org.w3c.dom.Node) RrdException(org.jrobin.core.RrdException)

Example 24 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdGraphDefTemplate method resolveValueGrid.

private void resolveValueGrid(Node parentNode) throws RrdException {
    validateTagsOnlyOnce(parentNode, new String[] { "show_grid", "grid_step", "label_factor" });
    boolean showGrid = true;
    double gridStep = Double.NaN;
    int NOT_SET = Integer.MIN_VALUE, labelFactor = NOT_SET;
    Node[] childNodes = getChildNodes(parentNode);
    for (Node childNode : childNodes) {
        String nodeName = childNode.getNodeName();
        if (nodeName.equals("show_grid")) {
            showGrid = getValueAsBoolean(childNode);
        } else if (nodeName.equals("grid_step")) {
            gridStep = getValueAsDouble(childNode);
        } else if (nodeName.equals("label_factor")) {
            labelFactor = getValueAsInt(childNode);
        }
    }
    rrdGraphDef.setDrawYGrid(showGrid);
    if (!Double.isNaN(gridStep) && labelFactor != NOT_SET) {
        rrdGraphDef.setValueAxis(gridStep, labelFactor);
    } else if (!Double.isNaN(gridStep) || labelFactor != NOT_SET) {
        throw new RrdException("Incomplete value axis settings");
    }
}
Also used : Node(org.w3c.dom.Node) RrdException(org.jrobin.core.RrdException)

Example 25 with RrdException

use of org.jrobin.core.RrdException in project i2p.i2p by i2p.

the class RrdGraphDefTemplate method resolveVRule.

private void resolveVRule(Node parentNode) throws RrdException {
    validateTagsOnlyOnce(parentNode, new String[] { "time", "color", "legend" });
    long timestamp = Long.MIN_VALUE;
    Paint color = null;
    String legend = null;
    Node[] childNodes = getChildNodes(parentNode);
    for (Node childNode : childNodes) {
        String nodeName = childNode.getNodeName();
        if (nodeName.equals("time")) {
            timestamp = Util.getTimestamp(getValue(childNode));
        } else if (nodeName.equals("color")) {
            color = getValueAsColor(childNode);
        } else if (nodeName.equals("legend")) {
            legend = getValue(childNode);
        }
    }
    if (timestamp != Long.MIN_VALUE && color != null) {
        rrdGraphDef.vrule(timestamp, color, legend);
    } else {
        throw new RrdException("Incomplete VRULE settings");
    }
}
Also used : Node(org.w3c.dom.Node) RrdException(org.jrobin.core.RrdException)

Aggregations

RrdException (org.jrobin.core.RrdException)37 Node (org.w3c.dom.Node)13 IOException (java.io.IOException)10 Map (java.util.Map)4 Date (java.util.Date)3 FetchData (org.jrobin.core.FetchData)3 RrdDb (org.jrobin.core.RrdDb)3 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)3 Source (org.opennms.netmgt.measurements.model.Source)3 File (java.io.File)2 Calendar (java.util.Calendar)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SAXSource (javax.xml.transform.sax.SAXSource)2 TimeParser (org.jrobin.core.timespec.TimeParser)2 TimeSpec (org.jrobin.core.timespec.TimeSpec)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1