1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package SNMP;
import static org.rrd4j.ConsolFun.AVERAGE;
import static org.rrd4j.ConsolFun.MAX;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.management.timer.Timer;
import org.rrd4j.ConsolFun;
import org.rrd4j.DsType;
import org.rrd4j.core.FetchData;
import org.rrd4j.core.FetchRequest;
import org.rrd4j.core.RrdDb;
import org.rrd4j.core.RrdDef;
import org.rrd4j.core.Sample;
import org.rrd4j.core.Util;
import org.rrd4j.graph.RrdGraph;
import org.rrd4j.graph.RrdGraphDef;
public class kkkkkk {
static final String Chemin ="D:/Mes documents/9raya/Niveau/RI5/rrd/";
static String file = "test";
static final int IMG_WIDTH = 500;
static final int IMG_HEIGHT = 300;
static java.util.GregorianCalendar calendar = new GregorianCalendar();
static final long Start_time = calendar.getTimeInMillis();
static long End_time ;
static Sample sample;
public kkkkkk() {
// TODO Auto-generated constructor stub
}
/**
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
String rrdPath = Chemin+file+".rrd";
String imgPath = Chemin+file+ ".png";
RrdDef rrdDef = new RrdDef(rrdPath);
rrdDef.setStartTime(Start_time);
rrdDef.addDatasource("speed", DsType.COUNTER, 600, Double.NaN, Double.NaN);
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 1, 24);
rrdDef.addArchive(ConsolFun.AVERAGE, 0.5, 6, 10);
RrdDb rrdDb = new RrdDb(rrdDef);
sample = rrdDb.createSample();
//int [] f = new int[] {1,3,6,1,2,1,2,2,1,10,1};
//EnvoieRequete m= new EnvoieRequete("udp:127.0.0.1/161","public",f);
//int Result =m.SendRequest("udp:127.0.0.1/161","public",f);
Thread thread = new Thread(new classeRunnable(), "Thread de test");
int i =0;
do
{
thread.run();
thread.sleep(1000);
i++;
}while(i<100);
//thread.stop();
System.out.println("apré thread.stop");
//time2=sample.getTime();
//thread.destroy();
FetchRequest fetchRequest = rrdDb.createFetchRequest(ConsolFun.AVERAGE, Start_time,End_time);
FetchData fetchData = fetchRequest.fetchData();
fetchData.dump();
rrdDb.close();
RrdGraphDef graphDef = new RrdGraphDef();
graphDef.setTimeSpan(Start_time,End_time);
graphDef.datasource("myspeed", rrdPath, "speed", ConsolFun.AVERAGE);
graphDef.line("myspeed", Color.black, null, 2);
graphDef.setFilename(imgPath);
RrdGraph graph = new RrdGraph(graphDef);
BufferedImage bi = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
graph.render(bi.getGraphics());
}
} |
Partager