Java Code Examples for com.codahale.metrics.MetricRegistry#register()

The following examples show how to use com.codahale.metrics.MetricRegistry#register() . 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: MetricsEverywhereTest.java    From quarks with Apache License 2.0 6 votes vote down vote up
@Override
public final void initialize(OpletContext<T, T> context) {
    super.initialize(context);

    this.meter = new Meter();
    this.gauge = new Gauge<Long>() {
        @Override
        public Long getValue() {
            return System.currentTimeMillis();
        }
    };

    MetricRegistry registry = context.getService(MetricRegistry.class);
    if (registry != null) {
        registry.register(context.uniquify("testMeter"), meter);
        registry.register(context.uniquify("testGauge"), gauge);
    }
}
 
Example 2
Source File: MetricsCollectorHandler.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private AggregateMetric getOrCreate(MetricRegistry registry, String name) {
  AggregateMetric existing = (AggregateMetric)registry.getMetrics().get(name);
  if (existing != null) {
    return existing;
  }
  AggregateMetric add = new AggregateMetric();
  try {
    registry.register(name, add);
    return add;
  } catch (IllegalArgumentException e) {
    // someone added before us
    existing = (AggregateMetric)registry.getMetrics().get(name);
    if (existing == null) { // now, that is weird...
      throw new IllegalArgumentException("Inconsistent metric status, " + name);
    }
    return existing;
  }
}
 
Example 3
Source File: FeedQueues.java    From commafeed with Apache License 2.0 6 votes vote down vote up
@Inject
public FeedQueues(SessionFactory sessionFactory, FeedDAO feedDAO, CommaFeedConfiguration config, MetricRegistry metrics) {
	this.sessionFactory = sessionFactory;
	this.config = config;
	this.feedDAO = feedDAO;

	refill = metrics.meter(MetricRegistry.name(getClass(), "refill"));
	metrics.register(MetricRegistry.name(getClass(), "addQueue"), new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return addQueue.size();
		}
	});
	metrics.register(MetricRegistry.name(getClass(), "takeQueue"), new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return takeQueue.size();
		}
	});
	metrics.register(MetricRegistry.name(getClass(), "giveBackQueue"), new Gauge<Integer>() {
		@Override
		public Integer getValue() {
			return giveBackQueue.size();
		}
	});
}
 
Example 4
Source File: HelixParticipantMetrics.java    From ambry with Apache License 2.0 6 votes vote down vote up
HelixParticipantMetrics(MetricRegistry metricRegistry, String zkConnectStr,
    Map<String, ReplicaState> localPartitionAndState) {
  String zkSuffix = zkConnectStr == null ? "" : "-" + zkConnectStr;
  this.localPartitionAndState = localPartitionAndState;
  EnumSet.complementOf(EnumSet.of(ReplicaState.DROPPED)).forEach(state -> replicaCountByState.put(state, 0));
  Gauge<Integer> bootstrapPartitionCount = () -> getReplicaCountInState(ReplicaState.BOOTSTRAP);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "bootstrapPartitionCount" + zkSuffix),
      bootstrapPartitionCount);
  Gauge<Integer> standbyPartitionCount = () -> getReplicaCountInState(ReplicaState.STANDBY);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "standbyPartitionCount" + zkSuffix),
      standbyPartitionCount);
  Gauge<Integer> leaderPartitionCount = () -> getReplicaCountInState(ReplicaState.LEADER);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "leaderPartitionCount" + zkSuffix),
      leaderPartitionCount);
  Gauge<Integer> inactivePartitionCount = () -> getReplicaCountInState(ReplicaState.INACTIVE);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "inactivePartitionCount" + zkSuffix),
      inactivePartitionCount);
  Gauge<Integer> offlinePartitionCount = () -> getReplicaCountInState(ReplicaState.OFFLINE);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "offlinePartitionCount" + zkSuffix),
      offlinePartitionCount);
  Gauge<Integer> errorStatePartitionCount = () -> getReplicaCountInState(ReplicaState.ERROR);
  metricRegistry.register(MetricRegistry.name(HelixParticipant.class, "errorStatePartitionCount" + zkSuffix),
      errorStatePartitionCount);
  partitionDroppedCount =
      metricRegistry.counter(MetricRegistry.name(HelixParticipant.class, "partitionDroppedCount" + zkSuffix));
}
 
