/** * @param start the start to set */ public void setStart(Date start) { long step = getNode().getProbe().getStep(); this.start = new Date(org.rrd4j.core.Util.normalize(start.getTime() / 1000L, step) * 1000L); }
/** * Used to normalize the end date to the last update time but only if it's * close to it * * @param p the probe to check against * @param endDate the desired end date * @return the normalized end date */ public static Date endDate(Probe<?, ?> p, Date endDate) { // Date normalized = endDate; // We normalize the last update time, it can't be used directly long step = p.getStep(); Date lastUpdate = p.getLastUpdate(); // We dont want to graph past the last normalized update time // but only if we are within a step interval if(Math.abs(endDate.getTime() - lastUpdate.getTime()) <= (step * 1000L)) return normalize(lastUpdate, step); // Else rrd4j will manage the normalization itself return endDate; }
static public Period getPeriod(Probe<?, ?> p, long endSec) { Date end = org.rrd4j.core.Util.getDate(endSec); Calendar calBegin = Calendar.getInstance(); calBegin.setTime(end); calBegin.add(Calendar.MONTH, -1); Date begin = calBegin.getTime(); end = jrds.Util.normalize(end, p.getStep()); Period pr = null; try { pr = new Period(Long.toString(begin.getTime()), Long.toString(end.getTime())); } catch (ParseException e) { } return pr; }
int graphStep = graph.getNode().getProbe().getStep(); if(p.period.getScale() != 0 || !cache) { res.addDateHeader("Expires", new Date().getTime() + graphStep * 1000);
ExtractInfo ei = ExtractInfo.get().make(p.getBegin(), p.getEnd()).make(probe.getStep()); try { sourceDp = probe.extract(ei);
public void collectAll() { log(Level.DEBUG, "Starting collect"); Timer timer = (Timer) getParent(); long start = System.currentTimeMillis(); startCollect(); String oldThreadName = Thread.currentThread().getName(); for(Probe<?, ?> probe: allProbes) { if(!isCollectRunning()) break; long duration = (System.currentTimeMillis() - start) / 1000; if(duration > (probe.getStep() / 2)) { log(Level.ERROR, "Collect too slow: %ds for timer %s", duration, timer); break; } log(Level.TRACE, "Starting collect for %s", probe); log(Level.DEBUG, "Collect all stats for host " + host.getName()); setRunningname(oldThreadName + "/" + probe.getName()); probe.collect(); setRunningname(oldThreadName + ":finished"); } stopCollect(); long end = System.currentTimeMillis(); float elapsed = (end - start) / 1000f; log(Level.DEBUG, "Collect time for %s: %fs", host.getName(), elapsed); }
public RrdDef getRrdDef(ArchivesSet archives) { RrdDef def = new RrdDef(getPath()); def.setVersion(2); def.addDatasource(getDsDefs()); def.addArchive(archives.getArchives()); def.setStep(p.getStep()); return def; }
@Test public void testFill() throws Exception { @SuppressWarnings("unchecked") Probe<?, ?> p = GenerateProbe.quickProbe(testFolder); p.setStep(30); p.getPd().add("test", DsType.GAUGE); Assert.assertTrue("Probe file creation failed", p.checkStore()); Extractor e = p.getMainStore().getExtractor(); e.addSource("test", "test"); String[] dsNames = e.getNames(); Assert.assertEquals("data source test not found", "test", dsNames[0]); long start = p.getLastUpdate().getTime(); for(int i = 1; i <= 30; i++) { JrdsSample s = p.newSample(); long sampletime = i * p.getStep() * 1000 + start; sampletime = (sampletime) - (sampletime % (p.getStep() * 1000)); s.setTime(new Date(sampletime)); s.put("test", i); p.getMainStore().commit(s); } ExtractInfo ei = ExtractInfo.get().make(new Date(start), new Date(start + 30 * p.getStep() * 1000)); DataProcessor dp = p.extract(ei); double[][] values = dp.getValues(); for(int i = 1; i <= 30; i++) { // Check raw values Assert.assertEquals("Wrong values stored", i, values[0][i], 1e-10); long sampletime = i * p.getStep() * 1000 + start; sampletime = (sampletime) - (sampletime % (p.getStep() * 1000)); } }