简体   繁体   中英

Is there a way to monitor to Java app running in Docker container in Google Cloud Run with Java JMX Stackdriver plugin?

I'm trying to collect metrics with DropWizard metrics library and export them through JMX.

On Google Cloud Engine it's easy to export these metrics with JMX plugin for Stackdriver ( https://cloud.google.com/monitoring/agent/plugins/jvm#configuring )

However I need to do similar thing using Cloud Run, is there a known way to do that?

Thanks!

I'm unfamiliar with JMX but familiar with GCP including Cloud Run.

I've implemented something similar(ish) using Prometheus (and Cloud Endpoints for app security), multiplexing the app and metrics on 8080.

IIUC the monitoring agent (based on collectd):

  1. collects metrics uses a predefined port
  2. ships these to Cloud Monitoring (formerly Stackdriver)

As you know, Cloud Run is container-based and only permits a single port ( 8080 ).

I suspect it would be messy (and likely not supported by Google) to try to bundle the agent in the app's container but that the agent would be able to call home (Cloud Monitoring) though still, though perhaps with some IAM tweaking.

It would be great if Cloud Run permitted multiple containers per service

Potentially, you can multiplex JMX and your app traffic over 8080.

It would be great if Cloud Run permitted multiple ports per service

Then, your regular users could access the app and the monitoring agent (running elsewhere) could ping the JMX metrics on the same service port and ship these to Cloud Monitoring.

You'd need to be more mindful of security. You can craft JWTs to authenticate to Cloud Run though these are more "prickly" with Cloud Run because each service requires a specific JWT using the service's endpoint to form its audience.

You'd likely want to prohibit authenticated app users from capturing your JMX metrics too.

I'm assuming there's no restriction on routing JMX traffic through Google's frontend to Cloud Run services.

Apparently much better option is to instrument Java code in Cloud Run is to use OpenCensus library.

OpenCensus library can easily work with DropWizard and it has implementation of Stackdriver exporter.

Some pointers here: https://opencensus.io/exporters/supported-exporters/java/stackdriver-stats/ https://cloud.google.com/monitoring/custom-metrics/open-census

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM