TheDubiousDubber
TheDubiousDubber

Reputation: 369

Spring Boot/Micrometer sending metrics to GCP Stackdriver

I'm trying to implement a simple solution to send http request metrics to Stackdriver in GCP from my API hosted in a compute engine instance. Using recent version of Spring Boot (2.1.5). I've also pulled in actuator and micrometer-registry-stackdriver packages, actuator works for health endpoint at the moment, but am unclear on how to implement metrics for this.

In the past (separate project, different stack), I mostly used the auto-configured elements with influx. Using management.metrics.export.influx.enabled=true, and some other properties in properties file, it was a pretty simple setup (though it is quite possible the lead on my team did some of the heavy lifting while I wasn't aware). Despite pulling in the stackdriver dependency I don't see any type of properties for stackdriver. Documentation is all generalized, so I'm unclear on how to do this for my use case. I've searched for examples and can find none.

From the docs: Having a dependency on micrometer-registry-{system} in your runtime classpath is enough for Spring Boot to configure the registry. I'm a bit of a noob, so I'm not sure what I need to do to get this to work. I don't need any custom metrics really, just trying to get some metrics data to show up.

Does anyone have or know of any examples in setting this up to work with Stackdriver?

Upvotes: 1

Views: 5146

Answers (3)

dan carter
dan carter

Reputation: 4341

Prior to spring-boot 2.3 StackDriver is not supported out of the box, but it's not much configuration to make it work.

@Bean
StackdriverConfig stackdriverConfig() {
    return new StackdriverConfig() {
        @Override
        public String projectId() {
            return MY_PROJECT_ID;
        }

        @Override
        public String get(String key) {
            return null;
        }
    }
}

@Bean
StackdriverMeterRegistry meterRegistry(StackdriverConfig stackdriverConfig) {
    return StackdriverMeterRegistry.builder(stackdriverConfig).build();
}

https://micrometer.io/docs/registry/stackdriver

Upvotes: 1

Bruno
Bruno

Reputation: 401

From my understanding, you try to monitor a 3rd party software that you built and get the results in GCP Stackdriver? If that’s right, I would like to suggest you to implement the stackdriver monitoring agent [1] on your VM instance, including the Stackdriver API output plugin. This agent gathers system and 3rd party application metrics and pushes the information to a monitoring system like Stackdriver.

The Stackdriver Monitoring Agent is based on the open-source “collectd” daemon so let me share some more precious documentation from its website [2].

Upvotes: 0

Ashik Mahbub
Ashik Mahbub

Reputation: 176

It seems like the feature for enabling Stackdriver Monitoring for COS is currently in Alpha. If you are down to try GCE COS VM with the agent, you can request access via this form .Curiously, I was able to install monitoring agent during instance creation as a test. I used COS image : Container-Optimized OS 75-12105.97.0 stable.

Inspecting COS, collect d agent seems to be installed here :/etc/stackdriver/monitoring.config.d and

Inspecting my monitoring Agent dashboard, I can see activity from the VM (CPU usage, etc.). I'm not sure if this is what you're trying to achieve but hopefully it points you in the right direction.

Upvotes: 0

Related Questions