如何优雅的采集activeMQ性能指标
如何优雅的采集activemq
使用telegraf 可以很好的采集相关的所有数据,而且是非入侵式
基本主流的应用都能采,插件式的
分为input 和 output 插件
平台说明
input 使用 jolokia telegraf 工具提供jolokia相关插件去获取activemq自带的api暴露的指标信息
output 我用的是prometheus client0,这是一个Prometheus客户端,会建立一个自己的socket。
部署Telegraf
部署在被采集机器
下载安装包
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
测试activeMQ是否能访问api
curl -u <你的用户>:<你的密码> http://127.0.0.1:8161/api/jolokia/
和mq控制台的用户密码信息一样
配置修改
修改 /etc/telegraf/telegraf.conf
…
…
## Log file name, the empty string means to log to stderr.
logfile = "/var/log/telegraf/telegraf.log" #填写
## The logfile will be rotated after the time interval specified. When set
## to 0 no time based rotation is performed. Logs are rotated only when
## written to, if there is no log activity rotation may be delayed.
logfile_rotation_interval = "0d" #填写
## The logfile will be rotated when it becomes larger than the specified
## size. When set to 0 no size based rotation is performed.
logfile_rotation_max_size = "50MB" #填写
## Maximum number of rotated archives to keep, any older logs are deleted.
## If set to -1, no archives are removed.
logfile_rotation_max_archives = 50 #填写
…
…
#[[outputs.influxdb]] #注释
#增加注释[[outputs.influxdb]]
生成telegraf out配置文件
cd /etc/telegraf/telegraf.d.
vim output-prometheus-telegraf.conf
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# Configuration for the Prometheus client to spawn
[[outputs.prometheus_client]]
## Address to listen on
listen = ":30013"
## Use HTTP Basic Authentication.
# basic_username = "Foo"
# basic_password = "Bar"
## If set, the IP Ranges which are allowed to access metrics.
## ex: ip_range = ["192.168.0.0/24", "192.168.1.0/30"]
# ip_range = []
## Path to publish the metrics on.
# path = "/metrics"
## Expiration interval for each metric. 0 == no expiration
# expiration_interval = "60s"
## Collectors to enable, valid entries are "gocollector" and "process".
## If unset, both are enabled.
# collectors_exclude = ["gocollector", "process"]
## Send string metrics as Prometheus labels.
## Unless set to false all string metrics will be sent as labels.
# string_as_label = true
## If set, enable TLS with the given certificate.
# tls_cert = "/etc/ssl/telegraf.crt"
# tls_key = "/etc/ssl/telegraf.key"
## Set one or more allowed client CA certificate file names to
## enable mutually authenticated TLS connections
# tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"]
## Export metric collection time.
# export_timestamp = false
创建input配置文件
vim input-amq.conf
###############################################################################
# INPUT PLUGINS #
###############################################################################
# Read JMX metrics from a Jolokia REST agent endpoint
[[inputs.jolokia2_agent]]
urls = ["http://localhost:20097/api/jolokia"]
name_prefix = "activemq."
username = "system"
password = "manager"
### JVM Generic
[[inputs.jolokia2_agent.metric]]
name = "OperatingSystem"
mbean = "java.lang:type=OperatingSystem"
paths = ["ProcessCpuLoad","SystemLoadAverage","SystemCpuLoad"]
[[inputs.jolokia2_agent.metric]]
name = "jvm_runtime"
mbean = "java.lang:type=Runtime"
paths = ["Uptime"]
[[inputs.jolokia2_agent.metric]]
name = "jvm_threading"
mbean = "java.lang:type=Threading"
paths = ["ThreadCount"]
[[inputs.jolokia2_agent.metric]]
name = "jvm_memory"
mbean = "java.lang:type=Memory"
paths = ["HeapMemoryUsage", "NonHeapMemoryUsage", "ObjectPendingFinalizationCount"]
[[inputs.jolokia2_agent.metric]]
name = "jvm_garbage_collector"
mbean = "java.lang:name=*,type=GarbageCollector"
paths = ["CollectionTime", "CollectionCount"]
tag_keys = ["name"]
[[inputs.jolokia2_agent.metric]]
name = "jvm_memory_pool"
mbean = "java.lang:name=*,type=MemoryPool"
paths = ["Usage", "PeakUsage", "CollectionUsage"]
tag_keys = ["name"]
tag_prefix = "pool_"
### ACTIVEMQ
[[inputs.jolokia2_agent.metric]]
name = "queue"
mbean = "org.apache.activemq:brokerName=*,destinationName=*,destinationType=Queue,type=Broker"
paths = ["QueueSize","EnqueueCount","ConsumerCount","DispatchCount","DequeueCount","ProducerCount","InFlightCount"]
tag_keys = ["brokerName","destinationName"]
[[inputs.jolokia2_agent.metric]]
name = "topic"
mbean = "org.apache.activemq:brokerName=*,destinationName=*,destinationType=Topic,type=Broker"
paths = ["ProducerCount","DequeueCount","ConsumerCount","QueueSize","EnqueueCount"]
tag_keys = ["brokerName","destinationName"]
[[inputs.jolokia2_agent.metric]]
name = "broker"
mbean = "org.apache.activemq:brokerName=*,type=Broker"
paths = ["TotalConsumerCount","TotalMessageCount","TotalEnqueueCount","TotalDequeueCount","MemoryLimit","MemoryPercentUsage","StoreLimit","StorePercentUsage","TempPercentUsage","TempLimit"]
tag_keys = ["brokerName"]
启动
systemctl start telegraf
或者
/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
检查进程
#启动多个采集进程的示例
# ps -ef|grep telegraf
root 4176 27285 0 14:23 pts/0 00:00:03 telegraf --config 2-jolokia2_agent-telegraf.conf
root 4755 27285 0 14:24 pts/0 00:00:00 telegraf --config jolokia2_agent-telegraf.conf
root 5720 27285 0 14:25 pts/0 00:00:00 telegraf --config temp-telegraf.conf
#实际应用
# ps -ef|grep tele
root 558 29131 0 15:07 pts/1 00:00:00 grep --color=auto tele
telegraf 11443 1 0 14:57 ? 00:00:03 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d
验证有没有数据
curl -s http://127..0.0.1:9275/metrics
配置Prometheus
vim /data/prometheus/prometheus.yml
追加内容
- job_name: 'activemq'
file_sd_configs:
- files: ['/data/prometheus/sd_config/activemq-endpoint.yml']
refresh_interval: 30s
vim /data/prometheus/sd_config/activemq-endpoint.yml
新增内容
- targets:
- 172.16.0.61:30013
labels:
service: activemq
展示(Grafana)
添加相关数据源,修改下实际的指标就能使用
扩展篇
会写一下怎么调试和新增jolokia的指标