Skip to content

Instantly share code, notes, and snippets.

@splatch
Created October 17, 2011 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splatch/1292370 to your computer and use it in GitHub Desktop.
Save splatch/1292370 to your computer and use it in GitHub Desktop.
package org.code_house.webconsole.monitor.jmx;
import org.joda.time.DateTime;
import org.rrd4j.ConsolFun;
import org.rrd4j.core.FetchData;
import org.rrd4j.core.FetchRequest;
import org.rrd4j.core.RrdDb;
import org.rrd4j.core.Util;
public class Fetch {
public static void main(String[] args) throws Exception {
String file = "jmx-memory.rrd";
RrdDb db = new RrdDb(file);
long now = Util.getTimestamp() - 1;
long back = Util.getTimestamp() - 300;
FetchRequest request = db.createFetchRequest(ConsolFun.AVERAGE, back, now);
FetchData data = request.fetchData();
long[] timestamps = data.getTimestamps();
for (String ds : data.getDsNames()) {
for (int i = 0; i < timestamps.length; i++) {
System.out.println(ds + " " + new DateTime(timestamps[i] * 1000).toString("dd.MM.YYYY HH:mm:ss") + " " + data.getValues(ds)[i]);
}
System.out.println("-");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment