Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show trigger tests and values in interface #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/RainGauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
8 changes: 5 additions & 3 deletions lib/RainGaugeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 'test_triggers'){
$result[] = array('name' => $file, 'short_name' => $file);
} else {
$result[] = array('name' => $file, 'short_name' => substr($file, 20));
}
}

return $result;
Expand Down
45 changes: 28 additions & 17 deletions scripts/raingauge_triggers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
source /etc/raingauge_rc

# Calculates rate (change in value over 1 second) for a given trigger command
# Gets previous value from file and calculates the change in values
get_delta() {
local counter_name="$1"
local new_value="$2"
file="${PT_STALK_COLLECT_DIR}/saved_trigger_values"
local file="/tmp/raingauge_saved_trigger_values"

if [[ ! -e "$file" ]]; then
touch "$file"
Expand All @@ -30,29 +29,41 @@ get_delta() {

# Function called by pt-stalk-raingauge
trg_plugin() {

local trigger_status=''

# Evaluate all trigger commands, calling get_delta if necessary
# e.g trigger_name="$(bash_command_to_execute)"
seconds_behind_master="$(mysql $EXT_ARGV -e "SHOW SLAVE STATUS\G" -ss | grep -i seconds_behind | awk '{print $2}')"
threads_running="$(mysql $EXT_ARGV -e "SHOW GLOBAL STATUS LIKE 'Threads_running'" -ss | awk '{print $2}')"
cpu_percentage="$(top -d 0.1 -bn2 | grep "Cpu(s)" | tail -n 1 | awk '{print $2+$4+$6}')"
threads_created="$(get_delta "threads_created" "$(mysql $EXT_ARGV -e "SHOW GLOBAL STATUS LIKE 'Threads_created'" -ss | awk '{print $2}')")"
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
# Nonzero value will cause pt-stalk-raingauge to collect and is used to reference which trigger was set off
# See which trigger set off collector by peeking in /var/log/pt-stalk.log
# Checks are formatted this way to handle comparisons involving floating point numbers
# To add new trigger, copy the format below and change variables, and increment echo number
if (( "$(echo "$seconds_behind_master" | awk '{print ($1 > 10)}')" )); then
echo '1' # seconds_behind_master
elif (( "$(echo "$threads_running" | awk '{print ($1 > 150)}')" )); then
echo '2' # threads_running
elif (( "$(echo "$cpu_percentage" | awk '{print ($1 > 50)}')" )); then
echo '3' # cpu_percentage
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
echo '4' # threads_created
# elif (( "$(echo "$_triggername" | awk '{print ($1 _comparison _threshold)}')" )); then
# echo '5' # _triggername
trigger_status='3'
elif (( "$(echo "$threads_running" | awk '{print ($1 > 150)}')" )); then
trigger_status='4'
else
echo '0' # Nothing triggered
trigger_status='0' # Nothing triggered
fi

if [[ $trigger_status != "0" ]]
then
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
4) threads_running -- $threads_running > 150
EOF
fi

echo $trigger_status
}
2 changes: 1 addition & 1 deletion views/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<?php foreach ($data as $f) { ?>
<?php
$this_ts = substr($f['name'], 0, 19);
if ($this_ts != $current_ts)
if ($this_ts != $current_ts && $this_ts != 'test_triggers')
{
$current_ts = $this_ts;
?>
Expand Down