com.codahale.metrics.jvm.ClassLoadingGaugeSet Java Examples

The following examples show how to use com.codahale.metrics.jvm.ClassLoadingGaugeSet. 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: CloudWatchReporter.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
public CloudWatchReporter build() {

            if (withJvmMetrics) {
                metricRegistry.register("jvm.uptime", (Gauge<Long>) () -> ManagementFactory.getRuntimeMXBean().getUptime());
                metricRegistry.register("jvm.current_time", (Gauge<Long>) clock::getTime);
                metricRegistry.register("jvm.classes", new ClassLoadingGaugeSet());
                metricRegistry.register("jvm.fd_usage", new FileDescriptorRatioGauge());
                metricRegistry.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
                metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet());
                metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
                metricRegistry.register("jvm.thread-states", new ThreadStatesGaugeSet());
            }

            cwRateUnit = cwMeterUnit.orElse(toStandardUnit(rateUnit));
            cwDurationUnit = toStandardUnit(durationUnit);

            return new CloudWatchReporter(this);
        }
 
Example #2
Source File: SolrDispatchFilter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void setupJvmMetrics(CoreContainer coresInit)  {
  metricManager = coresInit.getMetricManager();
  registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
  final Set<String> hiddenSysProps = coresInit.getConfig().getMetricsConfig().getHiddenSysProps();
  try {
    metricManager.registerAll(registryName, new AltBufferPoolMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "buffers");
    metricManager.registerAll(registryName, new ClassLoadingGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "classes");
    metricManager.registerAll(registryName, new OperatingSystemMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "os");
    metricManager.registerAll(registryName, new GarbageCollectorMetricSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "gc");
    metricManager.registerAll(registryName, new MemoryUsageGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "memory");
    metricManager.registerAll(registryName, new ThreadStatesGaugeSet(), SolrMetricManager.ResolutionStrategy.IGNORE, "threads"); // todo should we use CachedThreadStatesGaugeSet instead?
    MetricsMap sysprops = new MetricsMap((detailed, map) -> {
      System.getProperties().forEach((k, v) -> {
        if (!hiddenSysProps.contains(k)) {
          map.put(String.valueOf(k), v);
        }
      });
    });
    metricManager.registerGauge(null, registryName, sysprops, metricTag, true, "properties", "system");
  } catch (Exception e) {
    log.warn("Error registering JVM metrics", e);
  }
}
 
Example #3
Source File: JVMMetrics.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static void addJvmMetrics(MetricRegistries registries) {
  MetricRegistryInfo info = new MetricRegistryInfo("jvm", "ratis_jvm", "jvm", "jvm metrics");

  RatisMetricRegistry registry = registries.create(info);

  registry.registerAll("gc", new GarbageCollectorMetricSet());
  registry.registerAll("memory", new MemoryUsageGaugeSet());
  registry.registerAll("threads", new ThreadStatesGaugeSet());
  registry.registerAll("classLoading", new ClassLoadingGaugeSet());
}
 
Example #4
Source File: MonitoringModule.java    From curiostack with MIT License 5 votes vote down vote up
private static void configureJvmMetrics(MetricRegistry registry) {
  MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
  registry.register("jvm.buffer-pool", new BufferPoolMetricSet(mBeanServer));
  registry.register("jvm.class-loading", new ClassLoadingGaugeSet());
  registry.register("jvm.file-descriptor-ratio", new FileDescriptorRatioGauge());
  registry.register("jvm.gc", new GarbageCollectorMetricSet());
  registry.register("jvm.memory", new MemoryUsageGaugeSet());
  registry.register("jvm.threads", new ThreadStatesGaugeSet());
}
 
