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


Java MetricSet类代码示例

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


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

示例1: buildTimer

import com.codahale.metrics.MetricSet; //导入依赖的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: register

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
/**
 * Given a {@link Metric}, registers it under the given name.
 *
 * @param name   the name of the metric
 * @param metric the metric
 * @param <T>    the type of the metric
 * @return {@code metric}
 * @throws IllegalArgumentException if the name is already registered
 */
@SuppressWarnings("unchecked")
public final <T extends Metric> T register(final String name, final T metric)
throws IllegalArgumentException {
	if(metric instanceof MetricSet) {
		registerAll(name, (MetricSet) metric);
	} else {
		final Metric existing = metrics.putIfAbsent(name, metric);
		if(existing == null) {
			onMetricAdded(name, metric);
		} else {
			throw new IllegalArgumentException("A metric named " + name + " already exists");
		}
	}
	return metric;
}
 
开发者ID:emc-mongoose,项目名称:mongoose-base,代码行数:25,代码来源:CustomMetricRegistry.java

示例3: registerMetricSetImpl

import com.codahale.metrics.MetricSet; //导入依赖的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

示例4: removeMetricSetImpl

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
private void removeMetricSetImpl(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) {
                removeMetricSet(innerMetricSet, entry.getKey());
            } else {
                removeMetricSetImpl(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.remove(name);
        }
    }
}
 
开发者ID:centro,项目名称:monitoring-center,代码行数:26,代码来源:MetricCollectorImpl.java

示例5: getMetricSet

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public MetricSet getMetricSet() {
    Jenkins jenkins = Jenkins.getInstance();
    if (jenkins == null) {
        throw new AssertionError("Jenkins is missing");
    }
    HealthChecker c = jenkins.getExtensionList(PeriodicWork.class).get(HealthChecker.class);
    if (c == null) {
        throw new AssertionError("HealthChecker is missing");
    }
    return metrics(
            metric(name("jenkins", "health-check", "duration"), c.getHealthCheckDuration()),
            metric(name("jenkins", "health-check", "count"), c.getHealthCheckCount()),
            metric(name("jenkins", "health-check", "score"), c.getHealthCheckScore()),
            metric(name("jenkins", "health-check", "inverse-score"), new DerivativeGauge<Double, Double>(c.getHealthCheckScore()) {
                @Override
                protected Double transform(Double value) {
                    return value == null ? null : 1.0 - value;
                }
            })
    );
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:27,代码来源:Metrics.java

示例6: getMetricSet

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public MetricSet getMetricSet() {
    if (set == null || nextRefresh < System.currentTimeMillis()) {
        Map<String, Metric> metrics = new LinkedHashMap<String, Metric>();
        metrics.put(name("jenkins", "versions", "core"), new VersionGauge(Jenkins.VERSION));
        final Jenkins jenkins = Jenkins.getInstance();
        if (jenkins != null) {
            final PluginManager pluginManager = jenkins.getPluginManager();
            for (PluginWrapper p : pluginManager.getPlugins()) {
                if (p.isActive()) {
                    metrics.put(name("jenkins", "versions", "plugin", p.getShortName()),
                            new VersionGauge(p.getVersion()));
                }
            }
        }
        set = metrics(metrics); // idempotent
        nextRefresh = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15);
    }
    return set;
}
 
开发者ID:jenkinsci,项目名称:metrics-plugin,代码行数:25,代码来源:JenkinsVersionsProviderImpl.java

示例7: convert

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
public static Metric2Set convert(final MetricSet metricSet, final MetricNameConverter converter) {
	return new Metric2Set() {
		@Override
		public Map<MetricName, Metric> getMetrics() {
			final HashMap<MetricName, Metric> result = new HashMap<MetricName, Metric>();
			for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
				final MetricName convertedName;
				try {
					convertedName = converter.convert(entry.getKey());
					result.put(convertedName, entry.getValue());
				} catch (Exception e) {
					e.printStackTrace();
					logger.warn("Invalid name " + entry.getKey());
					logger.debug(e.getMessage(), e);
				}
			}
			return result;
		}
	};
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:21,代码来源:Metric2Set.java

示例8: register

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
/**
 * Given a {@link Metric}, registers it under the given name.
 *
 * @param name   the name of the metric
 * @param metric the metric
 * @param <T>    the type of the metric
 * @return {@code metric}
 * @throws IllegalArgumentException if the name is already registered
 */
