Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor the Jetty-based Java application using Prometheus and Grafana

I have deployed a Java application in the server (in 8091) using nohup and Jetty.

I need to monitor that application using Prometheus and Grafana.

So downloaded the JMX exporter.

Need to get all the available metrics (JMX exporter) for that application monitoring.

Downloaded the below jar file:

 https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.1.0/jmx_prometheus_javaagent-0.1.0.jar

Config.yaml

[root@localhost software]# cat config.yaml
---
startDelaySeconds: 0
hostPort: 127.0.0.1:7101
jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:7101/jmxrmi
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
rules:
- pattern: ".*"

The deployment command which I used for usual deployment: (in this directory, Jetty was present)

nohup  -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1 &

it works fine ..

When I tried to monitor the application with JMX exporter, I used the below command:

nohup java -javaagent:./jmx_prometheus_javaagent-0.1.0.jar=7101:config.yaml -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=epoch_temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1 &

it reports as : [1]+ Aborted (core dumped) nohup java -javaagent:./jmx_prometheus_javaagent-0.1.0.jar=7101:config.yaml -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=epoch_temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1

In log file : It reports as :

nohup: ignoring input
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.IllegalArgumentException: At most one of hostPort and jmxUrl must be provided
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector.loadConfig(JmxCollector.java:120)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector.<init>(JmxCollector.java:74)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:36)
        ... 6 more
FATAL ERROR in native method: processing of -javaagent failed

I m not sure whether the config.yaml and the command which I used for monitoring the deployed Java application was correct.

How to monitor this Jetty-based java application using Prometheus and Grafana?

like image 913
soundararajan.c Avatar asked Jan 30 '23 06:01

soundararajan.c


1 Answers

You have specified both hostPort and jmxUrl keys in config.yaml. But at most one of them must be provided. Remove one of them.

like image 195
Nolequen Avatar answered Jan 31 '23 20:01

Nolequen