使用telegraf 可以很好的采集相关的所有数据,而且是非入侵式

基本主流的应用都能采,插件式的

分为input 和 output 插件
平台说明
input 使用 jolokia telegraf 工具提供jolokia相关插件去获取activemq自带的api暴露的指标信息
output 我用的是prometheus client0,这是一个Prometheus客户端,会建立一个自己的socket。

部署在被采集机器

wget https://dl.influxdata.com/telegraf/releases/telegraf-1.12.0-1.x86_64.rpm&& yum install -y telegraf-1.12.0-1.x86_64.rpm

  1. curl -u <你的用户>:<你的密码> http://127.0.0.1:8161/api/jolokia/
  2. mq控制台的用户密码信息一样

修改 /etc/telegraf/telegraf.conf

  1. ## Log file name, the empty string means to log to stderr.
  2. logfile = "/var/log/telegraf/telegraf.log" #填写
  3. ## The logfile will be rotated after the time interval specified. When set
  4. ## to 0 no time based rotation is performed. Logs are rotated only when
  5. ## written to, if there is no log activity rotation may be delayed.
  6. logfile_rotation_interval = "0d" #填写
  7. ## The logfile will be rotated when it becomes larger than the specified
  8. ## size. When set to 0 no size based rotation is performed.
  9. logfile_rotation_max_size = "50MB" #填写
  10. ## Maximum number of rotated archives to keep, any older logs are deleted.
  11. ## If set to -1, no archives are removed.
  12. logfile_rotation_max_archives = 50 #填写
  13. #[[outputs.influxdb]] #注释
  14. #增加注释[[outputs.influxdb]]

cd /etc/telegraf/telegraf.d.
vim output-prometheus-telegraf.conf

  1. ###############################################################################
  2. # OUTPUT PLUGINS #
  3. ###############################################################################
  4. # Configuration for the Prometheus client to spawn
  5. [[outputs.prometheus_client]]
  6. ## Address to listen on
  7. listen = ":30013"
  8. ## Use HTTP Basic Authentication.
  9. # basic_username = "Foo"
  10. # basic_password = "Bar"
  11. ## If set, the IP Ranges which are allowed to access metrics.
  12. ## ex: ip_range = ["192.168.0.0/24", "192.168.1.0/30"]
  13. # ip_range = []
  14. ## Path to publish the metrics on.
  15. # path = "/metrics"
  16. ## Expiration interval for each metric. 0 == no expiration
  17. # expiration_interval = "60s"
  18. ## Collectors to enable, valid entries are "gocollector" and "process".
  19. ## If unset, both are enabled.
  20. # collectors_exclude = ["gocollector", "process"]
  21. ## Send string metrics as Prometheus labels.
  22. ## Unless set to false all string metrics will be sent as labels.
  23. # string_as_label = true
  24. ## If set, enable TLS with the given certificate.
  25. # tls_cert = "/etc/ssl/telegraf.crt"
  26. # tls_key = "/etc/ssl/telegraf.key"
  27. ## Set one or more allowed client CA certificate file names to
  28. ## enable mutually authenticated TLS connections
  29. # tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"]
  30. ## Export metric collection time.
  31. # export_timestamp = false

