Git Product home page Git Product logo

jmx_exporter_multi's Introduction

JMX Exporter

jmx_exporter文档https://github.com/prometheus/jmx_exporter/blob/master/README.md

原生的jmx_exporter需要为每一个java进程启动一个exporter,并且需要部署到该进程所属的机器上。可能存在一台机器上有很多jvm进程,那么一台机器上也需要部署多个exporter。为了方便管理,我希望能够在一台机器上部署一个jmx_exporter.

这里提供了一种解决方案:将一个jmx_exporter部署在一台机器上,同时抓取多个应用的jmx。现对于原生的jmx_exporter,只需要修改很少的配置文件即可。

比如抓取两个进程的jmx,只需要将原生配置改为列表即可,增加了几个变量jobs,name,socket

说明

删除了javaagent启动方式

启动

确保被抓取目标开启了remote jmx,并且配置文件无误

java -jar jmx_prometheus_httpserver_multi-0.13.0-SNAPSHOT-jar-with-dependencies.jar 8 example.yaml

参数分别是:你要抓取的jvm进程数,配置文件

Configuration

The configuration is in YAML. An example with all possible options:

---

jobs:
  - name: a
    startDelaySeconds: 0
    #hostPort: 127.0.0.1:1234
    username: 
    password: 
    socket: 127.0.0.1:9999
    jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:1234/jmxrmi
    ssl: false
    lowercaseOutputName: false
    lowercaseOutputLabelNames: false
    whitelistObjectNames: ["org.apache.cassandra.metrics:*"]
    blacklistObjectNames: ["org.apache.cassandra.metrics:type=ColumnFamily,*"]
    rules:
    - pattern: 'org.apache.cassandra.metrics<type=(\w+), name=(\w+)><>Value: (\d+)'
    name: cassandra_$1_$2
    value: $3
    valueFactor: 0.001
    labels: {}
    help: "Cassandra metric $1 $2"
    type: GAUGE
    attrNameSnakeCase: false
	
 - name: a
   startDelaySeconds: 0
   hostPort: 127.0.0.1:1235
   username: 
   password: 
   socket: 127.0.0.1:9999
   #jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:1235/jmxrmi
   ssl: false
   lowercaseOutputName: false
   lowercaseOutputLabelNames: false
   whitelistObjectNames: ["org.apache.cassandra.metrics:*"]
   blacklistObjectNames: ["org.apache.cassandra.metrics:type=ColumnFamily,*"]
   rules:
   - pattern: 'org.apache.cassandra.metrics<type=(\w+), name=(\w+)><>Value: (\d+)'
   name: cassandra_$4_$5
   value: $5
   valueFactor: 0.001
   labels: {}
   help: "Cassandra metric $4 $5"
   type: GAUGE
   attrNameSnakeCase: false
Name Description
jobname 任务的名字
socket 需要暴露给prometheus的地址
startDelaySeconds start delay before serving requests. Any requests within the delay period will result in an empty metrics set.
hostPort The host and port to connect to via remote JMX. If neither this nor jmxUrl is specified, will talk to the local JVM.
username The username to be used in remote JMX password authentication.
password The password to be used in remote JMX password authentication.
jmxUrl A full JMX URL to connect to. Should not be specified if hostPort is.
ssl Whether JMX connection should be done over SSL. To configure certificates you have to set following system properties:
-Djavax.net.ssl.keyStore=/home/user/.keystore
-Djavax.net.ssl.keyStorePassword=changeit
-Djavax.net.ssl.trustStore=/home/user/.truststore
-Djavax.net.ssl.trustStorePassword=changeit
lowercaseOutputName Lowercase the output metric name. Applies to default format and name. Defaults to false.
lowercaseOutputLabelNames Lowercase the output metric label names. Applies to default format and labels. Defaults to false.
whitelistObjectNames A list of ObjectNames to query. Defaults to all mBeans.
blacklistObjectNames A list of ObjectNames to not query. Takes precedence over whitelistObjectNames. Defaults to none.
rules A list of rules to apply in order, processing stops at the first matching rule. Attributes that aren't matched aren't collected. If not specified, defaults to collecting everything in the default format.
pattern Regex pattern to match against each bean attribute. The pattern is not anchored. Capture groups can be used in other options. Defaults to matching everything.
attrNameSnakeCase Converts the attribute name to snake case. This is seen in the names matched by the pattern and the default format. For example, anAttrName to an_attr_name. Defaults to false.
name The metric name to set. Capture groups from the pattern can be used. If not specified, the default format will be used. If it evaluates to empty, processing of this attribute stops with no output.
value Value for the metric. Static values and capture groups from the pattern can be used. If not specified the scraped mBean value will be used.
valueFactor Optional number that value (or the scraped mBean value if value is not specified) is multiplied by, mainly used to convert mBean values from milliseconds to seconds.
labels A map of label name to label value pairs. Capture groups from pattern can be used in each. name must be set to use this. Empty names and values are ignored. If not specified and the default format is not being used, no labels are set.
help Help text for the metric. Capture groups from pattern can be used. name must be set to use this. Defaults to the mBean attribute description and the full name of the attribute.
type The type of the metric, can be GAUGE, COUNTER or UNTYPED. name must be set to use this. Defaults to UNTYPED.