Example 5
Source File: OffsetMonitor.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
private void registerUpdateOffsetStatusMetric() {
  MetricRegistry metricRegistry = KafkaUReplicatorMetricsReporter.get().getRegistry();
  Gauge<Integer> gauge = new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return offsetMonitorFailureCount.get();
    }
  };
  try {
    metricRegistry.register(OFFSET_STATUS_FAILURE_COUNT_METRIC_NAME, gauge);
  } catch (Exception e) {
    logger.error(
        "Error while registering no progress metric " + OFFSET_STATUS_FAILURE_COUNT_METRIC_NAME,
        e);
  }
}
 
Example 6
Source File: SessionManager.java    From cruise-control with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Construct the session manager.
 * @param capacity the maximum of sessions allowed to exist at the same time.
 * @param sessionExpiryMs the maximum time to wait before expire an inactive session.
 * @param time the time object for unit test.
 * @param dropwizardMetricRegistry the metric registry to record metrics.
 */
SessionManager(int capacity,
               long sessionExpiryMs,
               Time time,
               MetricRegistry dropwizardMetricRegistry,
               Map<EndPoint, Timer> successfulRequestExecutionTimer) {
  _capacity = capacity;
  _sessionExpiryMs = sessionExpiryMs;
  _time = time;
  _inProgressSessions = new HashMap<>();
  _sessionCleaner.scheduleAtFixedRate(new ExpiredSessionCleaner(), 0, 5, TimeUnit.SECONDS);
  _successfulRequestExecutionTimer = successfulRequestExecutionTimer;
  // Metrics registration
  _sessionLifetimeTimer = dropwizardMetricRegistry.timer(MetricRegistry.name("SessionManager", "session-lifetime-timer"));
  _sessionCreationFailureMeter = dropwizardMetricRegistry.meter(MetricRegistry.name("SessionManager", "session-creation-failure-rate"));
  dropwizardMetricRegistry.register(MetricRegistry.name("SessionManager", "num-active-sessions"),
                                    (Gauge<Integer>) _inProgressSessions::size);

}
 
Example 7
Source File: MorphlineTest.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testMorphlineContext() throws Exception {
  ExceptionHandler ex = new ExceptionHandler() {      
    @Override
    public void handleException(Throwable t, Record record) {
      throw new RuntimeException(t);        
    }
  };
  
  MetricRegistry metricRegistry = new MetricRegistry();
  metricRegistry.register("myCounter", new Counter());
  
  HealthCheckRegistry healthChecks = new HealthCheckRegistry();
  healthChecks.register("foo", new HealthCheck() {      
    @Override
    protected Result check() throws Exception {
      return Result.healthy("flawless");
    }
  });

  Map<String,Object> settings = new HashMap<String,Object>(); 
  
  MorphlineContext ctx = new MorphlineContext.Builder()
    .setSettings(settings)
    .setExceptionHandler(ex)
    .setHealthCheckRegistry(healthChecks)
    .setMetricRegistry(metricRegistry)
    .build();
  
  assertSame(settings, ctx.getSettings());
  assertSame(ex, ctx.getExceptionHandler());
  assertSame(metricRegistry, ctx.getMetricRegistry());
  assertSame(healthChecks, ctx.getHealthCheckRegistry());
  ctx.getHealthCheckRegistry().runHealthChecks();
  
  assertEquals(0, new MorphlineContext.Builder().build().getSettings().size());
}
 
Example 8
Source File: MetricsModule.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton MetricRegistry provideMetrics() {
  MetricRegistry metrics = new MetricRegistry();
  metrics.register("jvm.memory", new MemoryUsageGaugeSet());
  metrics.register("jvm.garbage", new GarbageCollectorMetricSet());
  metrics.register("jvm.threads", new ThreadStatesGaugeSet());
  metrics.register("jvm.files", new FileDescriptorRatioGauge());
  metrics.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer()));
  return metrics;
}
 
Example 9
Source File: MetricsConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
/***
    * Initializes the metrics registry
    *
    * @return metric registry bean
    */
@Bean
public MetricRegistry metricRegistry() {
	final MetricRegistry bean = new MetricRegistry();

       // add JVM metrics
	bean.register("jvm.gc", new GarbageCollectorMetricSet());
	bean.register("jvm.memory", new MemoryUsageGaugeSet());
	bean.register("jvm.thread-states", new ThreadStatesGaugeSet());
	bean.register("jvm.fd", new FileDescriptorRatioGauge());

	return bean;
}
 
