Develope/Programming

[Jolokia + Telegraf] Agent Mode, Proxy Mode 실행방법 및 테스트

고로이 2018. 6. 12. 11:00
반응형

0. 배경

  • Test용 Process
19720 Kafka               :     JMX port 9999
32606 Bootstrap            JMX port 9876 




1. Jolokia Agent 사용 ( KAFKA )

1-1. JMX list 보기
  • java -jar jolokia-jvm-1.5.0-agent.jar 
  • java -jar jolokia-jvm-1.5.0-agent.jar list



1-2. JMX 선택 
  • java -jar jolokia-jvm-1.5.0-agent.jar <PID> —port=<PORT> —host=<HOST>
  • java -jar jolokia-jvm-1.5.0-agent.jar 19720 --port=2233 --host=localhost



1-3. jolokia 확인
  • 실행 전


  • 실행 후


1-4. 중지
  •  java -jar jolokia-jvm-1.5.0-agent.jar <PID>


1-5. Telegraf 설정
  • root 계정으로 접속
  • vi /etc/telegraf/telegraf.conf

    [[inputs.jolokia2_agent]]
      name_prefix = "jolokias"

      [[inputs.jolokia2_agent.metric]]
      name  = "jvm_memory"
      mbean = "java.lang:type=Memory"
      paths = ["HeapMemoryUsage", "NonHeapMemoryUsage", "ObjectPendingFinalizationCount"]

1-6. Telegraf 실행
   /bin/telegraf start

1-7. 수집 확인 (Kafka comsumer 이용)
/~/kafka/telegraf-consummer.sh | grep jolokia

{
  "fields": {
    "HeapMemoryUsage.committed": 1073741824,
    "HeapMemoryUsage.init": 1073741824,
    "HeapMemoryUsage.max": 1073741824,
    "HeapMemoryUsage.used": 238401024,
    "NonHeapMemoryUsage.committed": 54427648,
    "NonHeapMemoryUsage.init": 2555904,
    "NonHeapMemoryUsage.max": -1,
    "NonHeapMemoryUsage.used": 52841232,
    "ObjectPendingFinalizationCount": 0
  },
  "name": "jvm_memory",
  "tags": {
    "host": "tcore-ic-test",
    "jolokia_agent_url": "http://127.0.0.1:2233/jolokia/"
  },
  "timestamp": 1528710660
}



2. Jolokia Application 내부 배포 사용
32606 Bootstrap => Tomcat Jolokia 내부 배포



2-1. Telegraf 설정
  • root 계정으로 접속
  • vi /etc/telegraf/telegraf.conf

    [[inputs.jolokia2_agent]]
      name_prefix = "jolokias"

      [[inputs.jolokia2_agent.metric]]
      name  = "jvm_memory"
      mbean = "java.lang:type=Memory"
      paths = ["HeapMemoryUsage", "NonHeapMemoryUsage", "ObjectPendingFinalizationCount"]



2-2. 실행 및 수집 확인
  • /bin/telegraf start
  • /home/*******/applications/kafka/telegraf-consummer.sh | grep jolokia

{
  "fields": {
    "HeapMemoryUsage.committed": 492830720,
    "HeapMemoryUsage.init": 513802240,
    "HeapMemoryUsage.max": 7285506048,
    "HeapMemoryUsage.used": 80858784,
    "NonHeapMemoryUsage.committed": 32571392,
    "NonHeapMemoryUsage.init": 2555904,
    "NonHeapMemoryUsage.max": -1,
    "NonHeapMemoryUsage.used": 31371056,
    "ObjectPendingFinalizationCount": 0
  },
  "name": "jvm_memory",
  "tags": {
    "host": "********",
    "jolokia_agent_url": "http://localhost:8080/jolokia/"
  },
  "timestamp": 1528710960
}



2-3. Telegraf proxy mode 설정
1) <tomcat>/webapp/jolokia.war 리패키징
web.xml
<init-param> 
  <description>
    Classnames (comma separated) of RequestDispatcher used in addition
    to the LocalRequestDispatcher
  </description>
  <param-name>dispatcherClasses</param-name>
  <param-value>org.jolokia.jsr160.Jsr160RequestDispatcher</param-value>
</init-param>



2-4. Proxy mode 확인

curl -X POST -H "Content-Type: application/json" http://localhost:8080/jolokia -d '  
[  {
    "type":"read",
    "mbean":"java.lang:type=Threading",
    "attribute":"ThreadCount",
    "target": {
                "url":"service:jmx:rmi:///jndi/rmi://localhost:9876/jmxrmi” 
              }
  }]'




2-4. Telegraf 설정
  • root 계정으로 접속
  • vi /etc/telegraf/telegraf.conf

[[inputs.jolokia2_proxy]]

  [[inputs.jolokia2_proxy.target]]
    url = "service:jmx:rmi:///jndi/rmi://localhost:9876/jmxrmi"

  [[inputs.jolokia2_proxy.metric]]
    name  = "jvm_runtime"
    mbean = "java.lang:type=Runtime"
    paths = ["Uptime”]


2-2. 수집 확인
  • /bin/telegraf start
  • /home/tcore-ic/applications/kafka/telegraf-consummer.sh | grep jolokia

{
  "fields": {
    "Uptime": 545689
  },
  "name": "jvm_runtime",
  "tags": {
    "jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://localhost:9876/jmxrmi",
    "jolokia_proxy_url": "http://localhost:8080/jolokia"
  },
  "timestamp": 1528714180
}




3. 기타 확인

3-1. 설정
  • Telegraf 설정 :
    • Kafka : 2233,
    • jolokia_proxy : 9999 (Kafka JMX)
      • => tomcat에 있는 jolokia agent 에 Kafka JXM를 붙임

  • Telegraf.conf
[[inputs.jolokia2_proxy]]

  [[inputs.jolokia2_proxy.target]]
    url = "service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi" => KAFKA의 JMX 포트

  [[inputs.jolokia2_proxy.metric]]
    name  = "jvm_memory"
    mbean = "java.lang:type=Memory"
    paths = ["HeapMemoryUsage"]

[[inputs.jolokia2_agent]]
  name_prefix = "jolokia_kafka"
  urls = ["http://localhost:2233/jolokia”] => KAFKA 의 jolokiaAgent 포트

  [[inputs.jolokia2_agent.metric]]
  name  = "jvm_memory"
  mbean = "java.lang:type=Memory"
  paths = ["HeapMemoryUsage"]



3-2. 결과  = 수집 값이 같음 = 같은 JMX 수집

{
  "fields": {
    "HeapMemoryUsage.committed": 1073741824,
    "HeapMemoryUsage.init": 1073741824,
    "HeapMemoryUsage.max": 1073741824,
    "HeapMemoryUsage.used": 381007360
  },
  "name": "jolokia_kafkajvm_memory",
  "tags": {
    "jolokia_agent_url": "http://localhost:2233/jolokia"
  },
  "timestamp": 1528714100
}

{
  "fields": {
    "HeapMemoryUsage.committed": 1073741824,
    "HeapMemoryUsage.init": 1073741824,
    "HeapMemoryUsage.max": 1073741824,
    "HeapMemoryUsage.used": 382055936
  },
  "name": "jvm_memory",
  "tags": {
    "jolokia_agent_url": "service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi",
    "jolokia_proxy_url": "http://localhost:8080/jolokia"
  },
  "timestamp": 1528714100
}



반응형