Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I update a Gauge? #44

Open
danielamorais opened this issue Jun 21, 2019 · 1 comment
Open

How can I update a Gauge? #44

danielamorais opened this issue Jun 21, 2019 · 1 comment

Comments

@danielamorais
Copy link

The listener receives a Gauge and is necessary to persist in MetricManager. How can I update a Gauge inside MetricManager? At MetricRegistryImpl#register an exception "A metric named ... already exists" is thrown if I try to call MetricManager.register with the same metricName.

        CpuUsageService cpuUsageService = new CpuUsageServiceImpl(100L, 500L);
        cpuUsageService.addListener("foo.bar", cpu -> {
            SortedMap<MetricName, Gauge> gauges = MetricManager.getIMetricManager().getGauges(DUBBO_GROUP, MetricFilter.ALL);
            Gauge<Float> cpuUser = gauges.get(new MetricName("dubbo.cpu." + invoker.getUrl().getHost(), MetricLevel.MAJOR));
            if (cpuUser == null) {
                MetricName metricName = new MetricName("dubbo.cpu." + invoker.getUrl().getHost(), MetricLevel.MAJOR);
                MetricManager.register(DUBBO_GROUP, metricName, cpu);
            } else {
                //TODO: I need to update the Gauge here
            }
        });
@ralf0131
Copy link
Collaborator

If you want to update gauge, you need to keep the reference to that gauge, and provide a dedicate method to update it.

For example,

    class TestGauge implement Gauge {

        private int data;

        public void update() {
            // update here
        }

        public int getValue() {
 
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants