伺服监控器注释是否可以开箱即用?

时间:2017-01-26 07:15:31

标签: java spring spring-cloud netflix-servo

我写了一个类似的方法:

@Scheduled(fixedDelay = 10_000)
@Monitor(name = "componentMonitor", type = DataSourceType.COUNTER)
public int method() {
    log.info("ping");
    return RandomUtils.nextInt();
}

它已被调用,ping出现在控制台中,但componentMonitor未显示在/metrics中,此指标未发送到org.springframework.boot.actuate.autoconfigure.ExportMetricReader。那么如何使用@Monitor注释配置伺服/观察工作呢?

注意

通过com.netflix.spectator.api.Registry报告其他指标。因此,通常度量报告和伺服本身都可以工作。

2 个答案:

答案 0 :(得分:1)

不,它没有。我认为您可以使用Monitor来使其发挥作用。没有任何方面或任何内容可以自动创建http://api.nal.usda.gov/ndb/search/?format=json&q=us&sort=n&max=25&offset=0&api_key=h9TKX24GP1vDETSUfQc2hU8b4w3orECoocoQFeE7

答案 1 :(得分:0)

我的理解是你需要为@Monitor注册MonitorRegistryMetricPoller才能工作:

private void schedule(MetricPoller poller, List<MetricObserver> observers) {
    final PollRunnable task = new PollRunnable(poller, BasicMetricFilter.MATCH_ALL,
            true, observers);
    PollScheduler.getInstance().addPoller(task, 1, TimeUnit.MINUTES);
}

private void initMetricsPublishing() {
    final List<MetricObserver> observers = new ArrayList<>();

    final AmazonCloudWatchClient cloudWatchClient =
            new AmazonCloudWatchClient(awsCredentials);
    cloudWatchClient.setEndpoint(String.format("monitoring.%s.amazonaws.com", REGION));
    AwsTaggingCloudWatchMetricObserver cloudWatchMetricObserver = new AwsTaggingCloudWatchMetricObserver("cloudwatch",
            "Nomp", cloudWatchClient);
    observers.add(cloudWatchMetricObserver);
    PollScheduler.getInstance().start();
    schedule(new MonitorRegistryMetricPoller(), observers);  // <--- this
    schedule(new JvmMetricPoller(), observers);
    schedule(new TomcatPoller(), observers);
}