Answers: <p>After trying many things, I came to know that I needed to expose the port of my application's container in order to let Prometheus or other deployments to know. After exposing the port, I could see my application under targets on Prometheus and I could scrape all JMX and JVM metrics. Hope this would help someone in future...</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-09-24T07:36:16.657Z
Answers: 2019-09-24T07:36:16.657Z
Answers: Radiant
Body: <p>I am trying to use JMX_Exporter for my kotlin code to expose metrics to prometheus in order to show it in Grafana. I have gone through many articles and tried to understand how could it be done. I have found below two links useful and trying to achieve using those.</p>
  
  <p><a href="https://github.com/prometheus/jmx_exporter" rel="nofollow noreferrer">https://github.com/prometheus/jmx_exporter</a>
  <a href="https://www.openlogic.com/blog/monitoring-java-applications-prometheus-and-grafana-part-1" rel="nofollow noreferrer">https://www.openlogic.com/blog/monitoring-java-applications-prometheus-and-grafana-part-1</a>
  What i did so far is, created a folder 'prometheus-jmx' in root directory and added mentioned JAR and config.yml file in that folder. Then, i added below parameter to my dockerfile.</p>
  
  <pre><code>CMD java -Xms128m -Xmx256m -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8080:./config.yml -Dconfig.file=config/routing.conf -cp jagathe-jar-with- 
      dependencies.jar:./* com.bmw.otd.agathe.AppKt
  </code></pre>
  
  <p>My prometheus is running in my OpenShift cluster along with my application. I could scrape metrics for my other applications/deployments like Jenkins, SonarQube etc without any modifications in deployment.yml of Prometheus.</p>
  
  <p>My application is running properly now on OpenShift and from application's pod, I can scrape metrics by using below command.</p>
  
  <pre><code>curl http://localhost:portNumber
  </code></pre>
  
  <p>But on promethus UI, I cant see any JVM or JMX related metric.</p>
  
  <p>Can someone please tell me where and what am i doing wrong? Any kind of help would be appreciated.</p>
  
Tags: <openshift><prometheus><grafana>
Title: Expose metrics for Kotlin using JMX_Exporter to prometheus
UserDisplayName: Radiant
ThreadText: # Expose metrics for Kotlin using JMX_Exporter to prometheus
  
  (Asked by: username_0 on 2019-09-09)
  
  I am trying to use JMX\_Exporter for my kotlin code to expose metrics to prometheus in order to show it in Grafana. I have gone through many articles and tried to understand how could it be done. I have found below two links useful and trying to achieve using those.
  
  <https://github.com/prometheus/jmx_exporter>
  <https://www.openlogic.com/blog/monitoring-java-applications-prometheus-and-grafana-part-1>
  What i did so far is, created a folder 'prometheus-jmx' in root directory and added mentioned JAR and config.yml file in that folder. Then, i added below parameter to my dockerfile.
  
  ```
  CMD java -Xms128m -Xmx256m -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8080:./config.yml -Dconfig.file=config/routing.conf -cp jagathe-jar-with- 
      dependencies.jar:./* com.bmw.otd.agathe.AppKt
  
  ```
  
  My prometheus is running in my OpenShift cluster along with my application. I could scrape metrics for my other applications/deployments like Jenkins, SonarQube etc without any modifications in deployment.yml of Prometheus.
  
  My application is running properly now on OpenShift and from application's pod, I can scrape metrics by using below command.
  
  ```
  curl http://localhost:portNumber
  
  ```
  
  But on promethus UI, I cant see any JVM or JMX related metric.
  
  Can someone please tell me where and what am i doing wrong? Any kind of help would be appreciated.
  
  **Tags:** openshift, prometheus, grafana
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-24. Score: 1
  
  After trying many things, I came to know that I needed to expose the port of my application's container in order to let Prometheus or other deployments to know. After exposing the port, I could see my application under targets on Prometheus and I could scrape all JMX and JVM metrics. Hope this would help someone in future...
  
  
  ---
  
  