in src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritGraphiteReporter.java [55:110]
public GerritGraphiteReporter(
PluginConfigFactory configFactory, @PluginName String pluginName, MetricRegistry registry) {
Config config = configFactory.getGlobalPluginConfig(pluginName);
String host = config.getString(SECTION_GRAPHITE, null, KEY_HOST);
if (host != null) {
int port;
try {
port = config.getInt(SECTION_GRAPHITE, KEY_PORT, DEFAULT_PORT);
} catch (IllegalArgumentException e) {
log.warn(String.format("Invalid port value; default to %d", DEFAULT_PORT));
port = DEFAULT_PORT;
}
String prefix = config.getString(SECTION_GRAPHITE, null, KEY_PREFIX);
if (prefix == null) {
try {
prefix = name(DEFAULT_PREFIX, InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
log.error("Failed to get hostname", e);
throw new RuntimeException(e);
}
}
long configRate;
try {
configRate =
config.getTimeUnit(SECTION_GRAPHITE, null, KEY_RATE, DEFAULT_RATE, DEFAULT_RATE_UNIT);
} catch (IllegalArgumentException e) {
log.warn(String.format("Invalid rate value; default to %ds", DEFAULT_RATE));
configRate = DEFAULT_RATE;
}
if (configRate > 0) {
rate = (int) configRate;
} else {
log.warn(String.format("Rate value must be positive; default to %ds", DEFAULT_RATE));
rate = DEFAULT_RATE;
}
log.info(
String.format(
"Reporting to Graphite at %s:%d with prefix %s at rate %ds",
host, port, prefix, rate));
graphiteReporter =
GraphiteReporter.forRegistry(registry)
.convertRatesTo(TimeUnit.MINUTES)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.prefixedWith(prefix)
.filter(MetricFilter.ALL)
.build(new Graphite(new InetSocketAddress(host, port)));
} else {
log.warn("No hostname configured; not reporting to Graphite");
graphiteReporter = null;
rate = 0;
}
}