Skip to content

Commit

Permalink
Add mariadb health check
Browse files Browse the repository at this point in the history
  • Loading branch information
daaang committed Mar 15, 2024
1 parent ccdfac8 commit 8c22402
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def have_script
it { is_expected.to contain_file("/usr/local/lib/prom_web_exporter").with_ensure("directory") }
it { is_expected.to have_script.with_mode("0755") }
it { is_expected.to have_script.with_content(/^#!\/usr\/bin\/env bash$/) }
it { is_expected.to have_script.with_content(/^ENABLE_MARIADB_CHECK="false"$/) }
it { is_expected.to have_script.with_content(/^NFS_MOUNTS=\(\)$/) }
it { is_expected.to have_script.with_content(/^SOLR_INSTANCES=\(\)$/) }
it { is_expected.to have_script.with_content(/^ENABLE_SHIBD_CHECK="false"$/) }
Expand All @@ -39,6 +40,7 @@ def have_script
end

it { is_expected.to contain_package("mariadb-client") }
it { is_expected.to have_script.with_content(/^ENABLE_MARIADB_CHECK="true"$/) }
end

context "with nfs mounts set" do
Expand Down
24 changes: 24 additions & 0 deletions templates/profile/prometheus/exporter/webserver/metrics.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ set -eo pipefail
IFS=$'\n\t'
PROG="$0"
USAGE="[-h]"
<% if @target_mariadb.empty? -%>
ENABLE_MARIADB_CHECK="false"
<% else -%>
ENABLE_MARIADB_CHECK="true"
DB_HOST="<%= @target_mariadb["hostname"] %>"
DB_NAME="<%= @target_mariadb["database"] %>"
DB_USER="<%= @target_mariadb["username"] %>"
DB_PASS="<%= @target_mariadb["password"] %>"
<% end -%>
<% if @target_nfs.empty? -%>
NFS_MOUNTS=()
<% else -%>
Expand Down Expand Up @@ -52,6 +61,7 @@ shift $((OPTIND - 1))

main() {
print_headers
$ENABLE_MARIADB_CHECK && check_mariadb
[ -n "${NFS_MOUNTS[0]}" ] && check_nfs_mounts
[ -n "${SOLR_INSTANCES[0]}" ] && check_solr_instances
$ENABLE_SHIBD_CHECK && check_shibd
Expand All @@ -62,6 +72,20 @@ print_headers() {
echo ""
}

check_mariadb() {
echo "# HELP mlibrary_webserver_mariadb_up Check whether shibd is up"
echo "# TYPE mlibrary_webserver_mariadb_up gauge"
if mariadb_is_ok; then
echo "mlibrary_webserver_mariadb_up 1"
else
echo "mlibrary_webserver_mariadb_up 0"
fi
}

mariadb_is_ok() {
MYSQL_PWD="$DB_PASS" mariadb-check -c -h "$DB_HOST" -u "$DB_USER" "$DB_NAME" > /dev/null 2> /dev/null
}

check_nfs_mounts() {
echo "# HELP mlibrary_webserver_nfs_mount_up Check whether NFS mount is up"
echo "# TYPE mlibrary_webserver_nfs_mount_up gauge"
Expand Down

0 comments on commit 8c22402

Please sign in to comment.