簡體   English   中英

伺服monito注釋是否可以直接使用?

[英]Does servo monito annotation works out of the box?

我寫了這樣的方法:

@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 那么如何配置伺服/ spectacor使@Monitor注釋起作用?

注意

通過com.netflix.spectator.api.Registry報告其他指標的工作原理。 因此,通常,指標報告和伺服器本身都可以工作。

不,不是。 我認為您可以使用Monitors.newObjectMonitor(id, object)使其正常工作。 沒有方面或任何內容可以自動創建Monitor

據我了解,您需要注冊一個MonitorRegistryMetricPoller才能使@Monitor起作用:

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM