@Override protected Object doPost(String account, String id, SampleRequest request) throws Exception { File parent = new File(dataDir, account + "/" + id); File file = new File(parent, "database.rrd"); if (!file.exists()) { throw new DatabaseDoesNotExistException(); } RrdDb db = new RrdDb(file.getPath()); Sample sample = db.createSample(Util.normalize(request.getTime(), db.getRrdDef().getStep())); for (Map.Entry<String, Double> entry : request.getValues().entrySet()) { sample.setValue(entry.getKey(), entry.getValue()); } sample.update(); db.close(); return null; }
@BeforeClass public static void createRrd() throws IOException { startTime = start - start % step; endTime = startTime + 200 * step; RrdDef def = new RrdDef(fileName, startTime - 3 * step, step); def.addArchive(ConsolFun.AVERAGE, 0.5, 1, 215); def.addDatasource("bar", DsType.GAUGE, 3000, Double.NaN, Double.NaN); RrdDb db = new RrdDb(def, RrdBackendFactory.getFactory(backend)); db.createSample((startTime - step)).setValue(0, 0.0).update(); long sampleTime = startTime; for (double val : vals) { db.createSample(sampleTime).setValue(0, val).update(); sampleTime += step; } if (dorrdtool) { String xmlfile = System.getProperty("java.io.tmpdir") + File.separator + "variabletest.xml"; String rrdfile = System.getProperty("java.io.tmpdir") + File.separator + "variabletest.rrd"; db.dumpXml(xmlfile); System.out.println("rrdtool restore " + xmlfile + " " + rrdfile); String cmd = "rrdtool graph /dev/null " + String.format("--start=%d ", startTime) + String.format("--end=%d ", endTime) + String.format("DEF:baz=%s:bar:AVERAGE ", rrdfile) + "VDEF:min=baz,MINIMUM " + "PRINT:min:\"mininum %1.15le\" " + "VDEF:max=baz,MAXIMUM " + "PRINT:max:\"maximum %1.15le\" " + "VDEF:avg=baz,AVERAGE " + "PRINT:avg:\"average %1.15le\" " + "VDEF:stdev=baz,STDEV " + "PRINT:stdev:\"stdev %1.15le\" " + "VDEF:first=baz,FIRST " + "PRINT:first:\"first %1.15le\" " + "VDEF:last=baz,LAST " + "PRINT:last:\"last %1.15le\" " + "VDEF:total=baz,TOTAL " + "PRINT:total:\"total %1.15le\" " + "VDEF:percent=baz,95,PERCENT " + "PRINT:percent:\"95-th percent %1.15le\" " + "VDEF:percentnan=baz,95,PERCENTNAN " + "PRINT:percentnan:\"95-th percentnan %1.15le\" " + "VDEF:lslope=baz,LSLSLOPE " + "PRINT:lslope:\"lslope %1.15le\" " + "VDEF:lslint=baz,LSLINT " + "PRINT:lslint:\"lslintn %1.15le\" " + "VDEF:lslcorrel=baz,LSLCORREL " + "PRINT:lslcorrel:\"lslcorrel %1.15le\" "; System.out.println(cmd); long interval = (endTime - startTime) / 3; String cmd2 = "rrdtool graph /dev/null " + String.format("--start=%d ", startTime + interval) + String.format("--end=%d ", endTime - interval) + String.format("DEF:baz=%s:bar:AVERAGE ", rrdfile) + "VDEF:min=baz,MINIMUM " + "PRINT:min:\"mininum %1.15le\" " + "VDEF:max=baz,MAXIMUM " + "PRINT:max:\"maximum %1.15le\" " + "VDEF:avg=baz,AVERAGE " + "PRINT:avg:\"average %1.15le\" " + "VDEF:stdev=baz,STDEV " + "PRINT:stdev:\"stdev %1.15le\" " + "VDEF:first=baz,FIRST " + "PRINT:first:\"first %1.15le\" " + "VDEF:last=baz,LAST " + "PRINT:last:\"last %1.15le\" " + "VDEF:total=baz,TOTAL " + "PRINT:total:\"total %1.15le\" " + "VDEF:percent=baz,95,PERCENT " + "PRINT:percent:\"95-th percent %1.15le\" " + "VDEF:percentnan=baz,95,PERCENTNAN " + "PRINT:percentnan:\"95-th percentnan %1.15le\" " + "VDEF:lslope=baz,LSLSLOPE " + "PRINT:lslope:\"lslope %1.15le\" " + "VDEF:lslint=baz,LSLINT " + "PRINT:lslint:\"lslintn %1.15le\" " + "VDEF:lslcorrel=baz,LSLCORREL " + "PRINT:lslcorrel:\"lslcorrel %1.15le\" "; System.out.println(cmd2); String cmd3 = "rrdtool graph /dev/null " + String.format("--start=%d ", startTime - 10 * step) + String.format("--end=%d ", endTime + 2 * step) + String.format("DEF:baz=%s:bar:AVERAGE ", rrdfile) + "VDEF:min=baz,MINIMUM " + "PRINT:min:\"mininum %1.15le\" " + "VDEF:max=baz,MAXIMUM " + "PRINT:max:\"maximum %1.15le\" " + "VDEF:avg=baz,AVERAGE " + "PRINT:avg:\"average %1.15le\" " + "VDEF:stdev=baz,STDEV " + "PRINT:stdev:\"stdev %1.15le\" " + "VDEF:first=baz,FIRST " + "PRINT:first:\"first %1.15le\" " + "VDEF:last=baz,LAST " + "PRINT:last:\"last %1.15le\" " + "VDEF:total=baz,TOTAL " + "PRINT:total:\"total %1.15le\" " + "VDEF:percent=baz,95,PERCENT " + "PRINT:percent:\"95-th percent %1.15le\" " + "VDEF:percentnan=baz,95,PERCENTNAN " + "PRINT:percentnan:\"95-th percentnan %1.15le\" " + "VDEF:lslope=baz,LSLSLOPE " + "PRINT:lslope:\"lslope %1.15le\" " + "VDEF:lslint=baz,LSLINT " + "PRINT:lslint:\"lslintn %1.15le\" " + "VDEF:lslcorrel=baz,LSLCORREL " + "PRINT:lslcorrel:\"lslcorrel %1.15le\" "; System.out.println(cmd3); } }