🔍 Health Monitor & Alerts (Cloudflare Pages) #23
This file contains hidden or 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
| name: 🔍 Health Monitor & Alerts (Cloudflare Pages) | |
| on: | |
| schedule: | |
| # Run every 6 hours to monitor site health | |
| - cron: '0 */6 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| issues: write | |
| jobs: | |
| health-monitor: | |
| name: 🏥 Continuous Health Monitor | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: 🔍 Site availability check | |
| id: health_check | |
| run: | | |
| echo "🔍 Checking site health..." | |
| # Initialize counters | |
| FAILED_CHECKS=0 | |
| TOTAL_CHECKS=0 | |
| # Function to check URL | |
| check_url() { | |
| local url=$1 | |
| local name=$2 | |
| TOTAL_CHECKS=$((TOTAL_CHECKS + 1)) | |
| if curl -f -s -o /dev/null --max-time 10 "$url"; then | |
| echo "✅ $name: OK" | |
| return 0 | |
| else | |
| echo "❌ $name: FAILED" | |
| FAILED_CHECKS=$((FAILED_CHECKS + 1)) | |
| return 1 | |
| fi | |
| } | |
| # Check main endpoints | |
| check_url "https://sergiomarquez.dev" "Homepage" | |
| check_url "https://sergiomarquez.dev/privacy" "Privacy Page" | |
| # Set outputs for next steps | |
| echo "failed_checks=$FAILED_CHECKS" >> $GITHUB_OUTPUT | |
| echo "total_checks=$TOTAL_CHECKS" >> $GITHUB_OUTPUT | |
| if [ "$FAILED_CHECKS" -gt 0 ]; then | |
| echo "⚠️ Health check failed: $FAILED_CHECKS/$TOTAL_CHECKS checks failed" | |
| exit 1 | |
| else | |
| echo "✅ All health checks passed: $TOTAL_CHECKS/$TOTAL_CHECKS" | |
| fi | |
| - name: 📊 Performance monitoring | |
| if: success() | |
| run: | | |
| echo "📊 Performance check..." | |
| # Measure homepage load time | |
| START_TIME=$(date +%s%N) | |
| curl -f -s -o /dev/null "https://sergiomarquez.dev" | |
| END_TIME=$(date +%s%N) | |
| DURATION=$(( (END_TIME - START_TIME) / 1000000 )) | |
| echo "⏱️ Homepage load time: ${DURATION}ms" | |
| # Check if performance is acceptable | |
| if [ "$DURATION" -gt 5000 ]; then | |
| echo "⚠️ Performance degradation detected: ${DURATION}ms" | |
| echo "PERFORMANCE_ISSUE=true" >> $GITHUB_ENV | |
| else | |
| echo "✅ Performance acceptable: ${DURATION}ms" | |
| fi | |
| - name: 🤖 Create issue for failures | |
| if: failure() | |
| uses: actions/github-script@v7.0.1 | |
| with: | |
| script: | | |
| const title = `🚨 Site Health Check Failed - ${new Date().toISOString().split('T')[0]}`; | |
| const body = ` | |
| ## 🚨 Automated Health Check Failure | |
| **Timestamp**: ${new Date().toISOString()} | |
| **Failed Checks**: ${{ steps.health_check.outputs.failed_checks }}/${{ steps.health_check.outputs.total_checks }} | |
| ### 🔍 What to check: | |
| - [ ] Site accessibility: https://sergiomarquez.dev | |
| - [ ] Privacy page: https://sergiomarquez.dev/privacy | |
| ### 🛠️ Potential causes: | |
| - Cloudflare Pages deployment issue | |
| - DNS issues | |
| - SSL certificate problems | |
| - Build failure in Cloudflare | |
| ### 🔧 Next steps: | |
| 1. Check Cloudflare Pages dashboard | |
| 2. Verify latest deployment status | |
| 3. Check build logs in Cloudflare | |
| 4. Verify DNS configuration | |
| 5. Run manual health checks | |
| ### 🌐 Cloudflare Pages Info: | |
| - Auto-deploy from main branch | |
| - Build command: \`bun run build\` | |
| - Output directory: \`dist\` | |
| --- | |
| *This issue was automatically created by the health monitor workflow.* | |
| `; | |
| // Check if similar issue already exists | |
| const { data: issues } = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'health-check,automated' | |
| }); | |
| const existingIssue = issues.find(issue => | |
| issue.title.includes('Site Health Check Failed') && | |
| issue.created_at > new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() | |
| ); | |
| if (!existingIssue) { | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['bug', 'health-check', 'automated', 'high-priority', 'cloudflare'] | |
| }); | |
| console.log('Created new health check issue'); | |
| } else { | |
| console.log('Similar issue already exists, skipping creation'); | |
| } | |
| - name: 📈 Log successful check | |
| if: success() | |
| run: | | |
| echo "✅ Health monitoring completed successfully" | |
| echo "📊 All systems operational" | |
| echo "🌐 Cloudflare Pages deployment healthy" | |
| echo "🕐 Next check in 6 hours" |