Skip to content

Instantly share code, notes, and snippets.

@hkwi
Last active January 23, 2019 01:26
Show Gist options
  • Save hkwi/bafe1073eaf0abb2b437aa5127c4bc62 to your computer and use it in GitHub Desktop.
Save hkwi/bafe1073eaf0abb2b437aa5127c4bc62 to your computer and use it in GitHub Desktop.
kafka jmx_exporter instrumentation example
curl https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/lxd.py > ineventory.py
ansible-galaxy install -p roles sansible.zookeeper sansible.kafka
CLOUD_CFG=$(cat <<EOF
#cloud-config
ssh_pwauth: yes
password: password
chpasswd:
expire: false
EOF
)
lxc launch ubuntu:bionic demo -c user.user-data="$CLOUD_CFG"
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i inventory.py site.yml
---
- hosts: demo
vars:
ansible_user: ubuntu
ansible_ssh_pass: password
ansible_become: yes
ansible_python_interpreter: /usr/bin/python3
sansible_kafka_version_kafka: 0.11.0.1
sansible_kafka_version_scala: 2.12
pre_tasks:
- name: Update apt
become: yes
apt:
update_cache: yes
roles:
- role: sansible.zookeeper
- role: sansible.kafka
tasks:
- name: Download
get_url:
url: https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.11.0/jmx_prometheus_javaagent-0.11.0.jar
dest: /home/kafka/bin/jmx_prometheus_javaagent-0.11.0.jar
- name: Copy jmx_exporter config file
get_url:
url: https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-2_0_0.yml
dest: /home/kafka/etc/exporter.yml
when: sansible_kafka_version_kafka is version("2.0.0", ">=")
- name: Copy jmx_exporter config file
get_url:
url: https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-0-8-2.yml
dest: /home/kafka/etc/exporter.yml
when: sansible_kafka_version_kafka is version("2.0.0", "<")
- name: Add jmx_exporter
lineinfile:
path: /home/kafka/etc/environment
insertafter: '^JMX_PORT='
regexp: 'KAFKA_OPTS='
line: 'export KAFKA_OPTS="-javaagent:/home/kafka/bin/jmx_prometheus_javaagent-0.11.0.jar=8089:/home/kafka/etc/exporter.yml"'
- name: Stop kafka
systemd:
name: kafka
state: stopped
- name: Start kafka
systemd:
name: kafka
state: started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment