/** * Sets RRD's starting timestamp. * * @param date starting date */ public void setStartTime(Date date) { this.startTime = Util.getTimestamp(date); }
/** * Normalize to a probe step, as org.rrd4j.core.Util.normalize But use a * Date argument and return a Date * * @param date A Date to normalize * @param step Step in seconds * @return "Rounded" Date */ public static Date normalize(Date date, long step) { long timestamp = org.rrd4j.core.Util.getTimestamp(date); return org.rrd4j.core.Util.getDate(org.rrd4j.core.Util.normalize(timestamp, step)); }
/** * Returns path to user's home directory. * * @return Path to users home directory, with file separator appended. */ public static String getUserHomeDirectory() { return System.getProperty("user.home") + getFileSeparator(); }
private boolean lazyCheck() { // redraw if lazy option is not set or file does not exist if (!gdef.lazy || !Util.fileExists(gdef.filename)) { return false; // 'false' means 'redraw' } // redraw if not enough time has passed long secPerPixel = (gdef.endTime - gdef.startTime) / gdef.width; long elapsed = Util.getTimestamp() - Util.getLastModified(gdef.filename); return elapsed <= secPerPixel; }
/** * Returns path to directory used for placement of Rrd4j demo graphs and creates it * if necessary. * * @return Path to demo directory (defaults to $HOME/rrd4j/) if directory exists or * was successfully created. Null if such directory could not be created. */ public static String getRrd4jDemoDirectory() { String homeDirPath = getUserHomeDirectory() + RRD4J_DIR + getFileSeparator(); File homeDirFile = new File(homeDirPath); return (homeDirFile.exists() || homeDirFile.mkdirs()) ? homeDirPath : null; }
/** * Just an alias for {@link #getTime()} method. * * @return Current timestamp (without milliseconds) */ public static long getTimestamp() { return getTime(); }
protected void writeCsv(OutputStream out, DataProcessor dp, DateFormat exportDateFormat) throws IOException { String sources[] = dp.getSourceNames(); StringBuilder sourcesline = new StringBuilder(); sourcesline.append("Date,"); for(String name: sources) { if(!name.startsWith("rev_")) sourcesline.append(name).append(","); } sourcesline.deleteCharAt(sourcesline.length() - 1); sourcesline.append("\r\n"); out.write(sourcesline.toString().getBytes()); double[][] values = dp.getValues(); long[] ts = dp.getTimestamps(); for(int i = 0; i < ts.length; i++) { sourcesline.setLength(0); sourcesline.append(exportDateFormat.format(org.rrd4j.core.Util.getDate(ts[i]))).append(","); for(int j = 0; j < sources.length; j++) { if(!sources[j].startsWith("rev_")) sourcesline.append(values[j][i]).append(","); } sourcesline.deleteCharAt(sourcesline.length() - 1); sourcesline.append("\r\n"); out.write(sourcesline.toString().getBytes()); } } }
/** * Formats double as a string using exponential notation (RRDTool like). Used for debugging * through the project. * * @param x value to be formatted * @return string like "+1.234567E+02" */ public static String formatDouble(double x) { return formatDouble(x, true); }
public static void main(String[] args) { System.out.println("RRD4J :: RRDTool choice for the Java world"); System.out.println("==============================================================================="); System.out.println("RRD4J base directory: " + Util.getRrd4jHomeDirectory()); long time = Util.getTime(); System.out.println("Current time: " + time + ": " + new Date(time * 1000L)); System.out.println("-------------------------------------------------------------------------------"); System.out.println("See https://rrd4j.dev.java.net for more information and the latest version."); System.out.println("Copyright 2010 Sasa Markovic and Mathias Bogaert. Licensed under the Apache License, Version 2.0."); }
private double getCalendarField(double timestamp, int field) { Calendar calendar = Util.getCalendar((long) (timestamp)); return calendar.get(field); }
public static void main(String[] args) throws IOException { long start = Util.getTime(), end = start + 300 * 300; String rrdFile = Util.getRrd4jDemoPath("minmax.rrd"); String pngFile = Util.getRrd4jDemoPath("minmax.png");
/** * {@inheritDoc} * * Method to determine if a file with the given path already exists. */ @Override protected boolean exists(String path) { return Util.fileExists(path); }
private boolean lazyCheck() { // redraw if lazy option is not set or file does not exist if (!gdef.lazy || !Util.fileExists(gdef.filename)) { return false; // 'false' means 'redraw' } // redraw if not enough time has passed long secPerPixel = (gdef.endTime - gdef.startTime) / gdef.width; long elapsed = Util.getTimestamp() - Util.getLastModified(gdef.filename); return elapsed <= secPerPixel; }
/** * Sets the time when the graph should begin. Time in seconds since epoch * (1970-01-01) is required. Negative numbers are relative to the current time. * * @param time Starting time for the graph in seconds since epoch */ public void setStartTime(long time) { this.startTime = time; if (time <= 0) { this.startTime += Util.getTime(); } }
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; }
/** * Returns String representing all aggregated values. Just for debugging purposes. * * @return String containing all aggregated values */ public String dump() { return "MIN=" + Util.formatDouble(min) + ", MAX=" + Util.formatDouble(max) + "\n" + "FIRST=" + Util.formatDouble(first) + ", LAST=" + Util.formatDouble(last) + "\n" + "AVERAGE=" + Util.formatDouble(average) + ", TOTAL=" + Util.formatDouble(total); } }
/** * main. * * @param args an array of {@link java.lang.String} objects. */ public static void main(String[] args) { System.out.println("RRD4J :: RRDTool choice for the Java world"); System.out.println("==============================================================================="); System.out.println("RRD4J base directory: " + Util.getRrd4jHomeDirectory()); long time = Util.getTime(); System.out.println("Current time: " + time + ": " + new Date(time * 1000L)); System.out.println("-------------------------------------------------------------------------------"); System.out.println("See https://github.com/rrd4j/rrd4j for more information and the latest version."); System.out.println("Copyright 2017 The RRD4J Authors. Copyright (c) 2001-2005 Sasa Markovic and Ciaran Treanor. Copyright (c) 2013 The OpenNMS Group, Inc.. Licensed under the Apache License, Version 2.0."); }