Skip to content

Commit

Permalink
change format and add additional options
Browse files Browse the repository at this point in the history
  • Loading branch information
hors committed Jul 24, 2023
1 parent 72088dd commit 15ef2d4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions haproxy/dockerdir/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -e

log() {
local message=$1
local date=$(/usr/bin/date +"[%d/%b/%Y:%H:%M:%S.%3N]")
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")

echo "${date} ${message}"
echo "{\"time\":\"${date}\", \"message\": \"${message}\"}"
}

if [ "$1" = 'haproxy' ]; then
Expand Down
3 changes: 2 additions & 1 deletion haproxy/dockerdir/etc/haproxy/haproxy-global.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
stats socket /etc/haproxy/pxc/haproxy.sock mode 600 expose-fd listeners level admin

defaults
option tcplog
no option dontlognull
log-format '{"time":"%t", "client_ip": "%ci", "client_port":"%cp", "backend_source_ip": "%bi", "backend_source_port": "%bp", "frontend_name": "%ft", "backend_name": "%b", "server_name":"%s", "tw": "%Tw", "tc": "%Tc", "Tt": "%Tt", "bytes_read": "%B", "termination_state": "%ts", "actconn": "%ac", "feconn" :"%fc", "beconn": "%bc", "srv_conn": "%sc", "retries": "%rc", "srv_queue": "%sq", "backend_queue": "%bq" }'
default-server init-addr last,libc,none
log global
mode tcp
Expand Down
7 changes: 1 addition & 6 deletions haproxy/dockerdir/usr/bin/add_pxc_nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

set -o errexit

log() {
local message=$1
local date=$(/usr/bin/date +"[%d/%b/%Y:%H:%M:%S.%3N]")

echo "${date} ${message}"
}
. /entrypoint.sh

function main() {
log "Running $0"
Expand Down
15 changes: 8 additions & 7 deletions haproxy/dockerdir/usr/local/bin/check_pxc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ fi

log() {
local address=$1
local message=$2
local date=$(/usr/bin/date +"[%d/%b/%Y:%H:%M:%S.%3N]")
local port=$2
local message=$3
local date=$(/usr/bin/date +"%d/%b/%Y:%H:%M:%S.%3N")

echo "${address} ${date} ${message}"
echo "{\"time\":\"${date}\", \"backend_source_ip\": \"${address}\", \"backend_source_port\": \"${port}\", \"message\": \"${message}\"}"
}

PXC_NODE_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" $MYSQL_CMDLINE -h $PXC_SERVER_IP -P $PXC_SERVER_PORT \
Expand All @@ -41,15 +42,15 @@ PXC_NODE_STATUS=($(MYSQL_PWD="${MONITOR_PASSWORD}" $MYSQL_CMDLINE -h $PXC_SERVER
# ${PXC_NODE_STATUS[0]} - wsrep_local_state
# ${PXC_NODE_STATUS[1]} - pxc_maint_mod
# ${PXC_NODE_STATUS[2]} - wsrep_cluster_status
log "$PXC_SERVER_IP:$PXC_SERVER_PORT" "The following values are used for PXC node $PXC_SERVER_IP in backend $HAPROXY_PROXY_NAME:"
log "$PXC_SERVER_IP:$PXC_SERVER_PORT" "wsrep_local_state is ${PXC_NODE_STATUS[0]}; pxc_maint_mod is ${PXC_NODE_STATUS[1]}; wsrep_cluster_status is ${PXC_NODE_STATUS[2]}; $AVAILABLE_NODES nodes are available"
log "$PXC_SERVER_IP" "$PXC_SERVER_PORT" "The following values are used for PXC node $PXC_SERVER_IP in backend $HAPROXY_PROXY_NAME:"
log "$PXC_SERVER_IP" "$PXC_SERVER_PORT" "wsrep_local_state is ${PXC_NODE_STATUS[0]}; pxc_maint_mod is ${PXC_NODE_STATUS[1]}; wsrep_cluster_status is ${PXC_NODE_STATUS[2]}; $AVAILABLE_NODES nodes are available"
if [[ ${PXC_NODE_STATUS[2]} == 'Primary' && ( ${PXC_NODE_STATUS[0]} -eq 4 || \
${PXC_NODE_STATUS[0]} -eq 2 && ( "${AVAILABLE_NODES}" -le 1 || "${DONOR_IS_OK}" -eq 1 ) ) \
&& ${PXC_NODE_STATUS[1]} == 'DISABLED' ]];
then
log "$PXC_SERVER_IP:$PXC_SERVER_PORT" "PXC node $PXC_SERVER_IP for backend $HAPROXY_PROXY_NAME is ok"
log "$PXC_SERVER_IP" "$PXC_SERVER_PORT" "PXC node $PXC_SERVER_IP for backend $HAPROXY_PROXY_NAME is ok"
exit 0
else
log "$PXC_SERVER_IP:$PXC_SERVER_PORT" "PXC node $PXC_SERVER_IP for backend $HAPROXY_PROXY_NAME is not ok"
log "$PXC_SERVER_IP" "$PXC_SERVER_PORT" "PXC node $PXC_SERVER_IP for backend $HAPROXY_PROXY_NAME is not ok"
exit 1
fi

0 comments on commit 15ef2d4

Please sign in to comment.