Example 10
Source File: MonitoringModule.java    From curiostack with MIT License 5 votes vote down vote up
private static void configureGitMetrics(MetricRegistry registry) {
  try {
    Properties gitProperties = new Properties();
    gitProperties.load(Resources.getResource("git.properties").openStream());
    for (String key : gitProperties.stringPropertyNames()) {
      String value = gitProperties.getProperty(key);
      registry.register(key, (Gauge<String>) () -> value);
    }
  } catch (IOException e) {
    // git properties missing, ignore.
  }
}
 
Example 11
Source File: HelixVcrClusterMetrics.java    From ambry with Apache License 2.0 5 votes vote down vote up
public HelixVcrClusterMetrics(MetricRegistry registry, Set<PartitionId> assignedPartitionIds) {
  partitionIdNotInClusterMapOnRemove =
      registry.counter(MetricRegistry.name(HelixVcrCluster.class, "PartitionIdNotInClusterMapOnRemove"));
  partitionIdNotInClusterMapOnAdd =
      registry.counter(MetricRegistry.name(HelixVcrCluster.class, "PartitionIdNotInClusterMapOnAdd"));
  numberOfAssignedPartitions = () -> assignedPartitionIds.size();
  registry.register(MetricRegistry.name(HelixVcrCluster.class, "NumberOfAssignedPartitions"),
      numberOfAssignedPartitions);
}
 
Example 12
Source File: ExecutorFacade.java    From HttpSessionReplacer with MIT License 5 votes vote down vote up
/**
 * Registers monitoring for {@link ThreadPoolExecutor} using passed {@link MetricRegistry}.
 *
 * @param name
 *          the prefix for the metrics
 * @param pool
 *          pool that is monitored
 * @param metrics
 *          registry used for metrics
 */
private void monitorTreadPoolExecutor(String name, final ThreadPoolExecutor pool, MetricRegistry metrics) {
  // If this was JDK 1.8+ only, this would use lambdas
  metrics.register(name(name, "active"), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return pool.getActiveCount();
    }
  });
  metrics.register(name(name, "largest"), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return pool.getLargestPoolSize();
    }
  });
  metrics.register(name(name, "pool"), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return pool.getPoolSize();
    }
  });
  metrics.register(name(name, "waiting"), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return pool.getQueue().size();
    }
  });
}
 
Example 13
Source File: BasicJvmMetrics.java    From signalfx-java with Apache License 2.0 4 votes vote down vote up
private Gauge<Integer> createIntegerPeriodicGauge(MetricRegistry metricRegistry, String name,
        Gauge<Integer> gauge) {
    return metricRegistry.register(name, gauge);
}
 
Example 14
Source File: LastActivityMetricsCollector.java    From fahrschein with Apache License 2.0 4 votes vote down vote up
private void createOrReplaceGauge(final MetricRegistry metricRegistry, final String gaugeName, final LongSupplier gaugeValueSupplier) {
    metricRegistry.remove(gaugeName);
    metricRegistry.register(gaugeName, (Gauge<Integer>) () -> (int) gaugeValueSupplier.getAsLong());
}
 
Example 15
Source File: SingularityS3UploaderMetrics.java    From Singularity with Apache License 2.0 4 votes vote down vote up
@Inject
public SingularityS3UploaderMetrics(
  MetricRegistry registry,
  @Named(METRICS_OBJECT_MAPPER) ObjectMapper mapper,
  SingularityS3Configuration baseConfiguration
) {
  super(registry, baseConfiguration, mapper);
  this.registry = registry;
  this.uploaderCounter = registry.counter(name("uploaders", "total"));
  this.immediateUploaderCounter = registry.counter(name("uploaders", "immediate"));
  this.uploadCounter = registry.counter(name("uploads", "success"));
  this.errorCounter = registry.counter(name("uploads", "errors"));
  this.uploadTimer = registry.timer(name("uploads", "timer"));

  this.expiring = Optional.empty();
  this.timeOfLastSuccessUpload = -1;

  registry.register(
    name("uploads", "millissincelast"),
    new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        if (timeOfLastSuccessUpload == -1) {
          return -1;
        }

        return Integer.valueOf(
          (int) (System.currentTimeMillis() - timeOfLastSuccessUpload)
        );
      }
    }
  );

  registry.register(
    name("uploads", "lastdurationmillis"),
    new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        return lastUploadDuration;
      }
    }
  );

  registry.register(
    name("uploaders", "expiring"),
    new Gauge<Integer>() {

      @Override
      public Integer getValue() {
        if (!expiring.isPresent()) {
          return 0;
        }

        return expiring.get().size();
      }
    }
  );

  this.filesystemEventsMeter = registry.meter(name("filesystem", "events"));

  startJmxReporter();
}
 
