I'm sending metrics to Graphite using sockets:
String prefix = prefix
+ "." + metric + " " + value + " " + (System.currentTimeMillis() / 1000);
socket = new Socket(host, port);
out = new PrintWriter(socket.getOutputStream(), true);
out.println(prefix);
This sends metrics every millisecond or so. How can I make sure to send it every 1 or 5 minutes or at random intervals?
答案 0 :(得分:0)
Put it in a while loop and add a sleep
while (true){
String prefix = prefix
+ "." + metric + " " + value + " " + (System.currentTimeMillis() / 1000);
socket = new Socket(host, port);
out = new PrintWriter(socket.getOutputStream(), true);
out.println(prefix);
Thread.sleep(60);
}
Why do you want to do do it in a random interval? Graphite expects exact intervals.