Example #5
Source File: MetricSystem.java    From Microservices-Deployment-Cookbook with MIT License 5 votes vote down vote up
@PostConstruct
	public void init() {
		//		ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metricRegistry)
		//				.convertRatesTo(TimeUnit.SECONDS)
		//				.convertDurationsTo(TimeUnit.MILLISECONDS)
		//				.build();
		//
		//		consoleReporter.start(10, TimeUnit.SECONDS);

//		Graphite graphite = new Graphite(new InetSocketAddress("192.168.99.100", 2003));
//		GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metricRegistry)
//				.prefixedWith("com.packt.microservices.geolocation")
//				.convertRatesTo(TimeUnit.SECONDS)
//				.convertDurationsTo(TimeUnit.MILLISECONDS)
//				.filter(MetricFilter.ALL)
//				.build(graphite);
//		graphiteReporter.start(60, TimeUnit.SECONDS);


		geolocationWriteRequestCount = metricRegistry.counter("geolocationWriteRequestCount");
		metricRegistry.register("geolocationLastWriteTime", new Gauge<Long>() {
			@Override
			public Long getValue() {
				return geolocationLastWriteTime;
			}
		});

		metricRegistry.registerAll(new MetricSet() {
			@Override
			public Map<String, Metric> getMetrics() {

				Map<String, Metric> metrics = new HashMap<>();
				metrics.put("geolocationMemoryUsage", new MemoryUsageGaugeSet());
				metrics.put("geolocationClassLoading", new ClassLoadingGaugeSet());
				metrics.put("geolocationGarbageCollector", new GarbageCollectorMetricSet());
				return metrics;
			}
		});
	}
 
Example #6
Source File: GraphiteMetrics.java    From replicator with Apache License 2.0 5 votes vote down vote up
@Override
protected ScheduledReporter getReporter(Map<String, Object> configuration, MetricRegistry registry) {
    Object namespace = configuration.get(Configuration.GRAPHITE_NAMESPACE);
    Object hostname = configuration.get(Configuration.GRAPHITE_HOSTNAME);
    Object port = configuration.get(Configuration.GRAPHITE_PORT);

    Objects.requireNonNull(namespace, String.format("Configuration required: %s", Configuration.GRAPHITE_NAMESPACE));
    Objects.requireNonNull(hostname, String.format("Configuration required: %s", Configuration.GRAPHITE_HOSTNAME));
    Objects.requireNonNull(port, String.format("Configuration required: %s", Configuration.GRAPHITE_PORT));

    registry.register(MetricRegistry.name("jvm", "gc"), new GarbageCollectorMetricSet());
    registry.register(MetricRegistry.name("jvm", "threads"), new ThreadStatesGaugeSet());
    registry.register(MetricRegistry.name("jvm", "classes"), new ClassLoadingGaugeSet());
    registry.register(MetricRegistry.name("jvm", "fd"), new FileDescriptorRatioGauge());
    registry.register(MetricRegistry.name("jvm", "memory"), new MemoryUsageGaugeSet());

    ScheduledReporter reporter = GraphiteReporter
            .forRegistry(registry)
            .prefixedWith(namespace.toString())
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.SECONDS)
            .build(new Graphite(new InetSocketAddress(hostname.toString(), Integer.parseInt(port.toString()))));

    reporter.start(1L, TimeUnit.MINUTES);

    return reporter;
}
 
Example #7
Source File: DropWizardJVMMetrics.java    From james-project with Apache License 2.0 5 votes vote down vote up
public void start() {
    metricRegistry.register("jvm.file.descriptor", new FileDescriptorRatioGauge());
    metricRegistry.register("jvm.gc", new GarbageCollectorMetricSet());
    metricRegistry.register("jvm.threads", new ThreadStatesGaugeSet());
    metricRegistry.register("jvm.memory", new MemoryUsageGaugeSet());
    metricRegistry.register("jvm.class.loading", new ClassLoadingGaugeSet());
}
 
