Skip to content

Commit

Permalink
Merge pull request #206 from rackerlabs/development
Browse files Browse the repository at this point in the history
Release 2.0.2
  • Loading branch information
tonyskapunk authored Feb 26, 2019
2 parents 4ceb5be + e1c712a commit 6d787d6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.

## [Unreleased] -

## [2.0.2] - 2018-02-25
- Dynamically find CPU field to sort top CPU report [(#203)][203]

## [2.0.1] - 2018-02-05
- Fix bug related to DESTDIR included in recap script [(#195)][195] [(#198)][198].

Expand Down Expand Up @@ -212,6 +215,7 @@ All notable changes to this project will be documented in this file.
[175]: https://github.com/rackerlabs/recap/issues/175
[195]: https://github.com/rackerlabs/recap/issues/195
[198]: https://github.com/rackerlabs/recap/issues/198
[203]: https://github.com/rackerlabs/recap/issues/203

<!---
# One-liners to help generate content for CHANGELOG.md
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ An ansible playbook could be used to install `recap` from a git repository. The
- `prefix` - The value of *PREFIX*, default: `/usr`.
- `tmp_install_dir` - The location where the cloned repo will be placed, default: `/tmp/recap`.
- `uninstall` - Then this is defined it will remove `recap`, default: *undefined*.
- `enable_plugins` - To enable the global plugin configuration default: `false`.
- `plugin_list` - A list of plugins to enable, from the `plugin-available` directory, default: `all`.

#### Install (default)

Expand All @@ -179,6 +181,23 @@ Install recap with *BINPATH* in `/bin`:

```
ansible-playbook tools/ansible_recap.yml -e binpath=/bin
```

Install recap with all plugins enabled:

```
ansible-playbook tools/ansible_recap.yml -e enable_plugins=true
```

Install recap with a list of plugins to enable:

```
ansible-playbook tools/ansible_recap.yml \
-e enable_plugins=true \
-e '{"plugin_list":[docker_top,redis]}'
```

#### Uninstall
Expand Down
24 changes: 12 additions & 12 deletions src/core/resources
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ print_top_10_cpu() {
local LOGFILE="$1"
log INFO "Starting 'top 10 cpu' report - ${LOGFILE##*/}"
local pidstat_cpufield=0
#We need to know whether the version of pidstat is > 10.1.4, since that added a UID field
local version_strings="$( pidstat -V 2>&1 |
awk '{if(NR==1){print $NF}}' ) 10.1.4"
local sorted_versions="$( echo ${version_strings} | tr ' ' '\n' |
sort --version-sort | tr '\n' ' ' )"
if [[ "${version_strings}" == "${sorted_versions}" ]]; then
pidstat_cpufield=6
else
pidstat_cpufield=7
fi
# Systat versions have the CPU field in different places.
# Calculate dynamically the %CPU field
local pidstat_fields=( $(LC_ALL=C pidstat | sed -n '3p') )
for index in $(seq 0 ${#pidstat_fields[@]}); do
if [[ "${pidstat_fields[${index}]}" == "%CPU" ]]; then
# Array is 0 index, sorting is not, we add 1
pidstat_cpufield=$(( ${index} + 1 ))
break
fi
done
echo "Top 10 cpu using processes" >> "${LOGFILE}"
# capture header
pidstat | sed -n '3p' >> "${LOGFILE}"
pidstat -l 2 2 | grep -v '%system' |
LC_ALL=C pidstat | sed -n '3p' >> "${LOGFILE}"
LC_ALL=C pidstat -l 2 2 | grep -v '%system' |
egrep ^Average: | sort -nr -k ${pidstat_cpufield} |
head -11 >> "${LOGFILE}"
log INFO "Ended 'top 10 cpu' report"
Expand Down
2 changes: 1 addition & 1 deletion src/recap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#~

## Version
declare -r _VERSION='2.0.1'
declare -r _VERSION='2.0.2'

## Default settings(can *NOT* be overridden in config file)
declare -r DATE=$( date +%F_%T )
Expand Down
2 changes: 1 addition & 1 deletion src/recaplog
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#~

## Version
declare -r _VERSION='2.0.1'
declare -r _VERSION='2.0.2'

## Default settings
PATH=/bin:/usr/bin:/sbin:/usr/sbin
Expand Down
2 changes: 1 addition & 1 deletion src/recaptool
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#~

## Version
declare -r _VERSION='2.0.1'
declare -r _VERSION='2.0.2'

## Default settings
BASEDIR="/var/log/recap"
Expand Down
40 changes: 40 additions & 0 deletions tools/ansible_recap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- git
- make
systemd_unit_dir: "{{ destdir }}/usr/lib/systemd/system"
enable_plugins: "no"
plugin_list:
- all
tasks:
- name: Set dependencies and timers
set_fact:
Expand Down Expand Up @@ -56,6 +59,43 @@
DESTDIR: "{{ destdir }}"
PREFIX: "{{ prefix }}"

- name: Enabling plugins
block:
- name: Finding all plugins available
block:
- name: Find all plugins
find:
paths: "{{ prefix }}/lib/recap/plugins-available"
register: plugins_found

- name: Create plugin list with all plugins found
set_fact:
plugin_list: "{{ plugin_list + [ item.path | basename ] }}"
with_items: "{{ plugins_found.files }}"
when: plugins_found.matched

- name: Remove "all" from list
set_fact:
plugin_list: "{{ plugin_list | difference(['all']) }}"

when: "'all' in plugin_list"

- name: enable plugins in global config
lineinfile:
path: /etc/recap.conf
insertafter: '#USEPLUGINS="no"'
line: 'USEPLUGINS="yes"'
state: present

- name: enable list of plugins
file:
dest: "{{ prefix }}/lib/recap/plugins-enabled/{{ item }}"
src: "{{ prefix }}/lib/recap/plugins-available/{{ item }}"
state: link
with_items: "{{ plugin_list }}"

when: enable_plugins

- name: Enable systemd timers
systemd:
name: "{{ item }}"
Expand Down

0 comments on commit 6d787d6

Please sign in to comment.