本文整理匯總了Java中com.yammer.metrics.Metrics.defaultRegistry方法的典型用法代碼示例。如果您正苦於以下問題:Java Metrics.defaultRegistry方法的具體用法?Java Metrics.defaultRegistry怎麽用?Java Metrics.defaultRegistry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.yammer.metrics.Metrics
的用法示例。
在下文中一共展示了Metrics.defaultRegistry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildInfluxDBReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
private FilteredInfluxDBReporter buildInfluxDBReporter() {
FilteredInfluxDBReporter influxDBReporter = null;
influxDBReporter = new FilteredInfluxDBReporter(
Metrics.defaultRegistry(),
influxDBAddress,
influxDBDatabase,
influxDBRetentionPolicy,
influxDBUsername,
influxDBPassword,
influxDBConsistency,
influxDBTags,
metricDimensions,
Clock.defaultClock(),
VirtualMachineMetrics.getInstance()
);
return influxDBReporter;
}
示例2: init
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public void init(VerifiableProperties props) {
if(!initialized) {
KafkaMetricsConfig metricsConfig = new KafkaMetricsConfig(props);
InfluxDBMetricsConfig config = new InfluxDBMetricsConfig(props);
config.addTag("brokerId", props.getString("broker.id"));
this.reporter = new InfluxReporter(Metrics.defaultRegistry(), DEFAULT_NAME
,new InfluxDBClient(config), new MetricsPredicate(config.getPredicates()));
if (props.getBoolean(InfluxDBMetricsConfig.KAFKA_INFLUX_METRICS_ENABLE, false)) {
initialized = true;
startReporter(metricsConfig.pollingIntervalSecs());
LOG.info("KafkaInfluxMetricsReporter initialized.");
}
}
}
示例3: getStats
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@ManagedAttribute
public Map<String, Object> getStats() {
Map<String, Object> stats = new HashMap<String, Object>();
MetricsRegistry registry = Metrics.defaultRegistry();
for (Entry<MetricName, Metric> e : registry.allMetrics().entrySet()) {
MetricName name = e.getKey();
Metric metric = e.getValue();
if (metric instanceof Meter) {
Meter m = (Meter) metric;
stats.put(name.toString(), new MeterPOJO(m));
} else if (metric instanceof Gauge) {
Gauge<?> g = (Gauge<?>) metric;
stats.put(name.toString(), g.value());
}
}
return stats;
}
示例4: stopReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public synchronized void stopReporter() {
if (initialized && running) {
reporter.shutdown();
running = false;
LOG.info("Stopped Kafka Statsd metrics reporter");
try {
reporter = new StatsdReporter(
Metrics.defaultRegistry(),
statsdGroupPrefix,
predicate,
statsdHost,
statsdPort,
Clock.defaultClock()
);
} catch (IOException e) {
LOG.error("Unable to initialize StatsdReporter", e);
}
}
}
示例5: buildGraphiteReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
private FilteredGraphiteReporter buildGraphiteReporter() {
FilteredGraphiteReporter graphiteReporter = null;
try {
graphiteReporter = new FilteredGraphiteReporter(
Metrics.defaultRegistry(),
metricPrefix,
metricPredicate,
metricDimensions,
new FilteredGraphiteReporter.DefaultSocketProvider(graphiteHost, graphitePort),
Clock.defaultClock()
);
} catch (IOException e) {
LOG.error("Unable to initialize GraphiteReporter", e);
}
return graphiteReporter;
}
示例6: startReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public void startReporter(long pollingPeriodInSeconds) {
if (pollingPeriodInSeconds <= 0) {
throw new IllegalArgumentException("Polling period must be greater than zero");
}
synchronized (running) {
if (running.get()) {
log.warn("Reporter is already running");
} else {
statsd = createStatsd();
underlying = new StatsDReporter(
Metrics.defaultRegistry(),
statsd,
metricPredicate,
metricDimensions,
isTagEnabled);
underlying.start(pollingPeriodInSeconds, TimeUnit.SECONDS);
log.info("Started Reporter with host={}, port={}, polling_period_secs={}, prefix={}",
host, port, pollingPeriodInSeconds, prefix);
running.set(true);
}
}
}
示例7: init
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public synchronized void init(VerifiableProperties props) {
if (!initialized) {
KafkaMetricsConfig metricsConfig = new KafkaMetricsConfig(props);
statsdHost = props.getString("kafka.statsd.metrics.host", STATSD_DEFAULT_HOST).trim();
statsdPort = props.getInt("kafka.statsd.metrics.port", STATSD_DEFAULT_PORT);
statsdGroupPrefix = props.getString("kafka.statsd.metrics.group", STATSD_DEFAULT_PREFIX).trim();
String regex = props.getString("kafka.statsd.metrics.exclude.regex", null);
LOG.debug("Initialize StatsdReporter ["+statsdHost+","+statsdPort+","+statsdGroupPrefix+"]");
if (regex != null) {
predicate = new RegexMetricPredicate(regex);
}
try {
reporter = new StatsdReporter(
Metrics.defaultRegistry(),
statsdGroupPrefix,
predicate,
statsdHost,
statsdPort,
Clock.defaultClock()
);
} catch (IOException e) {
LOG.error("Unable to initialize StatsdReporter", e);
}
if (props.getBoolean("kafka.statsd.metrics.reporter.enabled", false)) {
initialized = true;
startReporter(metricsConfig.pollingIntervalSecs());
LOG.debug("StatsdReporter started.");
}
}
}
示例8: start
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@PostConstruct
public void start() {
try {
reporter =
new com.yammer.metrics.reporting.GraphiteReporter(
Metrics.defaultRegistry(), host, port, prefix);
reporter.start(period, periodUnit);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: stopReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public synchronized void stopReporter() {
if (initialized && running) {
// reporter.shutdown();
running = false;
LOG.info("Stopped Kafka Graphite metrics reporter");
try {
reporter = new GraphiteReporter(Metrics.defaultRegistry(), graphiteHost, graphitePort, graphiteGroupPrefix,
graphiteSuffix);
} catch (IOException e) {
LOG.error("Unable to initialize GraphiteReporter", e);
}
}
}
示例10: testServer
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Test
public void testServer() throws Exception {
final MetricsCommandProcessor commandProcessor = new MetricsCommandProcessor(
Metrics.defaultRegistry(),
new StaticMuninGraphProvider(Lists.<MuninGraph>newArrayList()),
mock(Hostname.class));
final int port = findFreePort();
final InetAddress loopback = InetAddress.getByName(null);
MuninServer sut = new MuninServer(commandProcessor, port, loopback);
sut.start();
Socket client = null;
for (int i = 0; i < 50; i++) {
try {
client = new Socket(loopback, port);
} catch (IOException e) {
Thread.sleep(10);
}
}
assertNotNull(client);
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String greeting = in.readLine();
assertTrue(greeting.startsWith("# Spotify munin node at"));
sut.shutdown();
client.close();
}
示例11: around
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Around(value = "timeChecked()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
MetricsRegistry registry = Metrics.defaultRegistry();
Timer timer = registry.newTimer(joinPoint.getThis().getClass(), joinPoint.getSignature().getName());
TimerContext time = timer.time();
try {
return joinPoint.proceed();
} finally {
time.stop();
}
}
示例12: dumpVmMetrics
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
/**
* Dumps JVM metrics for this process.
* @param incidentId incident id
*/
public static void dumpVmMetrics(String incidentId)
{
PrintWriter writer = null;
try
{
String dumpFile = EventUtil.getDumpPathPrefix() + "/" +
INC_DUMP_FILE_NAME + incidentId + INC_DUMP_FILE_EXT;
final OutputStream outStream =
new GZIPOutputStream(new FileOutputStream(dumpFile));
writer = new PrintWriter(outStream, true);
final VirtualMachineMetrics vm = VirtualMachineMetrics.getInstance();
writer.print("\n\n\n--------------------------- METRICS "
+ "---------------------------\n\n");
writer.flush();
JsonFactory jf = new JsonFactory();
jf.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
ObjectMapper mapper = new ObjectMapper(jf);
mapper.registerModule(new JodaModule());
mapper.setDateFormat(new ISO8601DateFormat());
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
MetricsServlet metrics = new MetricsServlet(Clock.defaultClock(),
vm,
Metrics.defaultRegistry(),
jf,
true);
final JsonGenerator json = jf.createGenerator(outStream,
JsonEncoding.UTF8);
json.useDefaultPrettyPrinter();
json.writeStartObject();
// JVM metrics
writeVmMetrics(json, vm);
// Components metrics
metrics.writeRegularMetrics(json, // json generator
null, // class prefix
false); // include full samples
json.writeEndObject();
json.close();
logger.debug("Creating full thread dump in dump file {}", dumpFile);
// Thread dump next....
writer.print("\n\n\n--------------------------- THREAD DUMP "
+ "---------------------------\n\n");
writer.flush();
vm.threadDump(outStream);
logger.debug("Dump file {} is created.", dumpFile);
}
catch(Exception exc)
{
logger.error(
"Unable to write dump file, exception: {}", exc.getMessage());
}
finally
{
if (writer != null)
{
writer.close();
}
}
}
示例13: init
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
@Override
public synchronized void init(VerifiableProperties props) {
if (!initialized) {
KafkaMetricsConfig metricsConfig = new KafkaMetricsConfig(props);
graphiteHost = props.getString("kafka.graphite.metrics.host", GRAPHITE_DEFAULT_HOST);
graphitePort = props.getInt("kafka.graphite.metrics.port", GRAPHITE_DEFAULT_PORT);
graphiteGroupPrefix = props.getString("kafka.graphite.metrics.env", GRAPHITE_DEFAULT_PREFIX);
System.setProperty("kafka.graphite.metrics.log.debug",
props.getString("kafka.graphite.metrics.log.debug", "false"));
System.setProperty("zookeeper.connect", props.getString("zookeeper.connect", "localhost:2181"));
System.setProperty("kafka.http.status.port", props.getString("kafka.http.status.port", "6091"));
System.setProperty("kafka.http.status.port", props.getString("kafka.http.status.port", "6091"));
System.setProperty("kafka.broker.datacenter", props.getString("kafka.broker.datacenter", "default"));
System.setProperty("kafka.broker.stats.sender", props.getString("kafka.broker.stats.sender", "false"));
hostMatch = props.getString("kafka.broker.stats.sender", "");
try {
graphiteSuffix = InetAddress.getLocalHost().getHostName().toLowerCase();
if (graphiteSuffix.contains(".")) {
String[] parts = graphiteSuffix.split("\\.");
graphiteSuffix = parts[0];
}
} catch (UnknownHostException e1) {
LOG.error(e1);
}
String regex = props.getString("kafka.graphite.metrics.exclude.regex", null);
LOG.info("Initialize GraphiteReporter [" + graphiteHost + "," + graphitePort + "," + graphiteGroupPrefix + "," + hostMatch + "]");
if (regex != null) {
predicate = new RegexMetricPredicate(regex);
}
try {
reporter = new GraphiteReporter(Metrics.defaultRegistry(), graphiteHost, graphitePort, graphiteGroupPrefix,
graphiteSuffix
);
} catch (IOException e) {
LOG.error("Unable to initialize GraphiteReporter", e);
}
if (props.getBoolean("kafka.graphite.metrics.reporter.enabled", false)) {
initialized = true;
startReporter(metricsConfig.pollingIntervalSecs());
LOG.debug("GraphiteReporter started.");
}
}
}
示例14: StatsdReporter
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
public StatsdReporter(String host, int port) throws IOException {
this(Metrics.defaultRegistry(), host, port, null);
}
示例15: enable
import com.yammer.metrics.Metrics; //導入方法依賴的package包/類
public static void enable() {
MemoryReporter memoryReporter = new MemoryReporter(Metrics.defaultRegistry(), "memory-reporter");
memoryReporter.start(1, TimeUnit.SECONDS);
}