使用telegraf 能夠很好的採集相關的全部數據,並且是非入侵式java
基本主流的應用都能採,插件式的apache
分爲input 和 output 插件
平臺說明
input 使用 jolokia telegraf 工具提供jolokia相關插件去獲取activemq自帶的api暴露的指標信息
output 我用的是prometheus client0,這是一個Prometheus客戶端,會創建一個本身的socket。vim
部署在被採集機器api
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
less
curl -u <你的用戶>:<你的密碼> http://127.0.0.1:8161/api/jolokia/ 和mq控制檯的用戶密碼信息同樣
修改 /etc/telegraf/telegraf.confcurl
… … ## 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]]
cd /etc/telegraf/telegraf.d.
vim output-prometheus-telegraf.confjvm
############################################################################### # 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
vim input-amq.confsocket
############################################################################### # 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
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
添加相關數據源,修改下實際的指標就能使用
會寫一下怎麼調試和新增jolokia的指標