Last active
November 20, 2017 23:06
-
-
Save arminwasicek/93b07cfd811d539ae86398e00853ad8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: ansible-playbook -i hosts jvm-histo-playbook.yaml | |
--- | |
- hosts: memleak | |
tasks: | |
- name: Set target java process | |
set_fact: | |
target_jar: "memleak-assembly-0.1.jar" | |
- name: Setting up the destination directory | |
set_fact: | |
dest_dir: "./histo" | |
- name: Determine the file name for the histogram | |
set_fact: | |
histo_dir: "/tmp" | |
histo_file_base: "{{ inventory_hostname }}_jmap-histo-{{ ansible_date_time.epoch }}" | |
- name: Derive histo files | |
set_fact: | |
histo_file: "{{ histo_file_base }}.txt" | |
histo_csv_size: "{{ histo_file_base }}.size.csv" | |
histo_csv_count: "{{ histo_file_base }}.count.csv" | |
- name: Collect the pid of the jvm to monitor | |
shell: "cat {{ target_jar }}.pid" | |
register: command_output | |
- set_fact: | |
stream_pid: "{{ command_output.stdout }}" | |
- name: Dump class histogram from jvm | |
shell: sudo su vagrant -c "jmap -histo {{ stream_pid }} > /tmp/{{ histo_file }}" | |
- name: Convert object counts to csv | |
shell: "cat {{ histo_dir }}/{{ histo_file }} | tail -n +4 | head -n -1 | awk '{ print \"count.{{ inventory_hostname }}.\"$4, $2, {{ ansible_date_time.epoch }} }' > {{ histo_dir }}/{{ histo_csv_count }}" | |
- name: Convert object size to csv | |
shell: "cat {{ histo_dir }}/{{ histo_file }} | tail -n +4 | head -n -1 | awk '{ print \"size.{{ inventory_hostname }}.\"$4, $3, {{ ansible_date_time.epoch }} }' > {{ histo_dir }}/{{ histo_csv_size }}" | |
- name: Retrieve histo file for object counts from remote host | |
fetch: | |
src: "{{ histo_dir }}/{{ histo_csv_count }}" | |
dest: "{{ dest_dir }}/{{ histo_csv_count }}" | |
flat: yes | |
- name: Retrieve histo file for obejct size from remote host | |
fetch: | |
src: "{{ histo_dir }}/{{ histo_csv_size }}" | |
dest: "{{ dest_dir }}/{{ histo_csv_size }}" | |
flat: yes | |
- name: Remove csv size file from remote host | |
become: yes | |
become_user: root | |
file: | |
state: absent | |
path: "{{ histo_dir }}/{{ histo_csv_size }}" | |
- name: Remove csv count file from remote host | |
become: yes | |
become_user: root | |
file: | |
state: absent | |
path: "{{ histo_dir }}/{{ histo_csv_count }}" | |
- name: Remove raw object file from remote host | |
become: yes | |
become_user: root | |
file: | |
state: absent | |
path: "{{ histo_dir }}/{{ histo_file }}" | |
- hosts: local | |
tasks: | |
- name: Configuring Sumo collector ip | |
set_fact: | |
collectorip: "localhost" | |
- name: Configuring Sumo collector port | |
set_fact: | |
collectorport: "2003" | |
- name: Setting up the destination directory | |
set_fact: | |
dest_dir: "./histo" | |
- name: Send object counts and sizes | |
shell: "cat {{ item }} | nc -q0 {{ collectorip }} {{ collectorport }}" | |
with_fileglob: "{{ playbook_dir }}/{{ dest_dir }}/*" | |
- name: Remove files | |
file: | |
state: absent | |
path: "{{ item }}" | |
with_fileglob: "{{ playbook_dir }}/{{ dest_dir }}/*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment