/**
   * Initializes the Graphite reporter based on the current configuration.
   *
   * @param config the graphite reporter configuration
   */
  private void configureGraphiteReporter(GraphiteReporterConfig config) {
    if (config.isEnabled()) {
      Graphite graphite =
          new Graphite(new InetSocketAddress(config.getServerUri(), config.getServerPort()));

      String nodeName;

      try {
        InetAddress localhost = InetAddress.getLocalHost();
        nodeName = localhost.getHostName();
      } catch (UnknownHostException e) {
        nodeName = "UNKNOWN";
      }

      graphiteReporter =
          GraphiteReporter.forRegistry(metricRegistry)
              .prefixedWith(String.format("motech.%s", nodeName))
              .convertRatesTo(config.getConvertRates())
              .convertDurationsTo(config.getConvertDurations())
              .filter(MetricFilter.ALL)
              .build(graphite);

      graphiteReporter.start(config.getFrequency(), config.getFrequencyUnit());
    }
  }
 @Bean
 public GraphiteReporter graphiteReporter() {
   LOGGER.debug("Creating graphite reporter");
   final Graphite graphite = new Graphite(new InetSocketAddress("192.168.10.120", 2003));
   final GraphiteReporter reporter =
       GraphiteReporter.forRegistry(metricRegistry)
           .prefixedWith("KillrAuction")
           .convertRatesTo(TimeUnit.SECONDS)
           .convertDurationsTo(TimeUnit.MILLISECONDS)
           .filter(MetricFilter.ALL)
           .build(graphite);
   reporter.start(30, TimeUnit.SECONDS);
   return reporter;
 }
 @PostConstruct
 private void init() {
   if (jHipsterProperties.getMetrics().getGraphite().isEnabled()) {
     log.info("Initializing Metrics Graphite reporting");
     String graphiteHost = jHipsterProperties.getMetrics().getGraphite().getHost();
     Integer graphitePort = jHipsterProperties.getMetrics().getGraphite().getPort();
     String graphitePrefix = jHipsterProperties.getMetrics().getGraphite().getPrefix();
     Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
     GraphiteReporter graphiteReporter =
         GraphiteReporter.forRegistry(metricRegistry)
             .convertRatesTo(TimeUnit.SECONDS)
             .convertDurationsTo(TimeUnit.MILLISECONDS)
             .prefixedWith(graphitePrefix)
             .build(graphite);
     graphiteReporter.start(1, TimeUnit.MINUTES);
   }
 }
  private void reportToGraphite(
      MetricRegistry metricRegistry,
      long reportingInterval,
      MeasurementSession measurementSession,
      MetricFilter filter) {
    String graphiteHostName = getGraphiteHostName();
    if (isReportToGraphite()) {
      final GraphiteReporter graphiteReporter =
          GraphiteReporter.forRegistry(metricRegistry)
              .prefixedWith(getGraphitePrefix(measurementSession))
              .convertRatesTo(TimeUnit.SECONDS)
              .convertDurationsTo(TimeUnit.MILLISECONDS)
              .filter(filter)
              .build(new Graphite(new InetSocketAddress(graphiteHostName, getGraphitePort())));

      graphiteReporter.start(reportingInterval, TimeUnit.SECONDS);
      reporters.add(graphiteReporter);
    }
  }
 private MetricRegistry buildMetricRegistry() {
   metricRegistry = new MetricRegistry();
   // set graphite reporter
   final MovieTimeConfig.GraphiteConfig graphiteConfig = configuration.getGraphite();
   if (graphiteConfig.isActivate()) {
     final Graphite graphite =
         new Graphite(new InetSocketAddress(graphiteConfig.getHost(), graphiteConfig.getPort()));
     final GraphiteReporter graphiteReporter =
         GraphiteReporter.forRegistry(metricRegistry)
             .prefixedWith(graphiteConfig.getApiKey())
             .convertRatesTo(TimeUnit.SECONDS)
             .convertDurationsTo(TimeUnit.MILLISECONDS)
             .filter(MetricFilter.ALL)
             .build(graphite);
     graphiteReporter.start(1, TimeUnit.MINUTES);
     log.info("Metrics graphite reporter bootstrapped");
   } else {
     log.info("Metrics reporter not running");
   }
   return metricRegistry;
 }
    @PostConstruct
    private void init() {
      Boolean graphiteEnabled =
          propertyResolver.getProperty(PROP_GRAPHITE_ENABLED, Boolean.class, false);
      if (graphiteEnabled) {
        log.info("Initializing Metrics Graphite reporting");
        String graphiteHost = propertyResolver.getRequiredProperty(PROP_HOST);
        Integer graphitePort = propertyResolver.getRequiredProperty(PROP_PORT, Integer.class);
        String graphitePrefix =
            propertyResolver.getProperty(PROP_GRAPHITE_PREFIX, String.class, "");

        Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, graphitePort));
        GraphiteReporter graphiteReporter =
            GraphiteReporter.forRegistry(metricRegistry)
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .prefixedWith(graphitePrefix)
                .build(graphite);
        graphiteReporter.start(1, TimeUnit.MINUTES);
      }
    }
