public GangliaMeterRegistry(GangliaConfig config, Clock clock, HierarchicalNameMapper nameMapper, MetricRegistry metricRegistry) { // Technically, Ganglia doesn't have any constraints on metric or tag names, but the encoding of Unicode can look // horrible in the UI. So be aware... super(config, metricRegistry, nameMapper, clock); this.config = config; try { final GMetric ganglia = new GMetric(config.host(), config.port(), config.addressingMode(), config.ttl()); this.reporter = GangliaReporter.forRegistry(getDropwizardRegistry()) .convertRatesTo(config.rateUnits()) .convertDurationsTo(config.durationUnits()) .build(ganglia); if(config.enabled()) start(); } catch (IOException e) { throw new RuntimeException("Failed to configure Ganglia metrics reporting", e); } }
@Override public void start(Settings settings, MetricRegistry metricRegistry) { if (settings.getBoolean("metrics.ganglia.enabled", false)) { final String hostname = settings.getLocalHostname(); final String address = settings.getRequiredString("metrics.ganglia.address"); final int port = settings.getInteger("metrics.ganglia.port", 8649); final long period = settings.getDuration("metrics.ganglia.period", TimeUnit.SECONDS, 60); try { GMetric ganglia = new GMetric(address, port, UDPAddressingMode.MULTICAST, 1); reporter = GangliaReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(ganglia); reporter.start(period, TimeUnit.SECONDS); log.info("Started Ganglia Metrics reporter for '{}', updating every {} seconds", hostname, period); } catch (IOException e) { log.error("Failed to start Ganglia reporter!", e); } } else { log.debug("Ganglia Metrics reporter is disabled"); } }
@Override public void start(PippoSettings settings, MetricRegistry metricRegistry) { if (settings.getBoolean("metrics.ganglia.enabled", false)) { final String hostname = settings.getLocalHostname(); final String address = settings.getRequiredString("metrics.ganglia.address"); final int port = settings.getInteger("metrics.ganglia.port", 8649); final long period = settings.getDurationInSeconds("metrics.ganglia.period", 60); try { GMetric ganglia = new GMetric(address, port, UDPAddressingMode.MULTICAST, 1); reporter = GangliaReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).build(ganglia); reporter.start(period, TimeUnit.SECONDS); log.info("Started Ganglia Metrics reporter for '{}', updating every {} seconds", hostname, period); } catch (IOException e) { log.error("Failed to start Ganglia reporter!", e); } } else { log.debug("Ganglia Metrics reporter is disabled"); } }
/** * Starts the GangliaReporter, pointing to the configured host and port. */ @JsonIgnore public void start(MetricRegistry registry) { if (host != null && port > 0) { try { final GMetric ganglia = new GMetric(host, port, GMetric.UDPAddressingMode.MULTICAST, 1); final GangliaReporter reporter = GangliaReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(ganglia); reporter.start(1, TimeUnit.MINUTES); LOG.info("Reporting to ganglia at {}:{}", host, port); } catch (IOException e) { LOG.warn("Failed to setup ganglia reporting at {}:{}", host, port, e); } } }
/** */ public void enableGangliaReporting(InetSocketAddress gangliaAddress) throws IOException { GMetric ganglia = new GMetric(gangliaAddress.getHostString(), gangliaAddress.getPort(), GMetric.UDPAddressingMode.UNICAST, 1); GangliaReporter reporter = GangliaReporter.forRegistry(registry) .prefixedWith(GANGLIA_METRICS_PREFIX) .build(ganglia); reporter.start(reportFrequency, TimeUnit.MILLISECONDS); }
@Override public ScheduledReporter getIfEnabled() { if (!config.isGangliaReportingEnabled()) { return null; } try { InetSocketAddress gangliaAddress = config.getGangliaAddress(); GMetric ganglia = new GMetric(gangliaAddress.getHostString(), gangliaAddress.getPort(), GMetric.UDPAddressingMode.UNICAST, 1); return GangliaReporter.forRegistry(registry) .prefixedWith(StatisticsCollector.GANGLIA_METRICS_PREFIX) .build(ganglia); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Builds reporter with the given ganglia metric. * * @param gMetric ganglia metric * @return reporter */ private GangliaReporter buildReporter(GMetric gMetric) { MetricRegistry mr = metricsService.getMetricRegistry(); return GangliaReporter.forRegistry(filter(mr)) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(gMetric); }
@Override protected void configure() { bind(GMetric.class).toProvider(GMetricProvider.class); bind(GangliaReporter.class).toProvider(GangliaReporterProvider.class); addConfigBeans(); addInitializer(MetricsGangliaReporterService.class); }
@Override public GangliaReporter get() { return GangliaReporter.forRegistry(metricRegistry) .prefixedWith(configuration.getPrefix()) .convertRatesTo(configuration.getUnitRates()) .convertDurationsTo(configuration.getUnitDurations()) .withDMax(configuration.getDMax()) .withTMax(configuration.getTMax()) .filter(new RegexMetricFilter(configuration.getIncludeMetrics())) .build(gMetric); }
@Test public void get() throws Exception { final MetricsGangliaReporterConfiguration configuration = new MetricsGangliaReporterConfiguration(); final GMetric graphiteSender = new GMetric("127.0.0.1", 12345, null, 23); final MetricRegistry metricRegistry = new MetricRegistry(); final GangliaReporterProvider provider = new GangliaReporterProvider(configuration, graphiteSender, metricRegistry); final GangliaReporter reporter = provider.get(); assertNotNull(reporter); }
/** * Initialize publishing by Ganglia. * <p> * Only the summary registry is published. * * @param repo the component repository, not null * @param summaryRegistry the summary metrics registry, not null * @param detailedRegistry the detailed metrics registry, not null */ protected void initGangliaPublish(ComponentRepository repo, MetricRegistry summaryRegistry, MetricRegistry detailedRegistry) throws IOException { ArgumentChecker.notNull(getGangliaAddress(), "gangliaAddress"); ArgumentChecker.notNull(getGangliaPort(), "gangliaPort"); ArgumentChecker.notNull(getGangliaAddressingMode(), "gangliaAddressingMode"); ArgumentChecker.notNull(getGangliaTtl(), "gangliaTtl"); GMetric ganglia = new GMetric(getGangliaAddress(), getGangliaPort(), UDPAddressingMode.valueOf(getGangliaAddressingMode()), getGangliaTtl(), true); GangliaReporter gangliaReporter = GangliaReporter.forRegistry(summaryRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(ganglia); repo.registerLifecycle(new GangliaReporterLifecycle(gangliaReporter)); }
private GangliaReporter createGangliaReporter(URI uri) { GangliaReporter gangliaReporter = null; try { final GMetric ganglia = new GMetric(uri.getHost(), uri.getPort(), GMetric.UDPAddressingMode.MULTICAST, 1); gangliaReporter = GangliaReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .prefixedWith(configuration.getString(CK_PREFIX)) .build(ganglia); gangliaReporter.start(configuration.getInt(CK_RUN_RATE), TimeUnit.SECONDS); } catch (IOException e) { LOG.error("Can not connect to Ganglia server"); } return gangliaReporter; }
@Synchronized @Override public void start() { init(); if (conf.isEnableCSVReporter()) { // NOTE: metrics output files are exclusive to a given process File outdir; if (!Strings.isNullOrEmpty(conf.getMetricsPrefix())) { outdir = new File(conf.getCsvEndpoint(), conf.getMetricsPrefix()); } else { outdir = new File(conf.getCsvEndpoint()); } outdir.mkdirs(); log.info("Configuring stats with csv output to directory [{}]", outdir.getAbsolutePath()); reporters.add(CsvReporter.forRegistry(getMetrics()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(outdir)); } if (conf.isEnableStatsdReporter()) { log.info("Configuring stats with statsD at {}:{}", conf.getStatsDHost(), conf.getStatsDPort()); reporters.add(StatsDReporter.forRegistry(getMetrics()) .build(conf.getStatsDHost(), conf.getStatsDPort())); } if (conf.isEnableGraphiteReporter()) { log.info("Configuring stats with graphite at {}:{}", conf.getGraphiteHost(), conf.getGraphitePort()); final Graphite graphite = new Graphite(new InetSocketAddress(conf.getGraphiteHost(), conf.getGraphitePort())); reporters.add(GraphiteReporter.forRegistry(getMetrics()) .prefixedWith(conf.getMetricsPrefix()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(graphite)); } if (conf.isEnableJMXReporter()) { log.info("Configuring stats with jmx {}", conf.getJmxDomain()); final JmxReporter jmx = JmxReporter.forRegistry(getMetrics()) .inDomain(conf.getJmxDomain()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); jmx.start(); } if (conf.isEnableGangliaReporter()) { try { log.info("Configuring stats with ganglia at {}:{}", conf.getGangliaHost(), conf.getGangliaPort()); final GMetric ganglia = new GMetric(conf.getGangliaHost(), conf.getGangliaPort(), GMetric.UDPAddressingMode.MULTICAST, 1); reporters.add(GangliaReporter.forRegistry(getMetrics()) .prefixedWith(conf.getMetricsPrefix()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(ganglia)); } catch (IOException e) { log.warn("ganglia create failure: {}", e); } } if (conf.isEnableConsoleReporter()) { log.info("Configuring console reporter"); reporters.add(ConsoleReporter.forRegistry(getMetrics()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build()); } for (ScheduledReporter r : reporters) { r.start(conf.getStatsOutputFrequencySeconds(), TimeUnit.SECONDS); } }
@Inject public MetricsGangliaReporterService(GangliaReporter gangliaReporter, MetricsGangliaReporterConfiguration configuration) { this.gangliaReporter = requireNonNull(gangliaReporter); this.configuration = requireNonNull(configuration); }
public GangliaReporterLifecycle(GangliaReporter gangliaReporter) { _gangliaReporter = gangliaReporter; }