Skip to content

feat(dashboard): add real metrics to manager dashboard#35

Open
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
edilsonoliveirama:feat/dashboard-metrics
Open

feat(dashboard): add real metrics to manager dashboard#35
edilsonoliveirama wants to merge 2 commits intoEvolutionAPI:mainfrom
edilsonoliveirama:feat/dashboard-metrics

Conversation

@edilsonoliveirama
Copy link
Copy Markdown

@edilsonoliveirama edilsonoliveirama commented Apr 20, 2026

Problem / Problema

EN: The /manager dashboard showed only a static placeholder text ("Dashboard content will be implemented here...") with no real data.

PT: O dashboard em /manager exibia apenas um texto placeholder estático, sem nenhum dado real.


Solution / Solução

EN: Created a standalone dashboard page that fetches live data from the existing API endpoints and displays real metrics, without touching the compiled bundle that powers the rest of the manager (instances, login, etc.).

PT: Criada uma página de dashboard standalone que busca dados em tempo real dos endpoints existentes da API e exibe métricas reais, sem tocar no bundle compilado que alimenta o restante do manager (instâncias, login, etc.).


Metrics / Métricas

Card Source / Fonte
Total de Instâncias GET /instance/all
Conectadas connected === true count
Desconectadas connected === false count
Servidor GET /server/ok + AlwaysOnline count
  • Instance table with status badge, phone, client name and AlwaysOnline indicator
  • Auto-refresh every 30s + manual refresh button
  • Reads apikey from localStorage (set by the existing login flow)

