package net.sourceforge.jrrd.examples;
/*
* #%L
* jRRD
* %%
* Copyright (C) 2001 - 2013 jRRD
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import net.sourceforge.jrrd.ConsolidationFunctionType;
import net.sourceforge.jrrd.DataChunk;
import net.sourceforge.jrrd.Main;
import net.sourceforge.jrrd.RRDException;
import net.sourceforge.jrrd.RRDatabase;
public class SimpleFetch2 {
public SimpleFetch2(String rrdFile) {
RRDatabase rrd = null;
DataChunk chunk = null;
try {
rrd = new RRDatabase(rrdFile);
// no period specified, so request the last 24 hours
chunk = rrd.getData(ConsolidationFunctionType.AVERAGE);
// retreive the data for the first datasource
Map<Date, Double> values = chunk.toMap(0);
for(Map.Entry<Date, Double> entry : values.entrySet()) {
Date index = entry.getKey();
double v = entry.getValue();
System.out.println("index: <" + index + ">, value <" + v + ">");
}
} catch (IOException e) {
// this exception will be thrown if the file cannot be read
e.printStackTrace();
} catch (RRDException e) {
// this exception will be thrown if the rrd archive does not
// contains the requested period
e.printStackTrace();
}
}
static void usage(int status) {
System.err.println("Usage: " + Main.class.getName() + " rrdfile");
System.exit(status);
}
public static void main(String[] args) {
if (args.length != 1) {
usage(1);
}
new SimpleFetch2(args[0]);
}
}