コード例 #1
0
ファイル: MetricManager.java プロジェクト: nickman/nash
  /**
   * Returns the named registry
   *
   * @param name the registry name
   * @param onf An optional ObjectNameFactory for this registry
   * @return the registry
   */
  public MetricRegistry getRegistry(final String name, final ObjectNameFactory onf) {
    if (name == null || name.trim().isEmpty())
      throw new IllegalArgumentException("Metric registry name was null");
    final String mname = name.trim();
    MetricRegistry m = subRegistries.get(mname);
    if (m == null) {
      synchronized (subRegistries) {
        m = subRegistries.get(mname);
        if (m == null) {
          m = new MetricRegistry();
          subRegistries.put(mname, m);
          final Builder builder =
              JmxReporter.forRegistry(m)
                  .inDomain("org.helios.nash.metrics")
                  .registerWith(JMXHelper.getHeliosMBeanServer());
          if (onf != null) {
            builder.createsObjectNamesWith(onf);
          }
          final JmxReporter reporter = builder.build();

          subReporters.put(mname, reporter);
          reporter.start();
        }
      }
    }
    return m;
  }
コード例 #2
0
 @PostConstruct
 public void init() {
   log.debug("Registering JVM gauges");
   metricRegistry.register(PROP_METRIC_REG_JVM_MEMORY, new MemoryUsageGaugeSet());
   metricRegistry.register(PROP_METRIC_REG_JVM_GARBAGE, new GarbageCollectorMetricSet());
   metricRegistry.register(PROP_METRIC_REG_JVM_THREADS, new ThreadStatesGaugeSet());
   metricRegistry.register(PROP_METRIC_REG_JVM_FILES, new FileDescriptorRatioGauge());
   metricRegistry.register(
       PROP_METRIC_REG_JVM_BUFFERS,
       new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
   if (jHipsterProperties.getMetrics().getJmx().isEnabled()) {
     log.debug("Initializing Metrics JMX reporting");
     JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
     jmxReporter.start();
   }
 }
コード例 #3
0
  @Override
  public void run(DataConfiguration configuration, Environment environment)
      throws ClassNotFoundException {
    JmxReporter.forRegistry(environment.metrics()).build().start();

    ObjectGraph objectGraph = ObjectGraph.create(new DataModule(environment, configuration));
    environment.healthChecks().register("data", objectGraph.get(DataHealthCheck.class));
    environment.jersey().register(objectGraph.get(TodoResource.class));
  }
コード例 #4
0
  @Override
  public void run() {
    final Level logLevel = setupLogger();

    final PluginBindings pluginBindings = installPluginConfigAndBindings(getPluginPath(configFile));

    if (isDumpDefaultConfig()) {
      dumpDefaultConfigAndExit();
    }

    final NamedConfigParametersModule configModule = readConfiguration(configFile);

    if (isDumpConfig()) {
      dumpCurrentConfigAndExit();
    }

    if (!validateConfiguration()) {
      LOG.error("Validating configuration file failed - exiting.");
      System.exit(1);
    }

    final List<String> arguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
    LOG.info("Running with JVM arguments: {}", Joiner.on(' ').join(arguments));

    injector = setupInjector(configModule, pluginBindings);

    if (injector == null) {
      LOG.error(
          "Injector could not be created, exiting! (Please include the previous error messages in bug reports.)");
      System.exit(1);
    }

    // This is holding all our metrics.
    final MetricRegistry metrics = injector.getInstance(MetricRegistry.class);

    addInstrumentedAppender(metrics, logLevel);

    // Report metrics via JMX.
    final JmxReporter reporter = JmxReporter.forRegistry(metrics).build();
    reporter.start();

    startCommand();
  }
コード例 #5
0
  @Override
  public void run(final MarketstemConfiguration configuration, final Environment environment)
      throws MalformedURLException, IOException {
    configureCrossOriginFilter(environment, "/*");

    registerResources(environment.jersey());
    registerProviders(environment.jersey());
    registerHealthChecks(environment);

    JmxReporter.forRegistry(environment.metrics()).build().start();
  }
コード例 #6
0
ファイル: MetricManager.java プロジェクト: nickman/nash
  /**
   * Closes the named registry
   *
   * @param name the registry name to close
   */
  public void closeRegistry(final String name) {
    if (name == null || name.trim().isEmpty())
      throw new IllegalArgumentException("Metric registry name was null");
    final String mname = name.trim();
    MetricRegistry m = subRegistries.remove(mname);
    if (m != null) {
      for (String metricName : m.getNames()) {
        m.remove(metricName);
      }
    }
    JmxReporter reporter = subReporters.remove(mname);
    if (reporter != null) {

      try {
        reporter.close();
      } catch (Exception x) {
        /* No Op */
      }
    }
  }
コード例 #7
0
  // -- MetricsConfigurerAdapter
  @Override
  public void configureReporters(MetricRegistry registry) {
    /* JVM metrics */
    registerAll("JVM.gc", new GarbageCollectorMetricSet(), registry);
    registerAll(
        "JVM.buffers",
        new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()),
        registry);
    registerAll("JVM.memory", new MemoryUsageGaugeSet(), registry);
    registerAll("JVM.threads", new ThreadStatesGaugeSet(), registry);

    /* reporter */
    if (Strings.isNullOrEmpty(statsdHostname)) {
      JmxReporter.forRegistry(registry).build().start();
    } else {
      StatsDReporter.forRegistry(registry)
          .prefixedWith(applicationName)
          .build(statsdHostname, statsdPort)
          .start(statsdPeriodSeconds, TimeUnit.SECONDS);
    }
  }
コード例 #8
0
ファイル: Metrics.java プロジェクト: GeorgeJahad/blueflood
  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();
  }
コード例 #9
0
ファイル: Metrics.java プロジェクト: pmbauer/quasar
 static {
   reporter = JmxReporter.forRegistry(metrics).build();
   reporter.start();
 }
 @Produces
 public MetricRegistry metricRegistry() {
   final MetricRegistry metricRegistry = new MetricRegistry();
   JmxReporter.forRegistry(metricRegistry).inDomain("uk.gov.justice.metrics").build().start();
   return metricRegistry;
 }
コード例 #11
0
 /**
  * @param queueSize
  * @param maxBatchSize
  */
 public CassandraBatchedStagedWriter(CassandraConnection connection, int batchSize) {
   super(Math.min(100000, batchSize * 100), batchSize);
   this.connection = requireNonNull(connection);
   final JmxReporter reporter = JmxReporter.forRegistry(metrics).inDomain("fooo.erer.er").build();
   reporter.start();
 }
コード例 #12
0
ファイル: CorePlugin.java プロジェクト: ryanrupp/stagemonitor
 private void reportToJMX(MetricRegistry metricRegistry, MetricFilter filter) {
   final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).filter(filter).build();
   reporter.start();
   reporters.add(reporter);
 }