Exemple #7
0
  static {
    Configuration config = Configuration.getInstance();

    // register jvm metrics
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    if (!System.getProperty("java.version").split("\\.")[1].equals("6")) {
      // if not running 1.6
      registry.registerAll(
          new PrefixedMetricSet(new BufferPoolMetricSet(mbs), JVM_PREFIX, "buffer-pool"));
    }
    registry.registerAll(new PrefixedMetricSet(new GarbageCollectorMetricSet(), JVM_PREFIX, "gc"));
    registry.registerAll(new PrefixedMetricSet(new MemoryUsageGaugeSet(), JVM_PREFIX, "memory"));
    registry.registerAll(
        new PrefixedMetricSet(new ThreadStatesGaugeSet(), JVM_PREFIX, "thread-states"));

    // instrument log4j
    InstrumentedAppender appender = new InstrumentedAppender(registry);
    appender.activateOptions();
    LogManager.getRootLogger().addAppender(appender);

    if (!config.getStringProperty(CoreConfig.RIEMANN_HOST).equals("")) {
      RiemannReporter tmpreporter;
      try {
        Riemann riemann =
            new Riemann(
                config.getStringProperty(CoreConfig.RIEMANN_HOST),
                config.getIntegerProperty(CoreConfig.RIEMANN_PORT));

        RiemannReporter.Builder builder =
            RiemannReporter.forRegistry(registry)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .convertRatesTo(TimeUnit.SECONDS);
        if (!config.getStringProperty(CoreConfig.RIEMANN_SEPARATOR).isEmpty()) {
          builder.useSeparator(config.getStringProperty(CoreConfig.RIEMANN_SEPARATOR));
        }
        if (!config.getStringProperty(CoreConfig.RIEMANN_TTL).isEmpty()) {
          builder.withTtl(config.getFloatProperty(CoreConfig.RIEMANN_TTL));
        }
        if (!config.getStringProperty(CoreConfig.RIEMANN_LOCALHOST).isEmpty()) {
          builder.localHost(config.getStringProperty(CoreConfig.RIEMANN_LOCALHOST));
        }
        if (!config.getStringProperty(CoreConfig.RIEMANN_PREFIX).isEmpty()) {
          builder.prefixedWith(config.getStringProperty(CoreConfig.RIEMANN_PREFIX));
        }
        if (!config.getStringProperty(CoreConfig.RIEMANN_TAGS).isEmpty()) {
          builder.tags(config.getListProperty(CoreConfig.RIEMANN_TAGS));
        }
        tmpreporter = builder.build(riemann);

        tmpreporter.start(30l, TimeUnit.SECONDS);
      } catch (IOException e) {
        tmpreporter = null;
      }
      reporter1 = tmpreporter;
    } else {
      reporter1 = null;
    }

    if (!config.getStringProperty(CoreConfig.GRAPHITE_HOST).equals("")) {
      Graphite graphite =
          new Graphite(
              new InetSocketAddress(
                  config.getStringProperty(CoreConfig.GRAPHITE_HOST),
                  config.getIntegerProperty(CoreConfig.GRAPHITE_PORT)));

      reporter =
          GraphiteReporter.forRegistry(registry)
              .convertDurationsTo(TimeUnit.MILLISECONDS)
              .convertRatesTo(TimeUnit.SECONDS)
              .prefixedWith(config.getStringProperty(CoreConfig.GRAPHITE_PREFIX))
              .build(graphite);

      reporter.start(30l, TimeUnit.SECONDS);
    } else {
      reporter = null;
    }

    reporter2 =
        JmxReporter.forRegistry(registry)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .convertRatesTo(TimeUnit.SECONDS)
            .build();
    reporter2.start();
  }