3
0
mirror of https://github.com/rvalitov/zabbix-php-fpm.git synced 2023-11-05 03:30:27 +01:00

[add] parallel and non parallel tasks are independent

This commit is contained in:
Ramil Valitov 2020-09-21 15:11:00 +03:00
parent 44f3f5d567
commit 8423a7a1a1
No known key found for this signature in database
GPG Key ID: 2AB186DABDFE1914
2 changed files with 63 additions and 49 deletions

View File

@ -134,7 +134,7 @@ function restoreUserParameters() {
function AddSleepToConfig() {
PARAMS_FILE=$(getUserParameters)
sudo sed -i 's#.*zabbix_php_fpm_discovery.*#UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh sleep $1#' "$PARAMS_FILE"
sudo sed -i 's#.*zabbix_php_fpm_discovery.*#UserParameter=php-fpm.discover[*],sudo /etc/zabbix/zabbix_php_fpm_discovery.sh sleep max_tasks 1 $1#' "$PARAMS_FILE"
travis_fold_start "AddSleepToConfig" "ⓘ New UserParameter file"
sudo cat "$PARAMS_FILE"
travis_fold_end
@ -733,6 +733,7 @@ testZabbixDiscoverSleep() {
#Add sleep
AddSleepToConfig
StartTimer
testZabbixDiscoverReturnsData
printSuccess "${FUNCNAME[0]}"
}
@ -750,17 +751,6 @@ testDiscoverScriptRunDuration() {
printSuccess "${FUNCNAME[0]}"
}
testZabbixDiscoverRunDuration() {
#Add sleep
AddSleepToConfig
DATA=$(zabbix_get -s 127.0.0.1 -p 10050 -k php-fpm.discover["/php-fpm-status"])
printElapsedTime
assertExecutionTime
printSuccess "${FUNCNAME[0]}"
}
testDiscoverScriptDoubleRun() {
DATA_FIRST=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status")
DATA_SECOND=$(sudo -u zabbix sudo "/etc/zabbix/zabbix_php_fpm_discovery.sh" "debug" "sleep" "/php-fpm-status")

View File

@ -196,6 +196,22 @@ function PrintDebug() {
fi
}
function getPoolManagerByCode() {
local MANAGER_CODE=$1
local $PROCESS_MANAGER
if [[ $MANAGER_CODE -eq 1 ]]; then
PROCESS_MANAGER="dynamic"
elif [[ $MANAGER_CODE -eq 2 ]]; then
PROCESS_MANAGER="static"
elif [[ $MANAGER_CODE -eq 3 ]]; then
PROCESS_MANAGER="ondemand"
else
PROCESS_MANAGER=""
fi
echo $PROCESS_MANAGER
}
# Encodes input data to JSON and saves it to result string
# Input arguments:
# - pool name
@ -812,6 +828,18 @@ for POOL_ITEM in "${PENDING_LIST[@]}"; do
# shellcheck disable=SC2016
POOL_SOCKET=$(echo "$POOL_ITEM" | $S_AWK -F "$ARRAY_SEPARATOR" '{print $2}')
if [[ -n "$POOL_NAME" ]] && [[ -n "$POOL_SOCKET" ]]; then
if [[ $MAX_PARALLEL_TASKS -eq 1 ]]; then
#We work in standard mode (non-parallel)
ProcessPool "$POOL_NAME" "$POOL_SOCKET"
EXIT_CODE=$?
DeletePoolFromPendingList "$POOL_NAME" "$POOL_SOCKET"
PROCESS_MANAGER=$(getPoolManagerByCode $EXIT_CODE)
if [[ -n $PROCESS_MANAGER ]]; then
UpdatePoolInCache "$POOL_NAME" "$POOL_SOCKET" "$PROCESS_MANAGER"
fi
else
#We work in parallel mode
PARALLEL_TASKS=$((PARALLEL_TASKS + 1))
if [[ $PARALLEL_TASKS -le $MAX_PARALLEL_TASKS ]]; then
PrintDebug "Starting processing task for pool $POOL_NAME $POOL_SOCKET, subprocess #$PARALLEL_TASKS..."
@ -839,14 +867,8 @@ for POOL_ITEM in "${PENDING_LIST[@]}"; do
PrintDebug "Finished parallel task PID $TASK_PID for pool \"$POOL_NAME\" at $POOL_SOCKET"
DeletePoolFromPendingList "$POOL_NAME" "$POOL_SOCKET"
if [[ $EXIT_CODE -ge 1 ]] && [[ $EXIT_CODE -le 3 ]]; then
if [[ $EXIT_CODE -eq 1 ]]; then
PROCESS_MANAGER="dynamic"
elif [[ $EXIT_CODE -eq 2 ]]; then
PROCESS_MANAGER="static"
else
PROCESS_MANAGER="ondemand"
fi
PROCESS_MANAGER=$(getPoolManagerByCode $EXIT_CODE)
if [[ -n $PROCESS_MANAGER ]]; then
UpdatePoolInCache "$POOL_NAME" "$POOL_SOCKET" "$PROCESS_MANAGER"
fi
done
@ -854,6 +876,8 @@ for POOL_ITEM in "${PENDING_LIST[@]}"; do
PARALLEL_TASKS=0
TASK_LIST=()
fi
#End of parallel mode
fi
#Confirm that we run not too much time
CheckExecutionTime