Changes / Alterações

  • manager/dashboard/index.html — standalone page (Tailwind CDN + vanilla JS fetch)
  • pkg/routes/routes.goGET /manager (exact) serves new dashboard; GET /manager/*any (wildcard) keeps original bundle intact
  • Dockerfile — copies manager/dashboard/ into final image
  • .gitignore — excludes manager build artifacts

Summary by Sourcery

Introduce a standalone manager dashboard at /manager that shows live metrics from existing API endpoints while keeping the original React manager bundle for other routes.

New Features:

  • Add a Tailwind-based HTML dashboard page that displays total, connected, disconnected, and AlwaysOnline instance metrics plus server status using live API data.
  • Serve the new dashboard at the exact /manager route and preserve client-side routing for other manager paths via the existing React bundle.
  • Enable automatic and manual refresh of dashboard data and show an instances table with status, phone, client name, and AlwaysOnline indicator.

Build:

  • Include the new manager/dashboard assets in the Docker image build output.

Chores:

  • Update .gitignore to exclude manager build artifacts from version control.

The /manager dashboard previously showed only a static placeholder
("Dashboard content will be implemented here..."). This replaces it
with a standalone HTML page that fetches live data from the API and
displays real metrics:

- Total instances count
- Connected instances count and percentage
- Disconnected instances count
- Server health status (GET /server/ok)
- AlwaysOnline count
- Instance table with name, status badge, phone number, client and
  AlwaysOnline indicator
- Auto-refresh every 30 seconds with manual refresh button

Implementation uses a standalone HTML file (Tailwind CDN + vanilla JS
fetch) served at GET /manager, keeping the existing compiled bundle
intact for all other routes (/manager/instances, /manager/login, etc.).

Changes:
- manager/dashboard/index.html: new self-contained dashboard page
- pkg/routes/routes.go: serve dashboard/index.html for GET /manager
  (exact), keep dist/index.html for GET /manager/*any (wildcard)
- Dockerfile: copy manager/dashboard/ into the final image
- .gitignore: exclude manager build artifacts from version control

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 20, 2026

Reviewer's Guide

Implements a new standalone HTML/JS manager dashboard served at /manager that fetches live metrics from existing API endpoints, while preserving the existing React manager bundle under /manager/*any and wiring the new assets into the Docker image and gitignore configuration.

Sequence diagram for manager dashboard data loading

sequenceDiagram
  actor ManagerUser
  participant Browser
  participant GinRouter
  participant DashboardHTML
  participant API_Instance
  participant API_Server

  ManagerUser->>Browser: Open /manager
  Browser->>GinRouter: GET /manager
  GinRouter-->>Browser: manager/dashboard/index.html
  Browser->>DashboardHTML: Parse and execute JS

  DashboardHTML->>Browser: Read apikey from localStorage
  DashboardHTML->>API_Instance: GET /instance/all with header apikey
  DashboardHTML->>API_Server: GET /server/ok with header apikey

  API_Instance-->>DashboardHTML: JSON instances list
  API_Server-->>DashboardHTML: JSON server status

  DashboardHTML->>Browser: Compute metrics (total, connected, disconnected, alwaysOnline)
  DashboardHTML->>Browser: Update metric cards and instance table

  loop every 30s
    DashboardHTML->>API_Instance: GET /instance/all with header apikey
    DashboardHTML->>API_Server: GET /server/ok with header apikey
    API_Instance-->>DashboardHTML: Updated JSON
    API_Server-->>DashboardHTML: Updated JSON
    DashboardHTML->>Browser: Update metrics and table
  end

  ManagerUser->>DashboardHTML: Click Atualizar button
  DashboardHTML->>API_Instance: Manual refresh GET /instance/all
  DashboardHTML->>API_Server: Manual refresh GET /server/ok
  API_Instance-->>DashboardHTML: JSON
  API_Server-->>DashboardHTML: JSON
  DashboardHTML->>Browser: Update metrics and table
Loading

Flow diagram for updated manager routing and assets

flowchart LR
  subgraph Client
    U[Manager user browser]
  end

  subgraph Server
    R[Gin_router]
    DHTML[manager/dashboard/index.html]
    DBundle[manager/dist/index.html]
  end

  subgraph ImageBuild[Docker image build]
    BDist[build output manager/dist]
    BDash[build output manager/dashboard]
    FinalImage[Final container image]
  end

  U -->|GET /manager| R
  U -->|GET /manager/instances etc| R

  R -->|serve file| DHTML
  R -->|serve file| DBundle

  BDist -->|COPY /build/manager/dist| FinalImage
  BDash -->|COPY /build/manager/dashboard| FinalImage

  style DHTML fill:#e0ffe0,stroke:#16a34a
  style DBundle fill:#e0f2ff,stroke:#2563eb
Loading

File-Level Changes

Change Details Files
Serve a new standalone dashboard HTML at /manager while keeping the existing React SPA routing under /manager/*any.
  • Reordered Gin routes so GET /manager serves manager/dashboard/index.html.
  • Added a new GET /manager/*any route that serves the existing manager/dist/index.html for all other manager paths.
  • Left the /assets static serving unchanged to continue serving compiled React assets.
pkg/routes/routes.go
Include the new dashboard assets in the container image build.
  • Copied manager/dashboard from the build stage into /app/manager/dashboard in the final Docker image alongside manager/dist.
  • Kept existing server and manager/dist copy steps intact.
Dockerfile
Add a static Tailwind-based dashboard page that fetches and displays live metrics from the API.
  • Created manager/dashboard/index.html as a standalone page using Tailwind via CDN and vanilla JavaScript.
  • Implemented API calls that read the apikey from localStorage and fetch /instance/all and /server/ok.
  • Derived metrics for total, connected, disconnected, and AlwaysOnline instances and server health, updating metric cards accordingly.
  • Rendered an auto-refreshing instances table with status badges, phone, client name, and AlwaysOnline indicator, with 30s polling and a manual refresh button.
  • Added simple utility helpers (apiFetch, set, renderTable, loadData) and basic loading/error handling in the UI.
manager/dashboard/index.html
Prevent manager build artifacts from being committed.
  • Updated .gitignore to exclude manager build outputs (exact patterns not shown in diff snippet).
.gitignore

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • When rendering the instances table, values like inst.name, inst.clientName, and inst.jid are interpolated directly into innerHTML, which can allow XSS if those fields ever contain untrusted data; consider building the table with createElement/textContent or sanitizing these fields before insertion.
  • apiKey is read from localStorage and used unconditionally in apiFetch, but the UI only shows a generic error when calls fail; it would be helpful to explicitly detect a missing/empty API key and present a clearer state/message to the user in that case.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When rendering the instances table, values like `inst.name`, `inst.clientName`, and `inst.jid` are interpolated directly into `innerHTML`, which can allow XSS if those fields ever contain untrusted data; consider building the table with `createElement`/`textContent` or sanitizing these fields before insertion.
- `apiKey` is read from `localStorage` and used unconditionally in `apiFetch`, but the UI only shows a generic error when calls fail; it would be helpful to explicitly detect a missing/empty API key and present a clearer state/message to the user in that case.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Replaces innerHTML interpolation of server-supplied fields (name,
clientName, jid) with DOM createElement/textContent to eliminate
potential XSS.

Also detects a missing or empty API key before making any requests and
renders an actionable message explaining how to set it, instead of
showing a generic fetch error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant