下面列出了怎么用com.codahale.metrics.jvm.CachedThreadStatesGaugeSet的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* ThreadStatesGaugeSet & ClassLoadingGaugeSet are currently not registered.
* metricRegistry.register("threads", new ThreadStatesGaugeSet());
*/
private StreamingMetrics() {
if (METRICS_OPTION != null && !METRICS_OPTION.isEmpty()) {
metricRegistry.register("gc", new GarbageCollectorMetricSet());
metricRegistry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS));
metricRegistry.register("memory", new MemoryUsageGaugeSet());
}
}
/**
* Register desired metrics.
*
* @param conf The current Hadoop configuration.
*/
private static void registerMetrics(Configuration conf)
{
bookKeeperMetrics = new BookKeeperMetrics(conf, metrics);
metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_GC_PREFIX.getMetricName(), new GarbageCollectorMetricSet());
metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_THREADS_PREFIX.getMetricName(), new CachedThreadStatesGaugeSet(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS));
metrics.register(BookKeeperMetrics.LDTSJvmMetric.LDTS_JVM_MEMORY_PREFIX.getMetricName(), new MemoryUsageGaugeSet());
}
/**
* Register desired metrics.
*/
protected void registerMetrics(Configuration conf)
{
metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_GC_PREFIX.getMetricName(), new GarbageCollectorMetricSet());
metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_THREADS_PREFIX.getMetricName(), new CachedThreadStatesGaugeSet(CacheConfig.getMetricsReportingInterval(conf), TimeUnit.MILLISECONDS));
metrics.register(BookKeeperMetrics.BookKeeperJvmMetric.BOOKKEEPER_JVM_MEMORY_PREFIX.getMetricName(), new MemoryUsageGaugeSet());
}
/**
* ThreadStatesGaugeSet & ClassLoadingGaugeSet are currently not registered.
* metricRegistry.register("threads", new ThreadStatesGaugeSet());
*/
private StreamingMetrics() {
if (METRICS_OPTION != null && !METRICS_OPTION.isEmpty()) {
metricRegistry.register("gc", new GarbageCollectorMetricSet());
metricRegistry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS));
metricRegistry.register("memory", new MemoryUsageGaugeSet());
}
}
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());
}
AsyncBenchmark(Configuration cfg) {
client = new AsyncDocumentClient.Builder()
.withServiceEndpoint(cfg.getServiceEndpoint())
.withMasterKeyOrResourceToken(cfg.getMasterKey())
.withConnectionPolicy(cfg.getConnectionPolicy())
.withConsistencyLevel(cfg.getConsistencyLevel())
.build();
logger = LoggerFactory.getLogger(this.getClass());
Database database = DocDBUtils.getDatabase(client, cfg.getDatabaseId());
collection = DocDBUtils.getCollection(client, database.getSelfLink(), cfg.getCollectionId());
nameCollectionLink = String.format("dbs/%s/colls/%s", database.getId(), collection.getId());
partitionKey = collection.getPartitionKey().getPaths().iterator().next().split("/")[1];
concurrencyControlSemaphore = new Semaphore(cfg.getConcurrency());
configuration = cfg;
ArrayList<Observable<Document>> createDocumentObservables = new ArrayList<>();
if (configuration.getOperationType() != Operation.WriteLatency
&& configuration.getOperationType() != Operation.WriteThroughput
&& configuration.getOperationType() != Operation.ReadMyWrites) {
String dataFieldValue = RandomStringUtils.randomAlphabetic(cfg.getDocumentDataFieldSize());
for (int i = 0; i < cfg.getNumberOfPreCreatedDocuments(); i++) {
String uuid = UUID.randomUUID().toString();
Document newDoc = new Document();
newDoc.setId(uuid);
newDoc.set(partitionKey, uuid);
newDoc.set("dataField1", dataFieldValue);
newDoc.set("dataField2", dataFieldValue);
newDoc.set("dataField3", dataFieldValue);
newDoc.set("dataField4", dataFieldValue);
newDoc.set("dataField5", dataFieldValue);
Observable<Document> obs = client.createDocument(collection.getSelfLink(), newDoc, null, false)
.map(ResourceResponse::getResource);
createDocumentObservables.add(obs);
}
}
docsToRead = Observable.merge(createDocumentObservables, 100).toList().toBlocking().single();
init();
if (configuration.isEnableJvmStats()) {
metricsRegistry.register("gc", new GarbageCollectorMetricSet());
metricsRegistry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS));
metricsRegistry.register("memory", new MemoryUsageGaugeSet());
}
if (configuration.getGraphiteEndpoint() != null) {
final Graphite graphite = new Graphite(new InetSocketAddress(configuration.getGraphiteEndpoint(),
configuration.getGraphiteEndpointPort()));
reporter = GraphiteReporter.forRegistry(metricsRegistry)
.prefixedWith(configuration.getOperationType().name())
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.filter(MetricFilter.ALL)
.build(graphite);
} else {
reporter = ConsoleReporter.forRegistry(metricsRegistry).convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS).build();
}
MeterRegistry registry = configuration.getAzureMonitorMeterRegistry();
if (registry != null) {
AsyncDocumentClient.monitor(registry);
}
registry = configuration.getGraphiteMeterRegistry();
if (registry != null) {
AsyncDocumentClient.monitor(registry);
}
}