Aller au contenu

Dashboards

Guide pour créer et gérer les dashboards Grafana.

Dashboards Pré-configurés

Logs Overview

Chemin : Lyroh Apps > Logs Overview

Contient : - Vue d'ensemble des logs par application - Répartition par serveur et environnement - Timeline du volume - Détection des erreurs - Explorateur de logs avec filtres

Créer un Dashboard Applicatif

Template pour NestJS

{
  "title": "NestJS Backend Logs",
  "panels": [
    {
      "title": "Logs Stream",
      "type": "logs",
      "targets": [{
        "expr": "{app=\"nestjs-backend\", env=\"$env\"} |= \"$search\""
      }]
    },
    {
      "title": "Erreurs par Heure",
      "type": "timeseries",
      "targets": [{
        "expr": "sum(count_over_time({app=\"nestjs-backend\"} |~ \"error\" [$__interval]))"
      }]
    },
    {
      "title": "Logs par Niveau",
      "type": "piechart",
      "targets": [{
        "expr": "sum by (level) (count_over_time({app=\"nestjs-backend\"} | json [1h]))"
      }]
    }
  ]
}

Template pour Python Scraper

{
  "title": "Python Scraper Logs",
  "panels": [
    {
      "title": "Activité du Scraper",
      "type": "timeseries",
      "targets": [{
        "expr": "sum(count_over_time({app=\"python-scraper\"} [$__interval]))"
      }]
    },
    {
      "title": "Erreurs de Scraping",
      "type": "logs",
      "targets": [{
        "expr": "{app=\"python-scraper\"} |~ \"(?i)(error|exception|failed)\""
      }]
    },
    {
      "title": "URLs Traitées",
      "type": "stat",
      "targets": [{
        "expr": "count_over_time({app=\"python-scraper\"} |~ \"processed|fetched\" [1h])"
      }]
    }
  ]
}

Template pour NextJS

{
  "title": "NextJS App Logs",
  "panels": [
    {
      "title": "Build & Requests",
      "type": "logs",
      "targets": [{
        "expr": "{app=~\"nextjs-app-.*\", env=\"$env\"}"
      }]
    },
    {
      "title": "Erreurs par App",
      "type": "bargauge",
      "targets": [{
        "expr": "sum by (app) (count_over_time({app=~\"nextjs-app-.*\"} |~ \"error\" [1h]))"
      }]
    }
  ]
}

Variables de Dashboard

Définir une variable

  1. Dashboard settings (icône engrenage)
  2. Variables > Add variable

Variable app

Paramètre Valeur
Name app
Type Query
Data source Loki
Query label_values(app)
Multi-value Yes
Include All Yes

Variable env

Paramètre Valeur
Name env
Type Query
Data source Loki
Query label_values(env)
Multi-value No
Include All Yes

Variable search (texte)

Paramètre Valeur
Name search
Type Text box
Default `` (vide)

Panels Utiles

Compteur d'Erreurs (Stat)

count_over_time({app="$app", env="$env"} |~ "(?i)error" [$__range])
  • Unit : short
  • Color mode : Background
  • Thresholds : 0 (green), 10 (yellow), 50 (red)

Heatmap des Erreurs

sum by (app) (count_over_time({env="prod"} |~ "error" [$__interval]))
  • Type : Status history ou Heatmap

Top Erreurs (Table)

topk(10, sum by (app) (count_over_time({env="prod"} |~ "error" [24h])))

Logs Récents (Logs Panel)

{app="$app", env="$env"} |= "$search"

Options : - Show time: On - Show labels: On - Wrap lines: On

Organisation

Structure des Dossiers

Dashboards/
├── Lyroh Apps/
│   ├── Logs Overview
│   ├── NestJS Backend
│   ├── Python Scraper
│   └── NextJS Apps
├── Infrastructure/
│   └── Loki Health
└── Alerting/
    └── Error Dashboard

Créer un Dossier

  1. Dashboards > Browse
  2. New > New folder
  3. Nommez le dossier

Export / Import

Exporter un Dashboard

  1. Ouvrez le dashboard
  2. Share > Export
  3. Cochez Export for sharing externally
  4. Save to file

Importer un Dashboard

  1. Dashboards > Browse
  2. Import
  3. Uploadez le fichier JSON ou collez l'ID Grafana.com

Dashboards Communautaires

Grafana.com propose des dashboards prêts à l'emploi :

Pour importer : 1. Copiez l'ID du dashboard 2. Import > Grafana.com dashboard 3. Collez l'ID 4. Sélectionnez la datasource Loki