jmxtrans docker-compose run

The following is a simple demo, using jmxtrans be jmx indicators of treatment, the use of docker-compose the project running
simultaneously writing data to the graphite

Preparing the Environment

  • docker-compose documents
 
version: "3"
services: 
  graphite:
    image: graphiteapp/graphite-statsd
    ports:
    - "80:80"
    - "2003-2004:2003-2004"
    - "2023-2024:2023-2024"
    - "8125:8125/udp"
    - "8126:8126"
  jmxtrans:
    build: 
      context: ./
      dockerfile: Dockerfile-jmxtrans
  app:
    build: ./
    image: dalongrong/java-jmx-openjdk
    container_name: app
    ports: 
    - "8080:8080"
    - "30384:30384"
  • dockerfile description
    contains a spring boot project App
    Dockerfile
 
FROM openjdk:8u222-jdk
LABEL AUTHOR="dalongrong"
LABEL EMAIL="[email protected]"
WORKDIR /
COPY webapi-0.0.1-SNAPSHOT.jar /webapi-0.0.1-SNAPSHOT.jar
COPY docker-entrypiont.sh /docker-entrypiont.sh
RUN chmod +x /docker-entrypiont.sh
EXPOSE 30384 8080
ENTRYPOINT [ "/docker-entrypiont.sh" ]

docker-entrypiont.sh:

#!/bin/sh
java \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=30384 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.rmi.port=30384 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.host=app \
-Djava.rmi.server.hostname=app \
-jar /webapi-0.0.1-SNAPSHOT.jar

jmxtrans Dockerfile-jmxtrans

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

jmxtrans configuration json file jmxtrans.json

   {
  "servers": [{
    "port": "30384",
    "host": "app",
    "numQueryThreads": 4;
    "queries": [
      {
        "obj": "Tomcat:type=ThreadPool,name=\"http-nio-8080\"",
        "resultAlias":"http-nio-8080",
        "attr": ["acceptCount","currentThreadsBusy","currentThreadCount"],
        "outputWriters": [{
          "@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
          "port": 2003,
          "host": "graphite",
          "rootPrefix":"webapi",
          "typeNames" : ["name"],
          "flushStrategy" :"always",
          "poolSize" : 10
        }]
      },
      {
        "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"
        }]
      }
    ]
  }]
}

Configuration instructions

  • jmx service app
    is mainly configured by jmx start running, specific reference docker-entrypiont.sh
  • jmxtrans
    by docker run, mainly Profile jmxtrans.json added several inquiries by GraphiteWriter while
    writing data to the Graphite
    illustrate several parameters, if you read the official wiki and code will find that there are several parameters that must be write, but it is not very clear wiki
    mainly rootPrefix, flushStrategy,typeNames

Start && test

  • start up
 
docker-compose up -d
  • effect

 

Explanation

The above is a simple docker-compose run, in fact, we can expand, add more jmx indicators for operation mode kuberntes, refer to a similar manner, but
we can use localhost to run multiple containers in the pod resolved, it is quite easy

Reference material

https://github.com/jmxtrans/jmxtrans/wiki/GraphiteWriter
https://github.com/jmxtrans/jmxtrans/wiki/Queries
https://github.com/rongfengliang/openjdk-docker-jmx/tree/jmxtrans

Guess you like

Origin www.cnblogs.com/rongfengliang/p/11223629.html