Skip to content

Instantly share code, notes, and snippets.

@splatch
Created Oct 17, 2011
Embed
What would you like to do?
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