Prometheus provides JMX exporter which can export JVM information.
- Create JMX exporter configuration. Let's call it
jmx_exporter_config.yml
.
---rules:-pattern:"java.lang.*"
2. Download JMX exporter
You can find the URL of JMX exporter jar file in Github repository.
https://github.com/prometheus/jmx_exporter
Here is the URL for 0.16.1
3. Start your Java application
For example, your application is packaged as a jar filemyapp_1.jar
.jmx_prometheus_javaagent-0.16.1.jar
andjmx_exporter_config.yml
are saved in/app
. We expose port8080
to export metrics.
java-javaagent:/app/jmx_prometheus_javaagent-0.16.1.jar=8080:/app/jmx_exporter_config.yml-jar myapp_1.jar
4. Download Prometheus
You can find the URL of Prometheus in its official site.
https://prometheus.io/download/
Here is the URL of 2.33.0 (MacOS).
5. Unzip Prometheus
After it is downloaded, unzip it and go to its directory.
tarxvfz prometheus-*.tar.gzcdprometheus-*
6. Update prometheus configuration
Add the following to theprometheus.yml
(underscrape_configs
). We adds label to help querying.
-job_name:"apps"static_configs:-targets:["localhost:8080"]labels:instance:'myapp_1'
The whole file should look like this.
# my global configglobal:scrape_interval:15s# Set the scrape interval to every 15 seconds. Default is every 1 minute.evaluation_interval:15s# Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configurationalerting:alertmanagers:-static_configs:-targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files:# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.-job_name:"prometheus"# metrics_path defaults to '/metrics'# scheme defaults to 'http'.static_configs:-targets:["localhost:9090"]-job_name:"apps"static_configs:-targets:["localhost:8080"]labels:instance:'myapp_1'
7. Start Prometheus
./prometheus--config.file=prometheus.yml
8. Query JVM information
Queryjvm_memory_bytes_used{area="heap",instance="myapp_1"}
Here is the query result.
Or you prefer a graph (You may need to refresh the browser if you want to see the latest data)
Here are other metrics you can try.
jvm_gc_collection_seconds_count
jvm_gc_collection_seconds_sum
jvm_memory_bytes_used
-jvm_memory_bytes_committed
jvm_memory_bytes_max
jvm_memory_bytes_init
process_cpu_seconds_total
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse