PhoenixKitStats (PhoenixKitStats v0.2.0)

Copy Markdown View Source

PhoenixKit plugin module for collecting and charting time-series stats.

An admin creates a stats group (e.g. "server1") representing one external data source. Each group gets its own Barograph database (a single SQLite file) and a dedicated Graphite plaintext TCP port. Whatever collector process runs on that source writes metric value timestamp lines to the port; the admin picks a metric on the group's page and gets a live SVG chart.

How it works

  1. use PhoenixKit.Module marks this module as a plugin (persists a @phoenix_kit_module attribute in the .beam file).
  2. PhoenixKit scans .beam files at startup and discovers this module automatically — no config line needed.
  3. children/0 starts PhoenixKitStats.DatabaseManager, which opens every active group's Barograph database + Graphite listener.
  4. migration_module/0 points at PhoenixKitStats.Migrations.Schema, which mix phoenix_kit.update uses to create/upgrade phoenix_kit_stats_groups in the host app's database — no core phoenix_kit PR required.

Installation

Add to your parent app's mix.exs:

{:phoenix_kit_stats, "~> 0.2"}

Then configure where per-group Barograph files are stored (required):

config :phoenix_kit_stats, data_dir: "/var/data/phoenix_kit_stats"

Optionally override the port range groups auto-allocate collector ports from (default 9100..9200):

config :phoenix_kit_stats, port_range: 9100..9200

Run mix deps.get, then mix phoenix_kit.update to create the phoenix_kit_stats_groups table. The module appears in the admin sidebar and Modules page automatically.

Security note

Graphite's plaintext protocol has no built-in authentication — each group's collector port is a bare TCP listener. Restrict who can reach those ports at the network layer (firewall / VPN / private interface); this module cannot enforce access control on the wire protocol itself.

Navigation paths

All navigation goes through PhoenixKitStats.Paths, which wraps PhoenixKit.Utils.Routes.path/1 for prefix/locale handling.

Summary

Functions

Admin sidebar tabs: a parent tab plus a visible "Groups" list and hidden leaf tabs for the new/edit/show pages. Static /new is ordered before the :uuid wildcard tabs so PhoenixKit's route generation (which registers routes in list order) doesn't let the wildcard shadow it.

Starts PhoenixKitStats.DatabaseManager under the host's PhoenixKit.Supervisor (via PhoenixKit.ModuleRegistry.static_children/0). No host-app supervision tree changes needed.

OTP apps whose templates Tailwind should scan for CSS classes.

Disables the module. Same pattern as enable_system/0.

Enables the module by persisting a boolean setting.

Whether the module is currently enabled.

Versioned migration coordinator for phoenix_kit_stats_groups. Picked up automatically by mix phoenix_kit.update — this module's table is not part of core phoenix_kit's own migration chain.

Unique key for this module. Used in settings, permissions, and PubSub events.

Display name shown in the admin UI.

Permission metadata for the roles/permissions matrix.

Version string. Shown on the admin Modules page.

Functions

admin_tabs()

Admin sidebar tabs: a parent tab plus a visible "Groups" list and hidden leaf tabs for the new/edit/show pages. Static /new is ordered before the :uuid wildcard tabs so PhoenixKit's route generation (which registers routes in list order) doesn't let the wildcard shadow it.

children()

Starts PhoenixKitStats.DatabaseManager under the host's PhoenixKit.Supervisor (via PhoenixKit.ModuleRegistry.static_children/0). No host-app supervision tree changes needed.

css_sources()

OTP apps whose templates Tailwind should scan for CSS classes.

disable_system()

Disables the module. Same pattern as enable_system/0.

enable_system()

Enables the module by persisting a boolean setting.

enabled?()

Whether the module is currently enabled.

Reads from the DB-backed settings table. Defensive against DB not being available yet (startup ordering, missing table, sandbox artifacts in tests) — always falls back to false.

migration_module()

Versioned migration coordinator for phoenix_kit_stats_groups. Picked up automatically by mix phoenix_kit.update — this module's table is not part of core phoenix_kit's own migration chain.

module_key()

Unique key for this module. Used in settings, permissions, and PubSub events.

module_name()

Display name shown in the admin UI.

permission_metadata()

Permission metadata for the roles/permissions matrix.

version()

Version string. Shown on the admin Modules page.