Skip to content

4. Alerts

Vincenzo Reina edited this page Apr 21, 2025 · 10 revisions

Alert System

ServerPulse includes a robust alert system that can notify you about important server events through Discord. This guide covers setting up and customizing alerts.

Discord Integration Setup

Creating a Discord Webhook

  1. Open your Discord server settings
  2. Navigate to "Integrations" → "Webhooks"
  3. Click "Create Webhook"
  4. Choose a name and channel for alerts
  5. Copy the webhook URL

Configuring Discord Integration

  1. Open infra/grafana/provisioning/alerting/discord_contact.yml
  2. Replace the example webhook URL with yours:
apiVersion: 1
contactPoints:
  - orgId: 1
    name: Discord contact point
    receivers:
      - uid: deiz0m4w2afpcb
        type: discord
        settings:
          url: https://discord.com/api/webhooks/your-webhook  # Replace this
          message: '{{ template "discord.default.message" . }}'
          title: '{{ template "default.title" . }}'
  1. Restart Docker containers to apply changes:
docker compose down
docker compose up -d

Default Alert Rules

ServerPulse comes with pre-configured alerts:

TPS Monitoring

# From metrics.yml
condition: C
data:
  - refId: A
    datasourceUid: P5697886F9CA74929
    model:
      query: "from(bucket: \"metrics_db\")
        |> range(start: v.timeRangeStart)
        |> filter(fn: (r) => r._measurement == \"minecraft_stats\")
        |> filter(fn: (r) => r._field == \"tps_1m\")
        |> filter(fn: (r) => r.server == \"bed1\")"
  • Triggers when TPS drops below 18
  • Evaluates every 10 seconds
  • Includes 5-minute historical context

Customizing Alerts

Alert Timing

Edit infra/grafana/provisioning/alerting/contact_policy.yml:

apiVersion: 1
policies:
  - orgId: 1
    receiver: Discord contact point
    group_wait: 0s          # Initial wait before first alert
    group_interval: 30s     # Wait between alert groups
    repeat_interval: 3m     # Time before resending same alert

Creating New Alert Rules

To add new alerts, you'll need to create or modify files in the infra/grafana/provisioning/alerting/ directory.

  1. Create a new file (e.g., infra/grafana/provisioning/alerting/custom_alerts.yml):
apiVersion: 1
groups:
  - orgId: 1
    name: Custom Alerts
    folder: Metrics alerts
    interval: 10s
    rules:
      - uid: memory_alert          # Unique identifier
        title: High Memory Usage
        condition: C
        data:
          - refId: A
            relativeTimeRange:
              from: 600
              to: 0
            datasourceUid: P5697886F9CA74929
            model:
              query: |
                from(bucket: "metrics_db")
                  |> range(start: v.timeRangeStart)
                  |> filter(fn: (r) => r._measurement == "minecraft_stats")
                  |> filter(fn: (r) => r._field == "used_memory")
        notification_settings:
          receiver: Discord contact point
  1. Or modify the existing metrics.yml file in the same directory:
apiVersion: 1
groups:
  - orgId: 1
    name: Metrics evaluation
    folder: Metrics alerts
    interval: 10s
    rules:
      # Existing TPS alert here
      - uid: memory_alert          # Add new alert
        title: High Memory Usage
        # ... rest of alert configuration

After adding new alert files or modifying existing ones:

  1. Restart the Docker containers:
docker compose down
docker compose up -d
  1. Check Grafana's alert list to verify your new alerts appear

Testing Alerts

  1. Simulate low TPS:

    • Use a plugin or command to stress test the server
    • Wait for alert notification (should arrive within 30s)
  2. Verify Discord Integration:

    • Check Discord channel for alert messages
    • Confirm formatting and content

Related Pages

Clone this wiki locally