Created
May 13, 2020 04:43
-
-
Save jams008/89ee92306a9ac6700bd05e918d77c527 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
#!/bin/sh | |
## DO NOT EDIT | |
## This file is under PUPPET control | |
################################# | |
### ### | |
### Script for get statistics ### | |
### from local php-fpm ### | |
### ### | |
################################# | |
### OPTIONS VERIFICATION | |
if [ -z "$1" ];then | |
cat <<EOF | |
Usage: $0 <metric> [pool port] [url] | |
Options: | |
metric -- statistics metric | |
pool port -- fpm pool port, default 9001 | |
url -- php-fpm statistics url or ping url, default http://localhost/fpm-status?port=9001 and http://localhost/fpm-ping?port=9001 | |
EOF | |
exit 1 | |
fi | |
### PARAMETERS | |
METRIC="$1" | |
STATS_URL="https://localhost:22222/fpm/status/php73" | |
PING_URL="https://localhost:22222/fpm/status/ping" | |
CURL="curl -k" | |
CACHE_TTL="1" # TTL min | |
CACHE_FILE="/tmp/fpm-check" | |
### for ping | |
if [ x"$METRIC" = x"ping" ]; then | |
[ `$CURL $PING_URL 2>/dev/null | grep pong` ] && echo 0 || echo 1 | |
exit 0 | |
fi | |
### RUN | |
## Check cache file | |
CACHE_FIND=`find $CACHE_FILE -mmin -$CACHE_TTL 2> /dev/null` | |
if [ -z "$CACHE_FIND" ] || ! [ -s "$CACHE_FILE" ];then | |
$CURL $STATS_URL > $CACHE_FILE 2>/dev/null || exit 1 | |
fi | |
## output metrics | |
case $METRIC in | |
pool) | |
grep "^pool:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
process_manager) | |
grep "^process manager:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
start_time) | |
grep "^start time:" $CACHE_FILE | sed 's|^start time:\s\+||' | |
;; | |
start_since) | |
grep "^start since:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
accepted_conn) | |
grep "^accepted conn:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
listen_queue) | |
grep "^listen queue:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
max_listen_queue) | |
grep "^max listen queue:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
listen_queue_len) | |
grep "^listen queue len:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
idle_processes) | |
grep "^idle processes:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
active_processes) | |
grep "^active processes:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
total_processes) | |
grep "^total processes:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
max_active_processes) | |
grep "^max active processes:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
max_children_reached) | |
grep "^max children reached:" $CACHE_FILE | cut -d ":" -f 2 | sed 's|^\s\+||' | |
;; | |
*) | |
echo "Unsupported metric $METRIC" | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment