try {
RrdDb rrdDb = new RrdDb("./etc/rrd4j/" + rrdName);
long[] times = Util.getTimestamps(start, end);
FetchRequest fetchRequest = rrdDb.createFetchRequest(
ConsolFun.valueOf(ds), times[0], times[1], res);
FetchData fetchData = fetchRequest.fetchData();
StringBuilder buffer = new StringBuilder();
long[] timestamps = fetchData.getTimestamps();
double[][] values = fetchData.getValues();
buffer.append("[");
for (int row = 0; row < fetchData.getRowCount(); row++) {
// change to microseconds
buffer.append("[" + (timestamps[row]*1000) + ",");
buffer.append("[");
ArrayList<String> data = new ArrayList<String>();
for (int dsIndex = 0; dsIndex < fetchData.getColumnCount(); dsIndex++) {
data.add(dsIndex,RrdResource.formatDouble(values[dsIndex][row],"null",true));
}
buffer.append(StringUtils.join(data, ","));
buffer.append("]],");
}