From a245ea7a8e8c0c41b39710c64098494dc0f0c675 Mon Sep 17 00:00:00 2001 From: Matt Agra Date: Tue, 19 Aug 2014 16:53:33 -0700 Subject: [PATCH 1/4] Show test_triggers file in RainGauge interface --- lib/RainGauge.php | 8 ++--- lib/RainGaugeModel.php | 8 +++-- scripts/raingauge_triggers.sh | 65 +++++++++++++++++++++++++++++++++++ views/sample.php | 2 +- 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100755 scripts/raingauge_triggers.sh diff --git a/lib/RainGauge.php b/lib/RainGauge.php index daf47a0..8be0e39 100644 --- a/lib/RainGauge.php +++ b/lib/RainGauge.php @@ -130,11 +130,11 @@ public function sample() { $data['page'] = get_var('page'); $file_type = $this->model->get_type($data['file']); - if (get_var('file_type') != null) { + if (get_var('file_type') != null) { $data['file'] = $this_ts = substr($data['data'][0]['name'], 0, 19) . '-' . get_var('file_type'); - $file_type = get_var('file_type'); - } - $data['file_type'] = $file_type; + $file_type = get_var('file_type'); + } + $data['file_type'] = $file_type; if (isset($data['file']) and $data['file'] != '') { $paged_file = $this->model->get_file_pages($data['server'], $data['sample'], $data['file']); diff --git a/lib/RainGaugeModel.php b/lib/RainGaugeModel.php index f892c65..7a04c4b 100644 --- a/lib/RainGaugeModel.php +++ b/lib/RainGaugeModel.php @@ -115,9 +115,11 @@ function get_sample($hostname, $filename) { if (in_array($file, array('.', '..'))) { continue; } - $result[] = array('name' => $file, - 'short_name' => substr($file, 20) - ); + if ($file == 'saved_trigger_values'){ + $result[] = array('name' => $file, 'short_name' => $file); + } else { + $result[] = array('name' => $file, 'short_name' => substr($file, 20)); + } } return $result; diff --git a/scripts/raingauge_triggers.sh b/scripts/raingauge_triggers.sh new file mode 100755 index 0000000..2db4102 --- /dev/null +++ b/scripts/raingauge_triggers.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Created by: Matt Agra +# Created on: 07.25.2014 +# +# This script builds the custom trg_plugin function used by pt-stalk-rainguage +# + +# Gets previous value from file and calculates the change in values +get_delta() { + local counter_name="$1" + local new_value="$2" + local file="/tmp/raingauge_saved_trigger_values" + + if [[ ! -e "$file" ]]; then + touch "$file" + fi + + local last_value="$(cat "$file" | grep "$counter_name" | awk '{print $2}')" + + if [[ -z "$last_value" ]]; then + echo 0 + else + echo "$(( new_value - last_value ))" + sed -i "/${counter_name}/d" "$file" + fi + echo -e "${counter_name}\t${new_value}" >> "$file" +} + +# Function called by pt-stalk-raingauge +trg_plugin() { + + local trigger_status='' + + # Evaluate all trigger commands, calling get_delta if necessary + local cpu_percentage="$(top -d 0.1 -bn2 | grep "Cpu(s)" | tail -n 1 | awk -F',' '{print 100 - $4}')" + local seconds_behind_master="$(mysql $EXT_ARGV -e "SHOW SLAVE STATUS\G" -ss | grep -i seconds_behind | awk '{print $2}')" + local threads_created="$(get_delta "threads_created" "$(mysql $EXT_ARGV -e "SHOW GLOBAL STATUS LIKE 'Threads_created'" -ss | awk '{print $2}')")" + local threads_running="$(mysql $EXT_ARGV -e "SHOW GLOBAL STATUS LIKE 'Threads_running'" -ss | awk '{print $2}')" + + # Check triggers against their threshold + if (( "$(echo "$cpu_percentage" | awk '{print ($1 > 50)}')" )); then + trigger_status='1' + elif (( "$(echo "$seconds_behind_master" | awk '{print ($1 > 10)}')" )); then + trigger_status='2' + elif (( "$(echo "$threads_created" | awk '{print ($1 > 100)}')" )); then + trigger_status='3' + elif (( "$(echo "$threads_running" | awk '{print ($1 > 150)}')" )); then + trigger_status='4' + else + trigger_status='0' # Nothing triggered + fi + + if [[ $trigger_status != "0" ]] + then + cat << EOF > /tmp/raingauge/test_triggers + 1) cpu_percentage -- $cpu_percentage > 50 + 2) seconds_behind_master -- $seconds_behind_master > 10 + 3) threads_created -- $threads_created > 100 + 4) threads_running -- $threads_running > 150 +EOF + fi + + echo $trigger_status +} diff --git a/views/sample.php b/views/sample.php index a219d5b..5cca1d9 100644 --- a/views/sample.php +++ b/views/sample.php @@ -35,7 +35,7 @@ From 55c6af5dc8d88a36eb7921f5d0abb4aef6370052 Mon Sep 17 00:00:00 2001 From: Matt Agra Date: Tue, 19 Aug 2014 17:36:02 -0700 Subject: [PATCH 2/4] Include test_triggers in raingauge interface --- lib/RainGaugeModel.php | 2 +- views/sample.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/RainGaugeModel.php b/lib/RainGaugeModel.php index ca68ddb..6e40aaf 100644 --- a/lib/RainGaugeModel.php +++ b/lib/RainGaugeModel.php @@ -115,7 +115,7 @@ function get_sample($hostname, $filename) { if (in_array($file, array('.', '..'))) { continue; } - if ($file == 'saved_trigger_values'){ + if ($file == 'test_triggers'){ $result[] = array('name' => $file, 'short_name' => $file); } else { $result[] = array('name' => $file, 'short_name' => substr($file, 20)); diff --git a/views/sample.php b/views/sample.php index 5cca1d9..003c184 100644 --- a/views/sample.php +++ b/views/sample.php @@ -35,7 +35,7 @@ From 0dc44c0a9f0dd1488dbc4ea31db2179d71ce02d7 Mon Sep 17 00:00:00 2001 From: Matt Agra Date: Thu, 21 Aug 2014 11:56:46 -0700 Subject: [PATCH 3/4] Get collect dir from raingauge_rc --- scripts/raingauge_triggers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/raingauge_triggers.sh b/scripts/raingauge_triggers.sh index 3698666..e9c4da3 100755 --- a/scripts/raingauge_triggers.sh +++ b/scripts/raingauge_triggers.sh @@ -57,7 +57,7 @@ trg_plugin() { if [[ $trigger_status != "0" ]] then - cat << EOF > /tmp/raingauge/test_triggers + cat << EOF > ${PT_STALK_COLLECT_DIR}/test_triggers 1) cpu_percentage -- $cpu_percentage > 50 2) seconds_behind_master -- $seconds_behind_master > 10 3) threads_created -- $threads_created > 100 From 18fbac674f32e713eadb9c5bd1ff56e9ec84c72a Mon Sep 17 00:00:00 2001 From: Matt Agra Date: Fri, 22 Aug 2014 13:04:53 -0700 Subject: [PATCH 4/4] Saving lives with quotes --- scripts/raingauge_triggers.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/raingauge_triggers.sh b/scripts/raingauge_triggers.sh index e9c4da3..d476253 100755 --- a/scripts/raingauge_triggers.sh +++ b/scripts/raingauge_triggers.sh @@ -57,7 +57,7 @@ trg_plugin() { if [[ $trigger_status != "0" ]] then - cat << EOF > ${PT_STALK_COLLECT_DIR}/test_triggers + cat << EOF > "${PT_STALK_COLLECT_DIR}/test_triggers" 1) cpu_percentage -- $cpu_percentage > 50 2) seconds_behind_master -- $seconds_behind_master > 10 3) threads_created -- $threads_created > 100