Metric names and label names are sanitized. All characters other than [a-zA-Z0-9:_] are replaced with underscores, and adjacent underscores are collapsed. There's no limitations on label values or the help text.

A minimal config is {}, which will connect to the local JVM and collect everything in the default format. Note that the scraper always processes all mBeans, even if they're not exported.

Example configurations for javaagents can be found at https://github.com/prometheus/jmx_exporter/tree/master/example_configs

Pattern input

The format of the input matches against the pattern is

domain<beanpropertyName1=beanPropertyValue1, beanpropertyName2=beanPropertyValue2, ...><key1, key2, ...>attrName: value
Part Description
domain Bean name. This is the part before the colon in the JMX object name.
beanProperyName/Value Bean properties. These are the key/values after the colon in the JMX object name.
keyN If composite or tabular data is encountered, the name of the attribute is added to this list.
attrName The name of the attribute. For tabular data, this will be the name of the column. If attrNameSnakeCase is set, this will be converted to snake case.
value The value of the attribute.

No escaping or other changes are made to these values, with the exception of if attrNameSnakeCase is set. The default help includes this string, except for the value.

Default format

The default format will transform beans in a way that should produce sane metrics in most cases. It is

domain_beanPropertyValue1_key1_key2_...keyN_attrName{beanpropertyName2="beanPropertyValue2", ...}: value

If a given part isn't set, it'll be excluded.

Debugging

You can start the jmx's scraper in standalone mode in order to debug what is called

java -cp jmx_exporter.jar io.prometheus.jmx.JmxScraper service:jmx:rmi:your_url

To get finer logs (including the duration of each jmx call), create a file called logging.properties with this content:

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=ALL
io.prometheus.jmx.level=ALL
io.prometheus.jmx.shaded.io.prometheus.jmx.level=ALL

Add the following flag to your Java invocation:

-Djava.util.logging.config.file=/path/to/logging.properties

jmx_exporter_multi's People

Contributors

gentlezuo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jmx_exporter_multi's Issues

Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List at io.prometheus.jmx.WebServer.main(WebServer.java:27)

进程信息
ps -ef|grep java
tomcat 35963 1 9 10:42 pts/1 00:00:51 /opt/jdk1.8.0_181/bin/java -Djava.util.logging.config.file=/app/tomcat/tomcat8_test_9080/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms2048m -Xmx2048m -XX:+UseConcMarkSweepGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -verbose:gc -Xloggc:/app/tomcat/tomcat8_test_9080/logs/gc_20210114.log -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0022 -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=10.18.3.222 -Dcom.sun.management.jmxremote.port=9990 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dignore.endorsed.dirs= -classpath /app/tomcat/tomcat8_test_9080/bin/bootstrap.jar:/app/tomcat/tomcat8_test_9080/bin/tomcat-juli.jar -Dcatalina.base=/app/tomcat/tomcat8_test_9080 -Dcatalina.home=/app/tomcat/tomcat8_test_9080 -Djava.io.tmpdir=/app/tomcat/tomcat8_test_9080/temp org.apache.catalina.startup.Bootstrap start
tomcat 36384 35821 0 10:52 pts/1 00:00:00 grep --color=auto java

执行报错信息
[tomcat@ara-dev006-10 ~]$ java -jar jmx_prometheus_httpserver_multi-0.1.0.jar 1 tomcat8_test_9080/bin/config.yaml
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at io.prometheus.jmx.WebServer.main(WebServer.java:27)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.