Skip to content

Commit

Permalink
Prepare directory for mod_prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
badlop committed Jul 2, 2024
1 parent 13066cb commit d820350
Show file tree
Hide file tree
Showing 8 changed files with 1,276 additions and 0 deletions.
342 changes: 342 additions & 0 deletions mod_prometheus/COPYING

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions mod_prometheus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
mod_prometheus - Prometheus metrics
===================================

- Requires: ejabberd git commit xxx or higher
- Author: [Pouriya Jahanbakhsh](https://github.com/pouriya)

This module provides a web page with metrics suitable
for [Prometheus](https://prometheus.io/),
using the [prometheus](https://github.com/deadtrickster/prometheus.erl) erlang library.


Options
-------

The configurable options are:

- `mnesia: true | false`

Enable mnesia metrics or not.
Default: `false`

- `vm: [metric: true | false, ...]`

Enable some Erlang Virtual Machine metrics.
Available ones are:
`memory`, `system_info`, `statistics`, `distribution`, `microstate_accounting`.
For details please consult
[prometheus.erl collectors](https://github.com/deadtrickster/prometheus.erl?tab=readme-ov-file#erlang-vm--otp-collectors).
Default: `[]`

- `hooks: [Hook]`

List of hooks to investigate.
Default is an empty list: `[]`

Each Hook is:
- `hook: atom()`: the name of the hook
- `type: counter | histogram`
- `help: "Explanation"`
- `stanza_label: true | false`
- `host_label: true | false`
- `collect: all | [Callback]`
where each Callback is:
- `module: atom()`
- `function: atom()`
- `help: "Explanation"`
- `buckets: [integer()]`

Quick Start Guide
-----------------

### Install module

1. Start ejabberd

1. Download dependencies, compile and install this module:
```sh
ejabberdctl module_install mod_prometheus
```
1. Check ejabberd provides metrics in the URL: `http://localhost:5289/metrics/`

### Start Prometheus and Grafana

Start Prometheus and Grafana, for example using Podman or Docker:

```sh
cd example
podman-compose up
# or
# docker-compose up
```

### Test Prometheus

1. Open in web browser `http://localhost:9090/`

1. Enter example query: `erlang_mnesia_tablewise_size{table="muc_online_room"}`

### Setup Grafana

1. Open in web browser `http://localhost:3000/`

1. Login with username `admin` and password `admin`

1. Add data source: Prometheus
- Connection: `http://host.docker.internal:9090` (or `http://prometheus:9090`, or something similar)
- Click `Save & test`

1. Create your first dashboard
- Import dashboard
- Upload dashboard JSON file: you can try `ejabberd-dash.json`
45 changes: 45 additions & 0 deletions mod_prometheus/conf/mod_prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
listen:
-
port: 5289
ip: "::"
module: ejabberd_http
request_handlers:
/metrics: mod_prometheus

modules:
mod_prometheus:
mnesia: true
vm:
memory: true
system_info: true
statistics: false
distribution: false
microstate_accounting: false
hooks:
# Histogram for a hook:
- hook: user_send_packet
type: histogram
help: "Handling of sent messages duration in millisecond"
stanza_label: true
host_label: true
# Counter for a hook:
- hook: user_send_packet
type: counter
help: "Number of sent messages"
# Histograms only for some callbacks of a hook:
- hook: user_send_packet
type: histogram
host_label: true
collect:
- module: mod_carboncopy
function: user_send_packet
help: "Handling of carbon copied messages in millisecond"
- module: mod_mam
function: user_send_packet
help: "Handling of MAM messages in millisecond"
buckets:
- 10
- 100
- 750
- 1000
- 1500
17 changes: 17 additions & 0 deletions mod_prometheus/example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.7'

services:

prometheus:
image: docker.io/prom/prometheus
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml

grafana:
image: docker.io/grafana/grafana-enterprise
container_name: grafana
ports:
- "3000:3000"
Loading

0 comments on commit d820350

Please sign in to comment.