Access specific JMX metric information on JConsole for a Spring Boot Application - spring

I have a Spring Boot application packaged as a WAR and deployed on a Tomcat 9 server.
It's been configured to expose the following metrics through JMX:
spring.jmx.default-domain: my-app
management.endpoints.jmx.exposure.include: health,info,metrics
I can connect to Tomcat through JConsole and see the my-app MBean that offers those 3 endpoints:
Selecting Metrics -> Operations - listNames I can get the whole list of metrics exposed, invoking the listNames method:
Now I would like to see a specific metric (e.g. jvm.memory.used), going to metrics -> Operations -> metrics:
However the metric(requiredMetricName, tag) method is disabled.
How can I get the value of a specific metric from the mbean in JConsole?

The reason it's disabled is because JConsole won't allow input of parameters of complex types. See https://stackoverflow.com/a/12025340/62667
But if you use an alternative JMX interface (e.g. add Hawtio to your application) then you could use that to invoke the operations.

Related

Is there any way to add `application` tag to standard prometheus micrometer metrics?

I have few spring-boot microservices with actuator and exposed prometheus metrics. For example:
# HELP process_uptime_seconds The uptime of the Java virtual machine
# TYPE process_uptime_seconds gauge
process_uptime_seconds 3074.971
But there is no application tag, so I'm not able to bind it to a certain application within a grafana dashboard...
Also I expect to have few application instances of some microservice, so in general it would be great to add an instance tag also.
Is there any way to customize the standard metrics with these tags?
The best way to add tags is to use the Prometheus service discovery. This keeps these tags out of your application code and keeps it from being concerned about where it exists.
However sometime if you absolutely need those extra tags (due to the service having extra insight that Prometheus service discovery isn't surfacing) you can't use the Java Simple Client (the Go client does support this though)
I turns out this feature is offered via a Micrometer feature called 'Common Tags' which wraps the Prometheus Java client. You setup your client so the tags are available via a config() call.
registry.config().commonTags("stack", "prod", "region", "us-east-1");
What I am usually doing is using Maven filtering on the resource files (e.g. application.yml) which will replace Maven-known properties like project.artifactId. Springs configuration then takes care of interpolating management.metrics.tags.application.
An application.yml example:
spring:
application:
name: ${project.artifactId}
management:
metrics:
tags:
application: ${spring.application.name}

Customize Spring boot Kafka listener metrics

We have a microservice architecture on the project and we use Prometheus and Grafana for monitoring. The services are implemented using Spring Boot and the integration with Prometheus is through spring-boot-actuator.
There are some Kafka consumers in the project, and for each #KafkaListener spring is generating some metrics. Here is a sample of the Prometheus time series for the metric spring_kafka_listener_seconds_count
spring_kafka_listener_seconds_count{exception="ListenerExecutionFailedException", instance="192.168.100.4:8001", job="spring-actuator", name="org.springframework.kafka.KafkaListenerEndpointContainer#0-0", result="failure"} 2
spring_kafka_listener_seconds_count{exception="none", instance="192.168.100.4:8001", job="spring-actuator", name="org.springframework.kafka.KafkaListenerEndpointContainer#0-0", result="success"} 2
spring_kafka_listener_seconds_count{exception="none", instance="192.168.100.4:8001", job="spring-actuator", name="org.springframework.kafka.KafkaListenerEndpointContainer#1-0", result="success"} 4
org.springframework.kafka.KafkaListenerEndpointContainer#0-0 - doesn't give much info regarding the #KafkaListener method of interest.
Is it possible to configure more meaningful value for the name label of these metrics?
Give the listener a meaningful id.
#KafkaListener(id = "someId", ...)
Note that, by default, the id will be used as the consumer group.id, unless you also specify group, or set idIsGroup to false.

How to enable spring-actuator to collect metrics from multiple applications

I have a pod which consists of multiple containers each have an application running. How do I enable actuator to fetch metrics from these applications. I couldn't find a way to do this.
There are four micro services running in the pod on different ports say 8082, 8080, 8081, 8083. But the actuator is scraping the metrics only from the micro service running on 8080(default port).
I tried adding application properties indicated in code section to all properties. but it didn't work. Here is the application.property content:
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.metrics.use-global-registry=true
management.server.port=8888
Expected output: I should be able to see the metrics from each applications using /metrics endpoint.
I was able to solve this problem. Here are the steps:
Configure separate acutator ports for each service in application.properties.
Expose the configure ports in deployment yaml(in case of kubernetes).
That's it.

Spring boot graphite network information

I am setting up graphite / grafana for my spring boot application. I am trying to find how to get network information like bytes in / out (network stats). Can someone tell me how I could derive this information? I am using tomcat as boot server
See meter name tomcat.global.received and tomcat.global.sent which come from Tomcat JMX Bean GlobalRequestProcessor's bytesReceived and bytesSent attributes respectively.
See also the relevant part of code in Micrometer.

How to access mulesoft application metrics using JMX

I want to expose some custom application metrics like how many records processed to JMX in mulesoft flow.
My application is spring boot application.
Any idea on how to achieve this?
Thanks & Regards,
Vikas Gite
Using the Default JMX Support Agent
You can configure several JMX agents simultaneously using the element. When set, this element registers the following agents:
List item
JMX agent
RMI registry agent (if necessary) on rmi://localhost:1099
Remote JMX access on service:jmx:rmi:///jndi/rmi://localhost:1099/server
(Optional) Log4J JMX agent, which exposes the configuration of the Log4J instance used by Mule for JMX management
JMX notification agent used to receive server notifications using JMX notifications
(Optional) MX4J adapter, which provides web-based JMX management, statistics, and configuration viewing of a Mule instance
Also you can try below which can directly be configured under the MULE's wrapper.conf (under $MULE_HOME/conf/wrapper.conf) to enable JMX connectivity so that we can use tools like JMC (Java Mission Control), VisualVM, JConsole to pull the JMX attribute values from the Mule Server and the deployed applications -
wrapper.java.additional.<n>=-Dcom.sun.management.jmxremote
wrapper.java.additional.<n>=-Dcom.sun.management.jmxremote.port=9999
wrapper.java.additional.<n>=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.<n>=-Dcom.sun.management.jmxremote.local.only=false
wrapper.java.additional.<n>=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.<n>=-Djava.rmi.server.hostname=<localhost ip>
wrapper.java.additional.<n>=-Djava.rmi.activation.port=9998
Here should be removed with the next incremental value of the java wrapper value and will be the ip of the the Mule runtime host/server
I hope you are looking for this, if not then please post further queries or clarity so that i will help you out.

Resources