使用jmx-exporter&&jmxtrans && nexus jmx 暴露nexus 系统指标信息

以下演示一个简单的使用jmxexporter 暴露nexus jmx 指标为prometheus metrics,同时也集成了一个简单的jmxtrans 输出数据到
graphite

环境准备

  • docker-compose 文件
 
version: "3"
services: 
  graphite:
    image: graphiteapp/graphite-statsd
    ports:
    - "80:80"
    - "2003-2004:2003-2004"
    - "2023-2024:2023-2024"
    - "8125:8125/udp"
    - "8126:8126"
  jmx-exporter:
    image: dalongrong/jmx-expoter
    build:
      context: ./
      dockerfile: Dockerfile-jmx
    ports: 
    - "9999:9999"
  jmxtrans:
    image: dalongrong/jmxtrans
    build: 
      context: ./
      dockerfile: Dockerfile-jmxtrans
  nexus:
    image: sonatype/nexus3:3.17.0
    container_name: nexus
    ports: 
    - "8081:8081"
    - "8099:8099"
    - "8044:8044"
    volumes: 
    - "./nexus-data:/nexus-data"
    - "./nexus/nexus.vmoptions:/opt/sonatype/nexus/bin/nexus.vmoptions"
    - "./nexus/org.apache.karaf.features.cfg:/opt/sonatype/nexus/etc/karaf/org.apache.karaf.features.cfg"
    - "./nexus/org.apache.karaf.management.cfg:/opt/sonatype/nexus/etc/karaf/org.apache.karaf.management.cfg"
  • jmx-exporter docker 镜像说明
FROM openjdk:8u222-jdk
LABEL AUTHOR="dalongrong"
LABEL EMAIL="[email protected]"
WORKDIR /
COPY jmx_prometheus_httpserver-0.12.1-SNAPSHOT-jar-with-dependencies.jar /jmx_prometheus_httpserver-0.12.1-SNAPSHOT-jar-with-dependencies.jar
COPY docker-entrypiont-jmx-exporter.sh /docker-entrypiont.sh
COPY jmx-exporter.yaml /jmx-exporter.yaml
RUN chmod +x /docker-entrypiont.sh
EXPOSE 9999
ENTRYPOINT [ "/docker-entrypiont.sh" ]

docker-entrypiont-jmx-exporter.sh

#!/bin/sh
java -jar /jmx_prometheus_httpserver-0.12.1-SNAPSHOT-jar-with-dependencies.jar 0.0.0.0:9999 /jmx-exporter.yaml
  • jmxtrans docker 镜像说明
FROM openjdk:8u222-jdk
LABEL AUTHOR="dalongrong"
LABEL EMAIL="[email protected]"
WORKDIR /
COPY jmxtrans-270-all.jar /jmxtrans-270-all.jar
COPY docker-entrypiont-jmx.sh /docker-entrypiont.sh
COPY jmxtrans.json /jmxtrans.json
RUN chmod +x /docker-entrypiont.sh
ENTRYPOINT [ "/docker-entrypiont.sh" ]
 

docker-entrypiont-jmx.sh

#!/bin/sh
java -jar /jmxtrans-270-all.jar -f /jmxtrans.json

jmxtrans.json 是一个简单的jmx query 配置,可以按照实际需要配置

{
  "servers": [{
    "port": "8044",
    "host": "nexus",
    "username" : "admin",
    "password" : "dalong123",
    "numQueryThreads" : 4,
    "queries": [
      {
        "obj": "java.lang:type=Memory",
        "resultAlias":"Memory",
        "attr" : [ "HeapMemoryUsage", "NonHeapMemoryUsage" ],
        "outputWriters": [{
          "@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
          "port": 2003,
          "host": "graphite",
          "rootPrefix":"webapi",
          "typeNames" : ["name"],
          "flushStrategy" :"always",
          "poolSize" : 10
        }]
      }
      ,
      {
        "obj": "java.lang:type=ClassLoading",
        "resultAlias":"ClassLoading",
        "attr": ["TotalLoadedClassCount","LoadedClassCount","UnloadedClassCount"],
        "outputWriters": [{
          "@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
          "port": 2003,
          "rootPrefix":"webapi",
          "typeNames" : ["name"],
          "flushStrategy" :"always",
          "poolSize" : 10,
          "host": "graphite"
        }]
      }
    ]
  }]
}
  • nexus 说明
    直接参考官方的有点问题,我添加了以下配置
    nexus.vmoptions
 
-XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
-Djava.rmi.server.hostname=nexus
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=8044
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.rmi.port=8044
-Dcom.sun.management.jmxremote.local.only=false

org.apache.karaf.features.cfg以及org.apache.karaf.management.cfg 配置参考官方介绍

  • jmx-exporter 编译
git clone https://github.com/prometheus/jmx_exporter.git
cd jmx_exporter
mvn clean package

启动&&测试

  • 启动
docker-compose build
docker-compose up -d
  • 效果

说明:

  • 当前直接使用容器运行的nexus,参考官方暴露jmx 有些问题,直接使用普通jmx 暴露的方式,进行了调整
  • jmx-exporter 使用httpserver 模式运行
  • jmx-exporter 使用源码编码方式,项目使用了编译好的
  • jmx-exporter && jmxtrans doker 镜像基于openjdk,镜像很简单
  • 没有添加prometheus server 以及granfana 添加起来也比较简单
  • 当前修改nexus jmx 启动参数的方式不是很安全,但是如果在容器内还可以勉强使用

参考资料

https://github.com/rongfengliang/jmx-exporter-jmxtrans-nexus-docker-compose
https://github.com/prometheus/jmx_exporter
https://github.com/jmxtrans/jmxtrans
https://support.sonatype.com/hc/en-us/articles/218501277-Configuring-Nexus-Repository-Manager-3-To-Allow-JMX-Connections

猜你喜欢

转载自www.cnblogs.com/rongfengliang/p/11225782.html
JMX