Example #8
Source File: DefaultMetricsService.java    From knox with Apache License 2.0 5 votes vote down vote up
private void registerJvmMetricSets() {
  metrics.registerAll(new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
  metrics.registerAll(new CachedThreadStatesGaugeSet(5, TimeUnit.MINUTES));
  metrics.registerAll(new ClassLoadingGaugeSet());
  metrics.registerAll(new GarbageCollectorMetricSet());
  metrics.registerAll(new JvmAttributeGaugeSet());
  metrics.registerAll(new MemoryUsageGaugeSet());
}
 
Example #9
Source File: SimCloudManager.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
SimCloudManager(TimeSource timeSource, SimDistribStateManager distribStateManager) throws Exception {
  this.loader = new SolrResourceLoader();
  if (distribStateManager == null) {
    this.stateManager =  new SimDistribStateManager(SimDistribStateManager.createNewRootNode());
    // init common paths
    stateManager.makePath(ZkStateReader.CLUSTER_PROPS);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_CONF_PATH);
    stateManager.makePath(ZkStateReader.LIVE_NODES_ZKNODE);
    stateManager.makePath(ZkStateReader.ROLES);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_EVENTS_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_TRIGGER_STATE_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_NODE_LOST_PATH);
    stateManager.makePath(ZkStateReader.SOLR_AUTOSCALING_NODE_ADDED_PATH);
    stateManager.makePath(Overseer.OVERSEER_ELECT);
  } else {
    this.stateManager = distribStateManager;
  }

  // register common metrics
  metricTag = Integer.toHexString(hashCode());
  String registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.jvm);
  metricManager.registerAll(registryName, new AltBufferPoolMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "buffers");
  metricManager.registerAll(registryName, new ClassLoadingGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "classes");
  metricManager.registerAll(registryName, new OperatingSystemMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "os");
  metricManager.registerAll(registryName, new GarbageCollectorMetricSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "gc");
  metricManager.registerAll(registryName, new MemoryUsageGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "memory");
  metricManager.registerAll(registryName, new ThreadStatesGaugeSet(), SolrMetricManager.ResolutionStrategy.REPLACE, "threads"); // todo should we use CachedThreadStatesGaugeSet instead?
  MetricsMap sysprops = new MetricsMap((detailed, map) -> {
    System.getProperties().forEach((k, v) -> {
      map.put(String.valueOf(k), v);
    });
  });
  metricManager.registerGauge(null, registryName, sysprops, metricTag, true, "properties", "system");

  registryName = SolrMetricManager.getRegistryName(SolrInfoBean.Group.node);
  metricManager.registerGauge(null, registryName, () -> new File("/").getUsableSpace(),
      metricTag, true, "usableSpace", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot");

  solrClient = new MockSearchableSolrClient() {
    @Override
    @SuppressWarnings({"rawtypes"})
    public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException {
      if (collection != null) {
        if (request instanceof AbstractUpdateRequest) {
          ((AbstractUpdateRequest)request).setParam("collection", collection);
        } else if (request instanceof QueryRequest) {
          if (request.getPath() != null && (
              request.getPath().startsWith("/admin/autoscaling") ||
              request.getPath().startsWith("/cluster/autoscaling") ||
          request.getPath().startsWith("/admin/metrics/history") ||
              request.getPath().startsWith("/cluster/metrics/history")
          )) {
            // forward it
            ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
            params.set("collection", collection);
            request = new QueryRequest(params);
          } else {
            // search request
            if (collection.equals(CollectionAdminParams.SYSTEM_COLL)) {
              return super.request(request, collection);
            } else {
              // forward it
              ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
              params.set("collection", collection);
              request = new QueryRequest(params);
            }
          }
        } else {
          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "when collection != null only UpdateRequest and QueryRequest are supported: request=" + request + ", collection=" + collection);
        }
      }
      try {
        SolrResponse rsp = SimCloudManager.this.request(request);
        return rsp.getResponse();
      } catch (UnsupportedOperationException e) {
        throw new SolrServerException(e);
      }
    }
  };


  this.timeSource = timeSource != null ? timeSource : TimeSource.NANO_TIME;
  this.clusterStateProvider = new SimClusterStateProvider(liveNodesSet, this);
  this.nodeStateProvider = new SimNodeStateProvider(liveNodesSet, this.stateManager, this.clusterStateProvider, null);
  this.queueFactory = new GenericDistributedQueueFactory(stateManager);
  this.simCloudManagerPool = ExecutorUtil.newMDCAwareFixedThreadPool(200, new SolrNamedThreadFactory("simCloudManagerPool"));

  this.autoScalingHandler = new AutoScalingHandler(this, loader);


  triggerThreadGroup = new ThreadGroup("Simulated Overseer autoscaling triggers");
  OverseerTriggerThread trigger = new OverseerTriggerThread(loader, this);
  triggerThread = new Overseer.OverseerThread(triggerThreadGroup, trigger, "Simulated OverseerAutoScalingTriggerThread");
  triggerThread.start();
}