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);
}
}
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;
}
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");
}
}
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");
}
}
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");
}
}
Aggregations