我正在使用 dropwizard codahale 指标库将指标数据发送到石墨服务器。但是,现在我要求将这些指标数据写入文件而不是推送到石墨服务器。这些文件中的数据可以稍后在需要时推送到石墨服务器。
有什么办法可以做到这一点?尤其是将指标写入中间文件而不是发送到服务器的部分,以这样的格式,可以在必要时将其推送到石墨服务器?
我正在使用 dropwizard codahale 指标库将指标数据发送到石墨服务器。但是,现在我要求将这些指标数据写入文件而不是推送到石墨服务器。这些文件中的数据可以稍后在需要时推送到石墨服务器。
有什么办法可以做到这一点?尤其是将指标写入中间文件而不是发送到服务器的部分,以这样的格式,可以在必要时将其推送到石墨服务器?
就在这里。Codhale 开箱即用,带有一个名为 CsvReporter 的类。这将收集您的指标并以 csv 格式将它们写入磁盘。
看看这里:https ://dropwizard.github.io/metrics/3.1.0/apidocs/com/codahale/metrics/CsvReporter.html
你可以这样初始化它:
File file = new File(expandPath(conf.getMetricCsvLocation()));
if(!file.exists()) {
log.warn("CSV Metrics location does not exist. Metrics will not be written. Change the file location to an existing location.");
return;
}
reporter = CsvReporter.forRegistry(env.metrics()).build(file);