Skip to content

Stats groups: set up a metrics source and its collector port

Describes Stats 0.3.0.

The Stats module collects numbers over time, such as CPU load or queue length, from sources outside your site. Each source is a stats group: it has its own store for metrics and its own network port that the source sends its numbers to.

Where to find it

In the admin sidebar, open Stats, then Groups (/admin/stats/groups). The Stats module must be turned on in Modules, and you need the Stats permission.

Before any group can receive data, a developer has to set where the metric files are kept (see “For developers” below).

The Stats Groups page with no groups yet and New Group The Stats Groups page with no groups yet and New Group

Stats groups, none yet.

The groups list

The table shows each group’s Name, Key, Port and Status (active or paused). Click a name to open the group’s chart page. The Actions column:

  • Edit: change the group’s details.
  • Pause: stop listening on the port. The stored metrics are kept.
  • Resume: start listening again. Shown instead of Pause on a paused group.
  • Delete: asks you to confirm, then removes the group together with all of its stored metrics. It can’t be undone.

With no groups, the table says No stats groups yet. Create one to start collecting metrics.

Creating or editing a group

New Group opens the form. Edit opens the same form for an existing group.

  • Name: what the group is called in the admin, for example “Server 1”.
  • Key: lowercase letters, numbers, underscores and hyphens. It must be unique. It’s also the name of the file the metrics are stored in, so don’t change it once a source is sending data: the group would start again with an empty store.
  • Collector Port: the network port the source sends its lines to. A new group gets the lowest free port from the configured range (9100 to 9200 unless a developer changed it). Each group needs its own port.
  • Graphite Template (optional): splits dotted metric names into labels, for example *.forklift.metric. Leave it empty if the source uses tag syntax (metric;label=value) or plain metric names.
  • Description: a note for yourself, up to 1,000 characters.

Create Group or Save Changes saves the group and opens its chart page. Saving an active group restarts its listener with the new port and template.

The New Stats Group form: name, key, collector port, Graphite template and description The New Stats Group form: name, key, collector port, Graphite template and description

A new stats group.

Keep the port private

The collector protocol has no password or other sign-in. Anyone who can reach a group’s port can send it numbers. Limit who can reach the port with a firewall or a VPN; the module can’t do this for you.

What it doesn’t do

  • It doesn’t include a collector. Any program that can send a line of text over the network can feed a group (see the chart page guide for an example).
  • It doesn’t check that the port is free when you save. If the listener can’t start, the group is still saved and marked active, but it receives nothing.
  • It doesn’t move stored data when you change a group’s key.

For developers

Set where each group’s metric file is stored. Without it no group starts listening:

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

Optionally change the range new groups take their port from:

config :phoenix_kit_stats, port_range: 9100..9200

Run mix phoenix_kit.update after installing, to create the groups table.