vim input-amq.conf

  1. ###############################################################################
  2. # INPUT PLUGINS #
  3. ###############################################################################
  4. # Read JMX metrics from a Jolokia REST agent endpoint
  5. [[inputs.jolokia2_agent]]
  6. urls = ["http://localhost:20097/api/jolokia"]
  7. name_prefix = "activemq."
  8. username = "system"
  9. password = "manager"
  10. ### JVM Generic
  11. [[inputs.jolokia2_agent.metric]]
  12. name = "OperatingSystem"
  13. mbean = "java.lang:type=OperatingSystem"
  14. paths = ["ProcessCpuLoad","SystemLoadAverage","SystemCpuLoad"]
  15. [[inputs.jolokia2_agent.metric]]
  16. name = "jvm_runtime"
  17. mbean = "java.lang:type=Runtime"
  18. paths = ["Uptime"]
  19. [[inputs.jolokia2_agent.metric]]
  20. name = "jvm_threading"
  21. mbean = "java.lang:type=Threading"
  22. paths = ["ThreadCount"]
  23. [[inputs.jolokia2_agent.metric]]
  24. name = "jvm_memory"
  25. mbean = "java.lang:type=Memory"
  26. paths = ["HeapMemoryUsage", "NonHeapMemoryUsage", "ObjectPendingFinalizationCount"]
  27. [[inputs.jolokia2_agent.metric]]
  28. name = "jvm_garbage_collector"
  29. mbean = "java.lang:name=*,type=GarbageCollector"
  30. paths = ["CollectionTime", "CollectionCount"]
  31. tag_keys = ["name"]
  32. [[inputs.jolokia2_agent.metric]]
  33. name = "jvm_memory_pool"
  34. mbean = "java.lang:name=*,type=MemoryPool"
  35. paths = ["Usage", "PeakUsage", "CollectionUsage"]
  36. tag_keys = ["name"]
  37. tag_prefix = "pool_"
  38. ### ACTIVEMQ
  39. [[inputs.jolokia2_agent.metric]]
  40. name = "queue"
  41. mbean = "org.apache.activemq:brokerName=*,destinationName=*,destinationType=Queue,type=Broker"
  42. paths = ["QueueSize","EnqueueCount","ConsumerCount","DispatchCount","DequeueCount","ProducerCount","InFlightCount"]
  43. tag_keys = ["brokerName","destinationName"]
  44. [[inputs.jolokia2_agent.metric]]
  45. name = "topic"
  46. mbean = "org.apache.activemq:brokerName=*,destinationName=*,destinationType=Topic,type=Broker"
  47. paths = ["ProducerCount","DequeueCount","ConsumerCount","QueueSize","EnqueueCount"]
  48. tag_keys = ["brokerName","destinationName"]
  49. [[inputs.jolokia2_agent.metric]]
  50. name = "broker"
  51. mbean = "org.apache.activemq:brokerName=*,type=Broker"
  52. paths = ["TotalConsumerCount","TotalMessageCount","TotalEnqueueCount","TotalDequeueCount","MemoryLimit","MemoryPercentUsage","StoreLimit","StorePercentUsage","TempPercentUsage","TempLimit"]
  53. tag_keys = ["brokerName"]

systemctl start telegraf

或者
/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

  1. #启动多个采集进程的示例
  2. # ps -ef|grep telegraf
  3. root 4176 27285 0 14:23 pts/0 00:00:03 telegraf --config 2-jolokia2_agent-telegraf.conf
  4. root 4755 27285 0 14:24 pts/0 00:00:00 telegraf --config jolokia2_agent-telegraf.conf
  5. root 5720 27285 0 14:25 pts/0 00:00:00 telegraf --config temp-telegraf.conf
  6. #实际应用
  7. # ps -ef|grep tele
  8. root 558 29131 0 15:07 pts/1 00:00:00 grep --color=auto tele
  9. telegraf 11443 1 0 14:57 ? 00:00:03 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
  1. curl -s http://127..0.0.1:9275/metrics
  1. vim /data/prometheus/prometheus.yml
  2. 追加内容
  3. - job_name: \'activemq\'
  4. file_sd_configs:
  5. - files: [\'/data/prometheus/sd_config/activemq-endpoint.yml\']
  6. refresh_interval: 30s
  7. vim /data/prometheus/sd_config/activemq-endpoint.yml
  8. 新增内容
  9. - targets:
  10. - 172.16.0.61:30013
  11. labels:
  12. service: activemq

添加相关数据源,修改下实际的指标就能使用

会写一下怎么调试和新增jolokia的指标

版权声明:本文为muzhifei原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/muzhifei/p/13110804.html