Graphite: How to send graphite metrics at random intervals?

时间:2018-09-18 19:45:54

标签: java graphite

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?

1 个答案:

答案 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.