Example 16
Source File: HealthResource.java    From sofa-registry with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() {
    MetricRegistry metrics = new MetricRegistry();
    metrics.register("healthCheck", (Gauge<CommonResponse>) () -> getHealthCheckResult());
    ReporterUtils.startSlf4jReporter(60, metrics);
}
 
Example 17
Source File: InstrumentedThreadPoolExecutor.java    From monasca-common with Apache License 2.0 4 votes vote down vote up
InstrumentedThreadPoolExecutor(MetricRegistry metricRegistry, String name, int corePoolSize,
    int maximumPoolSize, long keepAliveTime, TimeUnit unit,
    final BlockingQueue<Runnable> workQueue, ThreadFactory factory) {
  super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, factory);
  this.name = name;
  requestRate = metricRegistry.meter(MetricRegistry.name(getClass(), name, "request"));
  rejectedRate = metricRegistry.meter(MetricRegistry.name(getClass(), name, "rejected"));
  executionTimer = metricRegistry.timer(MetricRegistry.name(getClass(), name, "execution"));
  metricRegistry.register(MetricRegistry.name(getClass(), name, "queue.size"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getQueue().size();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.count"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getPoolSize();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.active"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getActiveCount();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.idle"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getPoolSize() - getActiveCount();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.percent-active"),
      new RatioGauge() {
        @Override
        protected Ratio getRatio() {
          return Ratio.of(getPoolSize(), getActiveCount());
        }
      });

  setRejectedExecutionHandler(new RejectedExecutionHandler() {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      rejectedRate.mark();
      if (!workQueue.offer(r))
        log.warn("Thread pool {} rejected work.", InstrumentedThreadPoolExecutor.this.name);
      throw new RejectedExecutionException();
    }
  });
}
 
Example 18
Source File: MetricsConfigurator.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public static Gauge<Map<String, Object>> createFrameworkGauge(MetricRegistry metricRegistry, String componentName, String metricName, Comparator<String> comparator) {
  String fullName = JMX_FRAMEWORK_PREFIX + componentName + "." + metricName + GAUGE_SUFFIX;
  Gauge<Map<String, Object>> gauge = new MapGauge(comparator);
  return metricRegistry.register(fullName, gauge);
}
 
