当前位置: 首页>>代码示例>>Java>>正文


Java Metric类代码示例

本文整理汇总了Java中com.codahale.metrics.Metric的典型用法代码示例。如果您正苦于以下问题:Java Metric类的具体用法?Java Metric怎么用?Java Metric使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Metric类属于com.codahale.metrics包,在下文中一共展示了Metric类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildTimer

import com.codahale.metrics.Metric; //导入依赖的package包/类
public synchronized GoTimer buildTimer() {
    String name = generateName("timing");
    GoTimer timer = getExistingTimer(name);
    if (timer == null) {
        timer = new GoTimer(name);
        Map<String, Metric> map = new HashMap<>(1);
        map.put(name, timer);
        MetricSet set = () -> map;
        try {
            registry.registerAll(set);
        } catch (Exception ex) {
            //I haven't figured out a good solution around this...
        }
    }
    return timer;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:17,代码来源:MetricBuilder.java

示例2: doGet

import com.codahale.metrics.Metric; //导入依赖的package包/类
@Override
public ModelAndView doGet(IHTTPSession session) {
	ModelAndView result = new ModelAndView();
	JsonArray array = new JsonArray();
	for (Entry<String, Metric> cur : ru.r2cloud.metrics.Metrics.REGISTRY.getMetrics().entrySet()) {
		JsonObject curObject = new JsonObject();
		curObject.add("id", cur.getKey());
		curObject.add("url", "/admin/static/rrd/" + cur.getKey() + ".rrd");
		if (cur.getValue() instanceof FormattedCounter) {
			curObject.add("format", ((FormattedCounter) cur.getValue()).getFormat().toString());
		}
		if (cur.getValue() instanceof FormattedGauge<?>) {
			curObject.add("format", ((FormattedGauge<?>) cur.getValue()).getFormat().toString());
		}
		array.add(curObject);
	}
	result.setData(array.toString());
	return result;
}
 
开发者ID:dernasherbrezon,项目名称:r2cloud,代码行数:20,代码来源:Metrics.java

示例3: testMetricSetAnnotations

import com.codahale.metrics.Metric; //导入依赖的package包/类
@Test
public void testMetricSetAnnotations() {
    Map<String, Metric> metrics = new TestLambdaMetricSet().getMetrics();

    // Prove that the defaults fall back to the classname as namespace, and field name as metric name.
    assertThat(metrics.get("io.symphonia.lambda.metrics.LambdaMetricSetTest.TestLambdaMetricSet/fooCounter"),
            instanceOf(Counter.class));

    // Prove we can override the name via the annotation
    assertThat(metrics.get("io.symphonia.lambda.metrics.LambdaMetricSetTest.TestLambdaMetricSet/myBarCounter"),
            instanceOf(Counter.class));

    // Prove we can override the namespace via the annotation
    assertThat(metrics.get("test.namespace/bazCounter"), instanceOf(Counter.class));

    // Prove we can override the namespace and name via the annotation
    assertThat(metrics.get("test.namespace/myBingCounter"), instanceOf(Counter.class));

    // Prove we can override the namespace via a class-level annotation
    assertThat(new NamespaceTestLambdaMetricSet().getMetrics().get("test.namespace/fooCounter"),
            instanceOf(Counter.class));
}
 
开发者ID:symphoniacloud,项目名称:lambda-monitoring,代码行数:23,代码来源:LambdaMetricSetTest.java

示例4: registerMetric

import com.codahale.metrics.Metric; //导入依赖的package包/类
static <T extends Metric> void registerMetric(final scala.Option<ActorRef> owner, final String metricName,
        final T metric) {
    if (owner.isEmpty()) {
       // there's no actor to monitor
        return;
    }

    String actorName = owner.get().path().toStringWithoutAddress();
    String fullName = MetricRegistry.name(actorName, metricName);

    MetricRegistry registry = MetricsReporter.getInstance(MeteringBehavior.DOMAIN).getMetricsRegistry();

    if (registry.getMetrics().containsKey(fullName)) {
        // already registered
        return;
    }

    try {
        registry.register(fullName, metric);
    } catch (IllegalArgumentException e) {
        // already registered - shouldn't happen here since we check above...
        LOG.debug("Unable to register '{}' in metrics registry: {}", e);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:25,代码来源:MeteredBoundedMailbox.java

示例5: installMXBean

import com.codahale.metrics.Metric; //导入依赖的package包/类
protected synchronized void installMXBean(final ObjectName objectName, final String name, String description, final Metric metric) {
	if(objectName==null) throw new IllegalArgumentException("The passed ObjectName was null");
	if(name==null || name.trim().isEmpty()) throw new IllegalArgumentException("The passed name was null or empty");
	if(metric==null) throw new IllegalArgumentException("The passed Metric was null");
	
	DropWizardMetrics dwm = objectNameMetrics.putIfAbsent(objectName, PLACEHOLDER);
	if(dwm==null || dwm==PLACEHOLDER) {
		dwm = new DropWizardMetrics(objectName, description);
		objectNameMetrics.replace(objectName, dwm);
		try {
			JMXHelper.registerMBean(dwm, objectName);
		} catch (Exception ex) {
			/* No Op ? */
			log.error("Error registering DWM: [{}]", objectName, ex);
		}
	}
	dwm.addMetric(metric, name, description);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:19,代码来源:SharedMetricsRegistry.java

示例6: handleMetrics

import com.codahale.metrics.Metric; //导入依赖的package包/类
private void handleMetrics(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
    String format = StringUtils.trimToNull(httpServletRequest.getParameter("format"));
    String[] startsWithFilters = httpServletRequest.getParameterValues("startsWithFilter");

    if (FORMAT_GRAPHITE.equalsIgnoreCase(format)) {
        httpServletResponse.setContentType(CONTENT_TYPE_TEXT_PLAIN);

        try (PrintWriter printWriter = httpServletResponse.getWriter()) {
            SortedMap<String, Metric> metricsByNames = MonitoringCenter.getMetricsByNames(true, startsWithFilters);
            printWriter.write(graphiteMetricFormatter.format(metricsByNames));
        }
    } else {
        boolean appendPrefix = Boolean.TRUE.toString().equalsIgnoreCase(StringUtils.trimToNull(httpServletRequest.getParameter("appendPrefix")));

        Map<String, SortedMap<String, ? extends Metric>> responseMap = new LinkedHashMap<>();
        responseMap.put("gauges", MonitoringCenter.getGaugesByNames(appendPrefix, startsWithFilters));
        responseMap.put("counters", MonitoringCenter.getCountersByNames(appendPrefix, startsWithFilters));
        responseMap.put("histograms", MonitoringCenter.getHistogramsByNames(appendPrefix, startsWithFilters));
        responseMap.put("meters", MonitoringCenter.getMetersByNames(appendPrefix, startsWithFilters));
        responseMap.put("timers", MonitoringCenter.getTimersByNames(appendPrefix, startsWithFilters));

        writeAsJson(httpServletRequest, httpServletResponse, responseMap);
    }
}
 
开发者ID:centro,项目名称:monitoring-center,代码行数:25,代码来源:MonitoringCenterServlet.java

示例7: processMetric

import com.codahale.metrics.Metric; //导入依赖的package包/类
private <A extends Annotation, T extends Metric> void processMetric(Class<?> targetClass,
                                                                    Method method,
                                                                    WatchdogRule rule,
                                                                    MetricAnnotationAccessor<A> annotationAccessor,
                                                                    MetricAdapter<T> metricAdapter) {
    A meteredAnn = method.getAnnotation(annotationAccessor.getAnnotationType());
    if(meteredAnn != null) {
        String name = MetricNameUtil.chooseName(annotationAccessor.getName(meteredAnn), annotationAccessor.isAbsoluteName(meteredAnn), targetClass, method);
        T meter = metricAdapter.getOrCreate(metricRegistry, name);
        if(meter == null) {
            LOG.warn("Can not find meter for name '{}'", name);
        } else {
            addLimitChecker(meter, rule, name);
        }
    }
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:17,代码来源:WatchdogAnnotationPostProcessor.java

示例8: automaticMetricCleanup2

import com.codahale.metrics.Metric; //导入依赖的package包/类
@Test
public void automaticMetricCleanup2() throws Exception {
    // Declare topology with custom metric oplet
    Topology t = newTopology();
    AtomicInteger n = new AtomicInteger(0);
    TStream<Integer> ints = t.poll(() -> n.incrementAndGet(), 10, TimeUnit.MILLISECONDS);
    TStream<Integer> ints2 = ints.pipe(new TestOplet<Integer>());
    ints2.pipe(new TestOplet<Integer>());

    // Submit job
    Future<? extends Job> fj = getSubmitter().submit(t);
    Job job = fj.get();
    Thread.sleep(TimeUnit.MILLISECONDS.toMillis(50));

    // Each test oplet registers two metrics 
    Map<String, Metric> all = metricRegistry.getMetrics();
    assertEquals(4, all.size());
    
    // After close all metrics have been unregistered 
    job.stateChange(Job.Action.CLOSE);
    assertEquals(0, all.size());
}
 
开发者ID:quarks-edge,项目名称:quarks,代码行数:23,代码来源:MetricsEverywhereTest.java

示例9: notifyListenerOfAddedMetric

import com.codahale.metrics.Metric; //导入依赖的package包/类
private void notifyListenerOfAddedMetric(
    final SemanticMetricRegistryListener listener, final Metric metric, final MetricId name
) {
    if (metric instanceof Gauge) {
        listener.onGaugeAdded(name, (Gauge<?>) metric);
    } else if (metric instanceof Counter) {
        listener.onCounterAdded(name, (Counter) metric);
    } else if (metric instanceof Histogram) {
        listener.onHistogramAdded(name, (Histogram) metric);
    } else if (metric instanceof Meter) {
        listener.onMeterAdded(name, (Meter) metric);
    } else if (metric instanceof Timer) {
        listener.onTimerAdded(name, (Timer) metric);
    } else if (metric instanceof DerivingMeter) {
        listener.onDerivingMeterAdded(name, (DerivingMeter) metric);
    } else {
        throw new IllegalArgumentException("Unknown metric type: " + metric.getClass());
    }
}
 
开发者ID:spotify,项目名称:semantic-metrics,代码行数:20,代码来源:SemanticMetricRegistry.java

示例10: testGetMetrics

import com.codahale.metrics.Metric; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Test
public void testGetMetrics() throws Exception {
    when(smaps.get(KEY.VSS)).thenReturn(1L);
    when(smaps.get(KEY.RSS)).thenReturn(2L);
    when(smaps.get(KEY.PSS)).thenReturn(3L);
    when(smaps.get(KEY.SWAP)).thenReturn(4L);
    when(smaps.get(KEY.SWAPPSS)).thenReturn(5L);

    final NativeMemoryUsageGaugeSet uut = new NativeMemoryUsageGaugeSet(smaps);

    final Map<String, Metric> metrics = uut.getMetrics();

    assertNotNull(metrics);
    assertEquals(5, metrics.keySet().size());
    assertTrue(metrics.keySet()
            .containsAll(Arrays.asList("vss", "rss", "pss", "swap", "swappss")));

    assertEquals(1L, ((Gauge) metrics.get("vss")).getValue());
    assertEquals(2L, ((Gauge) metrics.get("rss")).getValue());
    assertEquals(3L, ((Gauge) metrics.get("pss")).getValue());
    assertEquals(4L, ((Gauge) metrics.get("swap")).getValue());
    assertEquals(5L, ((Gauge) metrics.get("swappss")).getValue());
}
 
开发者ID:mweirauch,项目名称:metrics-jvm-extras,代码行数:25,代码来源:NativeMemoryUsageGaugeSetUnit0Test.java

示例11: setSessionManager

import com.codahale.metrics.Metric; //导入依赖的package包/类
/**
 * This method starts a separate thread that listens to key expirations
 * events.
 *
 * @param sessionManager
 */
@Override
public void setSessionManager(final SessionManager sessionManager) {
  this.sessionManager = sessionManager;
  MetricRegistry metrics = sessionManager.getMetrics();
  if (metrics != null) {
    // Cleanup old metrics related to this namespace
    metrics.removeMatching(new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        return name.startsWith(name(RedisConfiguration.METRIC_PREFIX, "redis"));
      }
    });
    if (sticky) {
      failoverMetrics = metrics.meter(name(RedisConfiguration.METRIC_PREFIX, namespace, "redis", "failover"));
    }

    redis.startMonitoring(metrics);
  }
  expirationManager.startExpiredSessionsTask(sessionManager);
}
 
开发者ID:AmadeusITGroup,项目名称:HttpSessionReplacer,代码行数:27,代码来源:RedisSessionRepository.java

示例12: invoke

import com.codahale.metrics.Metric; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see com.heliosapm.streams.jmx.metrics.MetricType.AttributeAdapter#invoke(com.codahale.metrics.Metric)
 */
@Override
public Object invoke(final Metric metric) {
	final Meter m = (Meter)metric;
	switch(this) {
		case RATE15M:
			return m.getFifteenMinuteRate();
		case RATE1M:
			return m.getOneMinuteRate();
		case RATE5M:
			return m.getFiveMinuteRate();
		case RATECOUNT:
			return m.getCount();
		case RATEMEAN:
			return m.getMeanRate();
		default:
			throw new RuntimeException();
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:23,代码来源:MetricType.java

示例13: getMetrics

import com.codahale.metrics.Metric; //导入依赖的package包/类
@SuppressWarnings("boxing")
@Override
public Map<String, Metric> getMetrics() {
  final Map<String, Metric> gauges = new HashMap<>();

  gauges.put("committedVirtualMemorySize", (Gauge<Long>) () -> invokeLong(committedVirtualMemorySize));
  gauges.put("totalSwapSpaceSize", (Gauge<Long>) () -> invokeLong(totalSwapSpaceSize));
  gauges.put("freeSwapSpaceSize", (Gauge<Long>) () -> invokeLong(freeSwapSpaceSize));
  gauges.put("processCpuTime", (Gauge<Long>) () -> invokeLong(processCpuTime));
  gauges.put("freePhysicalMemorySize", (Gauge<Long>) () -> invokeLong(freePhysicalMemorySize));
  gauges.put("totalPhysicalMemorySize", (Gauge<Long>) () -> invokeLong(totalPhysicalMemorySize));
  gauges.put("fd.usage", (Gauge<Double>) () -> invokeRatio(openFileDescriptorCount, maxFileDescriptorCount));
  gauges.put("systemCpuLoad", (Gauge<Double>) () -> invokeDouble(systemCpuLoad));
  gauges.put("processCpuLoad", (Gauge<Double>) () -> invokeDouble(processCpuLoad));

  return gauges;
}
 
开发者ID:Manfred73,项目名称:graphite-monitor-example,代码行数:18,代码来源:OperatingSystemGaugeSet.java

示例14: registerMetricSetImpl

import com.codahale.metrics.Metric; //导入依赖的package包/类
private void registerMetricSetImpl(MetricSet metricSet, String namespace) {
    for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }

        if (MetricSet.class.isInstance(entry.getValue())) {
            MetricSet innerMetricSet = MetricSet.class.cast(entry.getValue());
            if (namespace == null) {
                registerMetricSet(innerMetricSet, entry.getKey());
            } else {
                registerMetricSetImpl(innerMetricSet, MetricNamingUtil.join(namespace, entry.getKey()));
            }
        } else {
            String name = null;
            if (namespace == null) {
                name = entry.getKey();
            } else {
                name = MetricNamingUtil.join(namespace, entry.getKey());
            }
            name = addPostfixIfNeeded(name, getPostfixForMetric(entry.getValue()));
            metricRegistry.register(name, entry.getValue());
        }
    }
}
 
开发者ID:centro,项目名称:monitoring-center,代码行数:26,代码来源:MetricCollectorImpl.java

示例15: getMetrics

import com.codahale.metrics.Metric; //导入依赖的package包/类
@Override
public Map<String, Metric> getMetrics() {
    // these metrics are interesting to keep track of the effectiveness of the cache
    Map<String, Metric> metrics = new HashMap<>();
    String prefix = "redis."+keyPrefix.replace('/', '.');
    metrics.put(prefix+".get", getTimer);
    metrics.put(prefix+".mget", mgetTimer);
    metrics.put(prefix+".put", putTimer);
    metrics.put(prefix+".del", delTimer);
    metrics.put(prefix+".miss", missMeter);
    metrics.put(prefix+".hit", hitMeter);
    metrics.put(prefix+".notfound", notFoundMeter);
    Gauge<Double> hitRatioGauge = new Gauge<Double>() {

        @Override
        public Double getValue() {
            double getCount = getTimer.getCount();
            double hitCount = hitMeter.getCount();
            return hitCount/getCount;
        }
    };
    metrics.put(prefix+".hitratio", hitRatioGauge);

    return metrics;
}
 
开发者ID:Inbot,项目名称:inbot-es-http-client,代码行数:26,代码来源:RedisCache.java


注:本文中的com.codahale.metrics.Metric类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。