mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Add statsd_exporter to app PaaS startup scripts
`statsd_exporter` is only started if `STATSD_HOST` is set to `localhost`.
This commit is contained in:
@@ -69,10 +69,20 @@ function start_aws_logs_agent {
|
|||||||
echo "AWS logs agent pid: ${AWSLOGS_AGENT_PID}"
|
echo "AWS logs agent pid: ${AWSLOGS_AGENT_PID}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function start_statsd_exporter {
|
||||||
|
echo "Starting statsd exporter..."
|
||||||
|
exec ./scripts/statsd_exporter --web.listen-address=":${PORT}" --statsd.listen-udp=":8125" --statsd.mapping-config=statsd_mapping.yml &
|
||||||
|
STATSD_EXPORTER_PID=$!
|
||||||
|
echo "Statsd exporter pid: ${STATSD_EXPORTER_PID}"
|
||||||
|
}
|
||||||
|
|
||||||
function run {
|
function run {
|
||||||
while true; do
|
while true; do
|
||||||
kill -0 ${APP_PID} 2&>/dev/null || break
|
kill -0 ${APP_PID} 2&>/dev/null || break
|
||||||
kill -0 ${AWSLOGS_AGENT_PID} 2&>/dev/null || start_aws_logs_agent
|
kill -0 ${AWSLOGS_AGENT_PID} 2&>/dev/null || start_aws_logs_agent
|
||||||
|
if [ "${STATSD_HOST}" == "localhost" ]; then
|
||||||
|
kill -0 ${STATSD_EXPORTER_PID} 2&>/dev/null || start_statsd_exporter
|
||||||
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -84,6 +94,9 @@ check_params
|
|||||||
trap "on_exit" EXIT
|
trap "on_exit" EXIT
|
||||||
|
|
||||||
configure_aws_logs
|
configure_aws_logs
|
||||||
|
if [ "${STATSD_HOST}" == "localhost" ]; then
|
||||||
|
start_statsd_exporter
|
||||||
|
fi
|
||||||
|
|
||||||
# The application has to start first!
|
# The application has to start first!
|
||||||
start_application "$@"
|
start_application "$@"
|
||||||
|
|||||||
@@ -84,23 +84,33 @@ function send_signal_to_celery_processes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function start_application {
|
function start_application {
|
||||||
|
echo "Starting application..."
|
||||||
eval "$@"
|
eval "$@"
|
||||||
get_celery_pids
|
get_celery_pids
|
||||||
echo "Application process pids: "${APP_PIDS}
|
echo "Application process pids: "${APP_PIDS}
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_aws_logs_agent {
|
function start_aws_logs_agent {
|
||||||
|
echo "Starting aws logs agent..."
|
||||||
exec aws logs push --region eu-west-1 --config-file /home/vcap/app/awslogs.conf &
|
exec aws logs push --region eu-west-1 --config-file /home/vcap/app/awslogs.conf &
|
||||||
AWSLOGS_AGENT_PID=$!
|
AWSLOGS_AGENT_PID=$!
|
||||||
echo "AWS logs agent pid: ${AWSLOGS_AGENT_PID}"
|
echo "AWS logs agent pid: ${AWSLOGS_AGENT_PID}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_logs_tail {
|
function start_logs_tail {
|
||||||
|
echo "Starting logs tail..."
|
||||||
exec tail -n0 -f ${LOGS_DIR}/app.log.json &
|
exec tail -n0 -f ${LOGS_DIR}/app.log.json &
|
||||||
LOGS_TAIL_PID=$!
|
LOGS_TAIL_PID=$!
|
||||||
echo "tail pid: ${LOGS_TAIL_PID}"
|
echo "tail pid: ${LOGS_TAIL_PID}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function start_statsd_exporter {
|
||||||
|
echo "Starting statsd exporter..."
|
||||||
|
exec ./scripts/statsd_exporter --web.listen-address=":${PORT}" --statsd.listen-udp=":8125" --statsd.mapping-config=statsd_mapping.yml &
|
||||||
|
STATSD_EXPORTER_PID=$!
|
||||||
|
echo "Statsd exporter pid: ${STATSD_EXPORTER_PID}"
|
||||||
|
}
|
||||||
|
|
||||||
function ensure_celery_is_running {
|
function ensure_celery_is_running {
|
||||||
if [ "${APP_PIDS}" = "" ]; then
|
if [ "${APP_PIDS}" = "" ]; then
|
||||||
echo "There are no celery processes running, this container is bad"
|
echo "There are no celery processes running, this container is bad"
|
||||||
@@ -116,6 +126,7 @@ function ensure_celery_is_running {
|
|||||||
echo "Killing awslogs_agent and tail"
|
echo "Killing awslogs_agent and tail"
|
||||||
kill -9 ${AWSLOGS_AGENT_PID}
|
kill -9 ${AWSLOGS_AGENT_PID}
|
||||||
kill -9 ${LOGS_TAIL_PID}
|
kill -9 ${LOGS_TAIL_PID}
|
||||||
|
kill -9 ${STATSD_EXPORTER_PID}
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -132,6 +143,9 @@ function run {
|
|||||||
done
|
done
|
||||||
kill -0 ${AWSLOGS_AGENT_PID} 2&>/dev/null || start_aws_logs_agent
|
kill -0 ${AWSLOGS_AGENT_PID} 2&>/dev/null || start_aws_logs_agent
|
||||||
kill -0 ${LOGS_TAIL_PID} 2&>/dev/null || start_logs_tail
|
kill -0 ${LOGS_TAIL_PID} 2&>/dev/null || start_logs_tail
|
||||||
|
if [ "${STATSD_HOST}" == "localhost" ]; then
|
||||||
|
kill -0 ${STATSD_EXPORTER_PID} 2&>/dev/null || start_statsd_exporter
|
||||||
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -143,6 +157,9 @@ check_params
|
|||||||
trap "on_exit" EXIT
|
trap "on_exit" EXIT
|
||||||
|
|
||||||
configure_aws_logs
|
configure_aws_logs
|
||||||
|
if [ "${STATSD_HOST}" == "localhost" ]; then
|
||||||
|
start_statsd_exporter
|
||||||
|
fi
|
||||||
|
|
||||||
# The application has to start first!
|
# The application has to start first!
|
||||||
start_application "$@"
|
start_application "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user