info.ganglia.gmetric4j.gmetric.GMetric Java Examples

The following examples show how to use info.ganglia.gmetric4j.gmetric.GMetric. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GangliaReporter.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
@Override
protected void afterInit() {
  String server = metricsProperties.get(metricsPropertyKey + "server");
  String port = metricsProperties.get(metricsPropertyKey + "port");

  if(server == null || server.isEmpty()) {
    LOG.warn("No " + metricsPropertyKey + "server property in tajo-metrics.properties");
    return;
  }

  if(port == null || port.isEmpty()) {
    LOG.warn("No " + metricsPropertyKey + "port property in tajo-metrics.properties");
    return;
  }

  try {
    ganglia = new GMetric(server, Integer.parseInt(port), GMetric.UDPAddressingMode.MULTICAST, 1);
  } catch (Exception e) {
    LOG.warn(e.getMessage(), e);
  }
}
 
Example #2
Source File: GangliaReporter.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
protected void afterInit() {
  String server = metricsProperties.get(metricsPropertyKey + "server");
  String port = metricsProperties.get(metricsPropertyKey + "port");

  if(server == null || server.isEmpty()) {
    LOG.warn("No " + metricsPropertyKey + "server property in tajo-metrics.properties");
    return;
  }

  if(port == null || port.isEmpty()) {
    LOG.warn("No " + metricsPropertyKey + "port property in tajo-metrics.properties");
    return;
  }

  try {
    ganglia = new GMetric(server, Integer.parseInt(port), GMetric.UDPAddressingMode.MULTICAST, 1);
  } catch (Exception e) {
    LOG.warn(e.getMessage(), e);
  }
}
 
Example #3
Source File: GangliaMeterRegistry.java    From micrometer with Apache License 2.0 6 votes vote down vote up
private GangliaMeterRegistry(GangliaConfig config, Clock clock, HierarchicalNameMapper nameMapper, ThreadFactory threadFactory) {
    super(config, clock);

    // 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...
    this.config = config;
    this.nameMapper = nameMapper;
    config().namingConvention(NamingConvention.camelCase);

    try {
        this.ganglia = new GMetric(config.host(), config.port(), config.addressingMode(), config.ttl());
        start(threadFactory);
    } catch (IOException e) {
        throw new RuntimeException("Failed to configure Ganglia metrics reporting", e);
    }
}
 
Example #4
Source File: GMetricProviderTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void getReturnsGMetricUsingUnicast() throws Exception {
    final MetricsGangliaReporterConfiguration configuration = new MetricsGangliaReporterConfiguration() {
        @Override
        public GMetric.UDPAddressingMode getUDPAddressingMode() {
            return GMetric.UDPAddressingMode.UNICAST;
        }
    };
    final GMetricProvider provider = new GMetricProvider(configuration);

    final GMetric metric = provider.get();
    assertNotNull(metric);
}
 
Example #5
Source File: DefaultGangliaMetricsReporter.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #6
Source File: DefaultGangliaMetricsReporter.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Configures parameters for GMetric.
 */
private void configGMetric() {
    try {
        ganglia = new GMetric(address, port, GANGLIA_MODE, ttl);
    } catch (IOException e) {
        log.error("Fail to connect to given ganglia server!");
    }
}
 
Example #7
Source File: GangliaReporterProviderTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: GMetricProviderTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void getReturnsGMetricUsingMulticast() throws Exception {
    final MetricsGangliaReporterConfiguration configuration = new MetricsGangliaReporterConfiguration() {
        @Override
        public GMetric.UDPAddressingMode getUDPAddressingMode() {
            return GMetric.UDPAddressingMode.MULTICAST;
        }
    };
    final GMetricProvider provider = new GMetricProvider(configuration);

    final GMetric metric = provider.get();
    assertNotNull(metric);
}
 
Example #9
Source File: UDPAddressingModeConverter.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String convertTo(GMetric.UDPAddressingMode value) {
    if (value == null) {
        throw new ParameterException("Couldn't convert \"null\" to string.");
    }
    return value.name();
}
 
Example #10
Source File: UDPAddressingModeConverter.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public GMetric.UDPAddressingMode convertFrom(String value) {
    try {
        return GMetric.UDPAddressingMode.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        throw new ParameterException("Couldn't convert value \"" + value + "\" to UDP addressing mode.", e);
    }
}
 
