Java Code Examples for com.alipay.lookout.api.composite.MixinMetric#counter()
The following examples show how to use
com.alipay.lookout.api.composite.MixinMetric#counter() .
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: MeasurableScheduler.java From sofa-lookout with Apache License 2.0 | 6 votes |
public MeasurableScheduler(final Registry registry, final String name, int poolSize) { super(poolSize, poolSize, 0, TimeUnit.NANOSECONDS, new DelayQueue(), newThreadFactory(name), new AbortPolicy()); this.registry = registry; Id mixinMetricId = registry.createId("lookout.scheduler." + name).withTag( LookoutConstants.TAG_PRIORITY_KEY, PRIORITY.LOW.name()); MixinMetric mixinMetric = registry.mixinMetric(mixinMetricId); mixinMetric.gauge("queueSize", new Gauge<Integer>() { @Override public Integer value() { return MeasurableScheduler.super.getQueue().size(); } }); activeCount = mixinMetric.counter("activeThreads"); taskExecutionTime = mixinMetric.timer("taskExecutionTime"); taskExecutionDelay = mixinMetric.timer("taskExecutionDelay"); skipped = mixinMetric.counter("skipped"); this.id = mixinMetricId; }
Example 2
Source File: AbstractExporter.java From sofa-lookout with Apache License 2.0 | 6 votes |
public AbstractExporter(String name, Registry registry, DataType type) { this.name = name; this.registry = registry; Map<String, String> tags = new HashMap<>(); tags.put("exporter", name); // 转成小写, 跟之前保持一致 tags.put("type", type.name().toLowerCase()); Id id = registry.createId("exporter.stats", tags); MixinMetric mm = registry.mixinMetric(id); // 统计导出个数(导出的metric条数) count = mm.counter("count"); // 统计导出次数(每次会导出多条) batch = mm.counter("batch"); // 统计失败次数 fail = mm.counter("fail"); // 统计请求耗时 time = mm.timer("time"); }
Example 3
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * Record the number of calls and time consuming. * * @param mixinMetric MixinMetric * @param model information model */ private void recordCounterAndTimer(MixinMetric mixinMetric, RpcAbstractLookoutModel model) { Counter totalCounter = mixinMetric.counter("total_count"); Timer totalTimer = mixinMetric.timer("total_time"); Long elapsedTime = model.getElapsedTime(); totalCounter.inc(); if (elapsedTime != null) { totalTimer.record(elapsedTime, TimeUnit.MILLISECONDS); } if (!model.getSuccess()) { Counter failCounter = mixinMetric.counter("fail_count"); Timer failTimer = mixinMetric.timer("fail_time"); failCounter.inc(); if (elapsedTime != null) { failTimer.record(elapsedTime, TimeUnit.MILLISECONDS); } } }
Example 4
Source File: AbstractWebfluxImporter.java From sofa-lookout with Apache License 2.0 | 5 votes |
@PostConstruct public void init() { Map<String, String> tags = new HashMap<>(); tags.put("importer", name); tags.put("type", "metric"); Id id = registry.createId("importer.stats", tags); MixinMetric mm = registry.mixinMetric(id); counter = mm.counter("count"); size = mm.distributionSummary("size"); }
Example 5
Source File: RegistryTest.java From sofa-lookout with Apache License 2.0 | 4 votes |
@Test public void testNoopRegistry() throws Exception { final Registry registry = NoopRegistry.INSTANCE; //counter Counter counter = registry.counter(registry.createId("counter")); counter.inc(); counter.dec(); counter.count(); //timer Timer timer = registry.timer(registry.createId("timer")); timer.record(2, TimeUnit.SECONDS); final AtomicInteger x = new AtomicInteger(0); timer.record(new Runnable() { @Override public void run() { x.incrementAndGet(); } }); timer.record(new Callable<Object>() { @Override public Object call() throws Exception { x.incrementAndGet(); return null; } }); Assert.assertEquals(2, x.intValue()); //ds DistributionSummary ds = registry.distributionSummary(registry.createId("ds")); ds.record(1); ds.count(); ds.totalAmount(); //gauge registry.gauge(registry.createId("gauge"), new Gauge<Integer>() { @Override public Integer value() { return 3; } }); registry.removeMetric(registry.createId("gauge")); //info registry.info(registry.createId("jvm.system.properties"), new Info<Map>() { @Override public Map value() { return System.getProperties(); } }); registry.info(registry.createId("sofa.config"), new AutoPollFriendlyInfo<Map<String, String>>() { @Override public AutoPollSuggestion autoPollSuggest() { // AutoPollSuggestion.NEVEL_AUTO_POLL; //AutoPollSuggestion.POLL_WHEN_UPDATED; //new AutoPollSuggestion(24, TimeUnit.DAYS); return AutoPollSuggestion.POLL_WHEN_UPDATED; } @Override public long lastModifiedTime() { return -1L; } @Override public Map<String, String> value() { return new HashMap(); } }); //minxin MixinMetric mixinMetric = registry.mixinMetric(registry.createId("mixinMetric")); Counter compCounter = mixinMetric.counter("xx"); Timer compTimer = mixinMetric.timer("time"); DistributionSummary compDs = mixinMetric.distributionSummary("ds"); mixinMetric.gauge("compGauge", new Gauge<Long>() { @Override public Long value() { return 1l; } }); }