#!/usr/bin/env bash # Falsify the claims in monitoring-and-alerting-tools.html: that performance_schema/sys are # on by default and answer these questions without installing anything. # Standalone: SKIPs everything gracefully if no MySQL server is reachable. set -u PASS=0 FAIL=0 SKIP=0 CONTENT=0 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ARTICLE="$SCRIPT_DIR/monitoring-and-alerting-tools.html" pass() { echo "PASS: $1"; PASS=$((PASS+1)); } fail() { echo "FAIL: $1"; FAIL=$((FAIL+1)); } skip() { echo "SKIP: $1"; SKIP=$((SKIP+1)); } content_pass() { echo "CONTENT: $1"; CONTENT=$((CONTENT+1)); } MYSQL_BIN="$(command -v mysql || true)" CONNECTABLE=0 if [ -n "$MYSQL_BIN" ] && "$MYSQL_BIN" -u root -h 127.0.0.1 --connect-timeout=2 -e "SELECT 1;" >/dev/null 2>&1; then CONNECTABLE=1 fi if [ "$CONNECTABLE" = "0" ]; then skip "no local MySQL server reachable as root@127.0.0.1 - all live checks skipped" else # Claim 1: performance_schema is on by default. PS_ON=$("$MYSQL_BIN" -u root -h 127.0.0.1 -N -e "SHOW VARIABLES LIKE 'performance_schema';" 2>/dev/null | awk '{print $2}') if [ "$PS_ON" = "ON" ]; then pass "performance_schema is ON on this server (executed via SHOW VARIABLES)" else fail "performance_schema is not ON (got '$PS_ON') - the article's core claim does not hold here" fi # Claim 2: the sys schema exists and is queryable. SYS_COUNT=$("$MYSQL_BIN" -u root -h 127.0.0.1 -N -e "SELECT COUNT(*) FROM information_schema.schemata WHERE schema_name='sys';" 2>/dev/null) if [ "$SYS_COUNT" = "1" ]; then pass "sys schema exists on this server" else fail "sys schema not found" fi # Claim 3: events_statements_summary_by_digest is queryable and returns the columns cited. if "$MYSQL_BIN" -u root -h 127.0.0.1 -e "SELECT DIGEST_TEXT, COUNT_STAR, SUM_TIMER_WAIT FROM performance_schema.events_statements_summary_by_digest LIMIT 1;" >/dev/null 2>&1; then pass "performance_schema.events_statements_summary_by_digest is queryable with the columns cited in the article" else fail "could not query events_statements_summary_by_digest as shown in the article" fi # Claim 4: sys.statement_analysis is queryable. if "$MYSQL_BIN" -u root -h 127.0.0.1 -e "SELECT query, exec_count, total_latency FROM sys.statement_analysis LIMIT 1;" >/dev/null 2>&1; then pass "sys.statement_analysis is queryable with the columns cited in the article" else fail "could not query sys.statement_analysis as shown in the article" fi # Claim 5: the buffer pool hit ratio counters exist and are computable. READS=$("$MYSQL_BIN" -u root -h 127.0.0.1 -N -e "SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_reads';" 2>/dev/null | awk '{print $2}') REQS=$("$MYSQL_BIN" -u root -h 127.0.0.1 -N -e "SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read_requests';" 2>/dev/null | awk '{print $2}') if [ -n "$READS" ] && [ -n "$REQS" ] && [ "$REQS" -gt 0 ] 2>/dev/null; then RATIO=$(python3 -c "print(round((1-$READS/$REQS)*100,2))" 2>/dev/null || echo "") if [ -n "$RATIO" ]; then pass "buffer pool hit ratio computable from live counters: ${RATIO}% (reads=$READS requests=$REQS)" else fail "could not compute buffer pool hit ratio from live counters" fi else fail "Innodb_buffer_pool_reads / read_requests counters not available" fi fi # --- content regression guards --- if [ -f "$ARTICLE" ]; then if grep -qiE "]*>[^<]*FAQ" "$ARTICLE"; then fail "article still contains an FAQ heading block, which the brief bans" else content_pass "no FAQ heading block present (a prose mention of the old page's FAQ is fine)" fi if grep -q "no citation for any of them" "$ARTICLE" || grep -q "no basis" "$ARTICLE"; then content_pass "article explains why the old unsourced thresholds were removed" else fail "article dropped the explanation for removing the unsourced threshold table" fi if grep -q "buffer-pool-and-memory-tuning-guide" "$ARTICLE" && grep -q "mysqltuner-optimize-performance-guide" "$ARTICLE"; then content_pass "article links to the existing buffer-pool and MySQLTuner pages instead of re-teaching them" else fail "article is missing one of the required internal links (buffer-pool guide, MySQLTuner guide)" fi else skip "monitoring-and-alerting-tools.html not found next to this script (downloaded standalone) - content checks skipped" fi echo "PASS=$PASS FAIL=$FAIL SKIP=$SKIP CONTENT=$CONTENT" [ "$FAIL" -eq 0 ]