Example 19
Source File: NetworkMetrics.java    From ambry with Apache License 2.0 4 votes vote down vote up
public NetworkMetrics(MetricRegistry registry) {
  sendInFlight = registry.counter(MetricRegistry.name(Selector.class, "SendInFlight"));
  selectorConnectionClosed = registry.counter(MetricRegistry.name(Selector.class, "SelectorConnectionClosed"));
  selectorConnectionCreated = registry.counter(MetricRegistry.name(Selector.class, "SelectorConnectionCreated"));
  selectorSelectCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorSelectCount"));
  selectorIOCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorIOCount"));
  selectorReadyKeyCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorReadyKeyCount"));
  selectorPrepareKeyCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorPrepareKeyCount"));
  selectorReadKeyCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorReadKeyCount"));
  selectorWriteKeyCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorWriteKeyCount"));
  selectorSelectTime = registry.histogram(MetricRegistry.name(Selector.class, "SelectorSelectTime"));
  selectorIOTime = registry.histogram(MetricRegistry.name(Selector.class, "SelectorIOTime"));
  selectorNioCloseErrorCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorNioCloseErrorCount"));
  selectorDisconnectedErrorCount =
      registry.counter(MetricRegistry.name(Selector.class, "SelectorDisconnectedErrorCount"));
  selectorIOErrorCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorIoErrorCount"));
  selectorKeyOperationErrorCount =
      registry.counter(MetricRegistry.name(Selector.class, "SelectorKeyOperationErrorCount"));
  selectorCloseKeyErrorCount = registry.counter(MetricRegistry.name(Selector.class, "SelectorCloseKeyErrorCount"));
  selectorCloseSocketErrorCount =
      registry.counter(MetricRegistry.name(Selector.class, "SelectorCloseSocketErrorCount"));

  transmissionSendPendingTime =
      registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendPendingTime"));
  transmissionSendAllTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendAllTime"));
  transmissionRoundTripTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionRoundTripTime"));
  transmissionReceiveAllTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionReceiveAllTime"));
  transmissionSendBytesRate = registry.meter(MetricRegistry.name(Selector.class, "TransmissionSendBytesRate"));
  transmissionReceiveBytesRate = registry.meter(MetricRegistry.name(Selector.class, "TransmissionReceiveBytesRate"));
  transmissionSendTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendTime"));
  transmissionSendSize = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionSendSize"));
  transmissionReceiveTime = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionReceiveTime"));
  transmissionReceiveSize = registry.histogram(MetricRegistry.name(Selector.class, "TransmissionReceiveSize"));

  sslFactoryInitializationCount =
      registry.counter(MetricRegistry.name(Selector.class, "SslFactoryInitializationCount"));
  sslFactoryInitializationErrorCount =
      registry.counter(MetricRegistry.name(Selector.class, "SslFactoryInitializationErrorCount"));
  sslTransmissionInitializationCount =
      registry.counter(MetricRegistry.name(Selector.class, "SslTransmissionInitializationCount"));
  sslTransmissionInitializationErrorCount =
      registry.counter(MetricRegistry.name(Selector.class, "SslTransmissionInitializationErrorCount"));
  sslHandshakeTime = registry.histogram(MetricRegistry.name(Selector.class, "SslHandshakeTime"));
  sslHandshakeCount = registry.counter(MetricRegistry.name(Selector.class, "SslHandshakeCount"));
  sslHandshakeErrorCount = registry.counter(MetricRegistry.name(Selector.class, "SslHandshakeErrorCount"));
  sslRenegotiationCount = registry.counter(MetricRegistry.name(Selector.class, "SslRenegotiationCount"));
  sslEncryptionTimeInUsPerKB = registry.meter(MetricRegistry.name(Selector.class, "SslEncryptionTimeInUsPerKB"));
  sslDecryptionTimeInUsPerKB = registry.meter(MetricRegistry.name(Selector.class, "SslDecryptionTimeInUsPerKB"));

  networkClientSendAndPollTime =
      registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientSendAndPollTime"));
  networkClientRequestQueueTime =
      registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientRequestQueueTime"));
  networkClientRoundTripTime = registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientRoundTripTime"));
  networkClientTotalTime = registry.timer(MetricRegistry.name(NetworkClient.class, "NetworkClientTotalTime"));
  connectionCheckoutTimeoutError =
      registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionCheckoutTimeoutError"));
  connectionNotAvailable = registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionNotAvailable"));
  connectionReachLimit = registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionReachLimit"));
  connectionDisconnected = registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionDisconnected"));
  connectionReplenished = registry.counter(MetricRegistry.name(NetworkClient.class, "ConnectionReplenished"));
  networkClientIOError = registry.counter(MetricRegistry.name(NetworkClient.class, "NetworkClientIOError"));
  networkClientException = registry.counter(MetricRegistry.name(NetworkClient.class, "NetworkClientException"));

  selectorActiveConnectionsList = new ArrayList<>();
  selectorUnreadyConnectionsList = new ArrayList<>();
  networkClientPendingRequestList = new ArrayList<>();

  final Gauge<Long> selectorActiveConnectionsCount = () -> {
    long activeConnectionsCount = 0;
    for (AtomicLong activeConnection : selectorActiveConnectionsList) {
      activeConnectionsCount += activeConnection.get();
    }
    return activeConnectionsCount;
  };
  registry.register(MetricRegistry.name(Selector.class, "SelectorActiveConnectionsCount"),
      selectorActiveConnectionsCount);

  final Gauge<Long> selectorUnreadyConnectionsCount = () -> {
    long unreadyConnectionCount = 0;
    for (Set<String> unreadyConnection : selectorUnreadyConnectionsList) {
      unreadyConnectionCount += unreadyConnection.size();
    }
    return unreadyConnectionCount;
  };
  registry.register(MetricRegistry.name(Selector.class, "SelectorUnreadyConnectionsCount"),
      selectorUnreadyConnectionsCount);

  final Gauge<Long> networkClientPendingRequestsCount = () -> {
    long pendingRequestsCount = 0;
    for (AtomicLong pendingRequest : networkClientPendingRequestList) {
      pendingRequestsCount += pendingRequest.get();
    }
    return pendingRequestsCount;
  };
  registry.register(MetricRegistry.name(NetworkClient.class, "NetworkClientPendingConnectionsCount"),
      networkClientPendingRequestsCount);
}
 
Example 20
Source File: HealthResource.java    From sofa-registry with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void init() {
    MetricRegistry metrics = new MetricRegistry();
    metrics.register("healthCheck", (Gauge<CommonResponse>) () -> getHealthCheckResult());
    ReporterUtils.startSlf4jReporter(60, metrics);
}