@SuppressWarnings("unchecked")
public <T extends Metric> T register(MetricName name, T metric) throws IllegalArgumentException {
	if (metric instanceof MetricSet) {
		throw new IllegalArgumentException("This metrics registry is not compatible with MetricSets. Use a Metric2Set instead.");
	} else {
		final Metric existing = metrics.putIfAbsent(name, metric);
		if (existing != null) {
			throw new IllegalArgumentException("A metric named " + name + " already exists");
		}
		else {
			// This is a new metric - we have to register the Metric with
			// the legacy Dropwizard Metric registry as
			// well to support existing reports and listeners
			metricRegistry.register(name.toGraphiteName(), metric);
		}
	}
	return metric;
}
 
开发者ID:stagemonitor,项目名称:stagemonitor,代码行数:28,代码来源:Metric2Registry.java

示例9: configuration

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
private void configuration(@Observes AfterDeploymentValidation adv, BeanManager manager) {
    // Fire configuration event
    manager.fireEvent(configuration);
    configuration.unmodifiable();

    // Produce and register custom metrics
    MetricRegistry registry = getReference(manager, MetricRegistry.class);
    MetricName name = getReference(manager, MetricName.class);
    for (Map.Entry<Bean<?>, AnnotatedMember<?>> bean : metrics.entrySet()) {
        // TODO: add MetricSet metrics into the metric registry
        if (bean.getKey().getTypes().contains(MetricSet.class)
            // skip non @Default beans
            || !bean.getKey().getQualifiers().contains(DEFAULT)
            // skip producer methods with injection point
            || hasInjectionPoints(bean.getValue()))
            continue;
        registry.register(name.of(bean.getValue()), (Metric) getReference(manager, bean.getValue().getBaseType(), bean.getKey()));
    }

    // Let's clear the collected metric producers
    metrics.clear();
}
 
开发者ID:astefanutti,项目名称:metrics-cdi,代码行数:23,代码来源:MetricsExtension.java

示例10: registerAll

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
private void registerAll(String prefix, MetricSet metricSet, MetricRegistry registry) {
    for (Map.Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
        if (entry.getValue() instanceof MetricSet) {
            registerAll(prefix + "." + entry.getKey(), (MetricSet) entry.getValue(), registry);
        } else {
            registry.register(prefix + "." + entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:10,代码来源:JVMMetricsBean.java

示例11: buildCounter

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
public synchronized GoCounter buildCounter() {
    String name = generateName("counter");
    GoCounter counter = getExistingCounter(name);
    if (counter == null) {
        counter = new GoCounter(name);
        Map<String, Metric> map = new HashMap<>();
        map.put(name, counter);
        MetricSet set = () -> map;
        registry.registerAll(set);
    }
    return counter;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:13,代码来源:MetricBuilder.java

示例12: buildGauge

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
public synchronized GoGauge buildGauge() {
    String name = generateName("gauge");
    GoGauge gauge = getExistingGauge(name);
    if (gauge == null) {
        gauge = new GoGauge(name);
        Map<String, Metric> map = new HashMap<>();
        map.put(name, gauge);
        MetricSet set = () -> map;
        registry.registerAll(set);
    }
    return gauge;
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:13,代码来源:MetricBuilder.java

示例13: registerAll

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
private static void registerAll(String prefix, MetricSet metricSet, MetricRegistry registry) {
  for (Entry<String, Metric> entry : metricSet.getMetrics().entrySet()) {
    if (entry.getValue() instanceof MetricSet) {
      registerAll(prefix + "." + entry.getKey(), (MetricSet) entry.getValue(), registry);
    } else {
      registry.register(prefix + "." + entry.getKey(), entry.getValue());
    }
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:10,代码来源:DrillMetrics.java

示例14: scoped

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
private static MetricSet scoped(final String name, final MetricSet metricSet) {
  return new MetricSet() {
    @Override
    public Map<String, Metric> getMetrics() {
      ImmutableMap.Builder<String, Metric> scopedMetrics = ImmutableMap.builder();
      for(Map.Entry<String, Metric> entry: metricSet.getMetrics().entrySet()) {
        scopedMetrics.put(MetricRegistry.name(name, entry.getKey()), entry.getValue());
      }
      return scopedMetrics.build();
    }
  };
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:13,代码来源:Metrics.java

示例15: init

import com.codahale.metrics.MetricSet; //导入依赖的package包/类
@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;
			}
		});
	}
 
开发者ID:PacktPublishing,项目名称:Microservices-Deployment-Cookbook,代码行数:40,代码来源:MetricSystem.java


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