java - 石墨:如何以随机间隔发送石墨指标?
问题描述
我正在使用套接字向 Graphite 发送指标:
String prefix = prefix
+ "." + metric + " " + value + " " + (System.currentTimeMillis() / 1000);
socket = new Socket(host, port);
out = new PrintWriter(socket.getOutputStream(), true);
out.println(prefix);
这每毫秒左右发送一次指标。如何确保每 1 或 5 分钟或随机间隔发送一次?
解决方案
把它放在一个while循环中并添加一个睡眠
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);
}
为什么要以随机间隔进行?Graphite 需要精确的间隔。
推荐阅读
- python - python中的正则表达式用于时间格式,后跟逗号和三位数字
- c# - 如何编写 JsonConverter 来序列化和反序列化包含单个值的自定义结构?
- android-studio - 在 Mac M1 中配置 Android Studio 和 Flutter
- asp.net - 在 Windows 窗体 C# 中从 oracle 获取 BLOB 文件
- c# - 如何使用 .NetCore 将结构返回为 json
- go - 为什么使用 gosnmp 发出的 snmpwalk 请求会在 29 秒后超时?
- javascript - 仅在客户端下载文本文件
- c++ - 从服务器端关闭客户端套接字的问题
- python - 如何在熊猫中创建按月分组的二进制虚拟变量的总和?
- javascript - Sqlite executeSql 没有返回 ResultSet