Skip to content

Instantly share code, notes, and snippets.

@scsibug
Created July 7, 2013 22:45
Show Gist options
  • Save scsibug/5945259 to your computer and use it in GitHub Desktop.
Save scsibug/5945259 to your computer and use it in GitHub Desktop.
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException {
RrdGraphDef graphDef = new RrdGraphDef();
configureImageParameters(graphDef, req);
configureContents(graphDef, req);
try {
RrdGraph graph = new RrdGraph(graphDef);
BufferedImage bi = new BufferedImage(graph.getRrdGraphInfo().getWidth(), graph.getRrdGraphInfo().getHeight(), BufferedImage.TYPE_INT_RGB);
graph.render(bi.getGraphics());
res.setContentType("image/png");
javax.imageio.ImageIO.write(bi, "png", res.getOutputStream());
} catch(FileNotFoundException e) {
throw new ServletException("Could not read database files for all requested items.", e);
}
}
@scsibug
Copy link
Author

scsibug commented Jul 7, 2013

servlet to write RRD4j graphs directly to a client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment