Skip to content

[Feature]: expose Prometheus /metrics — concurrent invokes, plugin process count, invoke latency #812

Closed

Description

@mahmut-Abi

Self Checks

I have searched existing issues/discussions — no feature request covers runtime metrics exposure for the plugin daemon.

Background

dify-plugin-daemon carries all LLM and tool invocations in self-hosted Dify (1.0+), yet exposes zero runtime metrics. Under high-concurrency workflow runs it is impossible to answer:

  • Is throughput limited by the daemon itself, a specific plugin, or the upstream model API?
  • How many invokes are queued vs executing, per plugin?
  • Which plugin is leaking processes or erroring silently?

We ended up correlating api-side outbound-latency alerts (which have no target-host dimension) with daemon pod restarts — a very lossy attribution path. A capacity incident is only confirmed after user-visible failures.

Requested metrics (Prometheus text format, /metrics endpoint)

Metric Type Labels Purpose
plugin_daemon_invokes_in_flight gauge plugin queued/executing invokes per plugin — the saturation signal
plugin_daemon_invoke_duration_seconds histogram plugin, outcome latency distribution per plugin
plugin_daemon_plugin_processes gauge plugin running plugin subprocesses (detect leaks)
plugin_daemon_invoke_errors_total counter plugin, error_class failures by class (timeout, crash, plugin error)

Standard Go runtime metrics (goroutines, GC, FDs) and process metrics would be a welcome bonus.

Acceptance

A /metrics endpoint (server port or dedicated), standard Prometheus text format, scrape-friendly.

Why it matters

The daemon is the LLM-calling choke point of every self-hosted deployment. With per-plugin in-flight gauges and latency histograms, bottleneck attribution becomes a dashboard query instead of a forensic exercise.

Activity

  1. jjj-n commented on Sep 20, 2026

    @jjj-n

    Hi, I'd like to work on this, but I would like to confirm the first-PR scope before implementing it.

    I propose an initial production-ready increment that adds:

    1. a Prometheus-compatible /metrics endpoint;
    2. invokes-in-flight by plugin;
    3. invoke duration by plugin and bounded outcome;
    4. invoke errors by plugin and a bounded error class;
    5. concurrency-focused tests proving gauges are decremented on success, error, timeout, and cancellation.

    I would keep plugin process counts out of the first PR unless there is already one authoritative lifecycle point that can expose the value without polling or duplicating process state.

    Do the maintainers have a preferred Prometheus library, and should /metrics be served on the existing HTTP listener or a separately configurable listener?

  2. Souravrajvi0 commented on Sep 20, 2026

    @Souravrajvi0
    Contributor

    Opened a PR that implements the metrics called out in this issue on top of the existing Prometheus endpoint (PROMETHEUS_ENABLED, default true in .env.example):

    • plugin_daemon_invokes_in_flight{plugin}
    • plugin_daemon_invoke_duration_seconds{plugin,outcome}
    • plugin_daemon_invoke_errors_total{plugin,error_class}
    • plugin_daemon_plugin_processes{plugin} (local runtime scale events + remote debug 0/1)

    Invoke metrics are recorded from the SSE invoke path (baseSSEWithSession). GET /metrics is now registered in addition to /metrics/.

    PR: #821 — will replace with actual PR number after create

    Happy to iterate on label naming or process-count semantics if maintainers prefer live instance counts over desired replica count from scale callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions