Пример #1
0
 public static void registerAll(MetricSet ms) throws IllegalArgumentException {
   metrics.registerAll(ms);
 }
Пример #2
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();
  }
Пример #3
0
 static {
   METRIC_REGISTRY = new MetricRegistry();
   METRIC_REGISTRY.registerAll(new GarbageCollectorMetricSet());
   METRIC_REGISTRY.registerAll(new MemoryUsageGaugeSet());
 }