Example #11
Source File: GMetricProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public GMetric get() {
    try {
        return new GMetric(
                configuration.getGroup(),
                configuration.getPort(),
                configuration.getUDPAddressingMode(),
                configuration.getTtl(),
                configuration.isGanglia31x(),
                configuration.getUUID(),
                configuration.getSpoof());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #12
Source File: GangliaReporterProvider.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public GangliaReporterProvider(MetricsGangliaReporterConfiguration configuration,
                               GMetric gMetric,
                               MetricRegistry metricRegistry) {
    this.configuration = requireNonNull(configuration);
    this.gMetric = requireNonNull(gMetric);
    this.metricRegistry = requireNonNull(metricRegistry);
}
 
Example #13
Source File: MetricsGangliaReporterConfiguration.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
public GMetric.UDPAddressingMode getUDPAddressingMode() {
    if (UDPAddressingMode == null) {
        try {
            return GMetric.UDPAddressingMode.getModeForAddress(getGroup());
        } catch (IOException e) {
            return GMetric.UDPAddressingMode.UNICAST;
        }
    } else {
        return UDPAddressingMode;
    }
}
 
Example #14
Source File: MetricsGangliaReporterModule.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(GMetric.class).toProvider(GMetricProvider.class);
    bind(GangliaReporter.class).toProvider(GangliaReporterProvider.class);

    addConfigBeans();
    addInitializer(MetricsGangliaReporterService.class);
}
 
Example #15
Source File: UDPAddressingModeConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertFromValidString() throws Exception {
    Assert.assertEquals(GMetric.UDPAddressingMode.MULTICAST, new UDPAddressingModeConverter().convertFrom("MULTICAST"));
}
 
Example #16
Source File: UDPAddressingModeConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertFromValidLowerCaseString() throws Exception {
    assertEquals(GMetric.UDPAddressingMode.UNICAST, new UDPAddressingModeConverter().convertFrom("unicast"));
}
 
Example #17
Source File: UDPAddressingModeConverterTest.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void convertTo() throws Exception {
    assertEquals("MULTICAST", new UDPAddressingModeConverter().convertTo(GMetric.UDPAddressingMode.MULTICAST));
}
 
Example #18
Source File: BookKeeperMetrics.java    From rubix with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize reporters for reporting metrics to desired services.
 */
protected void initializeReporters()
{
  final Iterable<String> metricsReporterNames = Splitter.on(",").trimResults().omitEmptyStrings().split(CacheConfig.getMetricsReporters(conf));

  final Set<MetricsReporter> metricsReporters = new HashSet<>();
  for (String reporterName : metricsReporterNames) {
    metricsReporters.add(MetricsReporter.valueOf(reporterName.toUpperCase()));
  }

  for (MetricsReporter reporter : metricsReporters) {
    switch (reporter) {
      case JMX:
        final JmxReporter jmxReporter = JmxReporter.forRegistry(metrics)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(metricsFilter)
            .build();

        log.debug("Reporting metrics to JMX");
        jmxReporter.start();
        reporters.add(jmxReporter);
        break;
      case STATSD:
        if (!CacheConfig.isOnMaster(conf)) {
          CacheConfig.setStatsDMetricsHost(conf, ClusterUtil.getMasterHostname(conf));
        }
        final StatsDReporter statsDReporter = StatsDReporter.forRegistry(metrics)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(metricsFilter)
            .build(CacheConfig.getStatsDMetricsHost(conf), CacheConfig.getStatsDMetricsPort(conf));

        log.debug(String.format("Reporting metrics to StatsD [%s:%d]", CacheConfig.getStatsDMetricsHost(conf), CacheConfig.getStatsDMetricsPort(conf)));
        statsDReporter.start(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS);
        reporters.add(statsDReporter);
        break;
      case GANGLIA:
        if (!CacheConfig.isOnMaster(conf)) {
          CacheConfig.setGangliaMetricsHost(conf, ClusterUtil.getMasterHostname(conf));
        }
        log.debug(String.format("Reporting metrics to Ganglia [%s:%s]", CacheConfig.getGangliaMetricsHost(conf), CacheConfig.getGangliaMetricsPort(conf)));
        final GMetric ganglia = new GMetric(CacheConfig.getGangliaMetricsHost(conf), CacheConfig.getGangliaMetricsPort(conf), GMetric.UDPAddressingMode.MULTICAST, 1);
        final GangliaReporter gangliaReporter = GangliaReporter.forRegistry(metrics)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .filter(metricsFilter)
                .build(ganglia);
        gangliaReporter.start(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS);
        reporters.add(gangliaReporter);
        break;
    }
  }
}
 
Example #19
Source File: GangliaConfig.java    From micrometer with Apache License 2.0 4 votes vote down vote up
default GMetric.UDPAddressingMode addressingMode() {
    return getEnum(this, GMetric.UDPAddressingMode.class, "addressingMode")
            .orElse(GMetric.UDPAddressingMode.MULTICAST);
}