Skip to content

hpdobrica/edrums-prometheus-exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-Drums Prometheus Exporter

A Prometheus exporter that captures MIDI events from electronic drum kits and exports hit velocity metrics to Prometheus Pushgateway for monitoring and analysis.

Features

  • Real-time MIDI event capture from electronic drum kits
  • Prometheus histogram metrics for hit velocities
  • Configurable drum element mapping (snare, hi-hat, toms, cymbals, etc.)
  • Support for drum variations (rim shots, edge hits, bell hits, etc.)
  • Interactive configuration generator
  • Periodic metric push to Prometheus Pushgateway

Prerequisites

  • Go 1.19 or higher
  • A MIDI-compatible electronic drum kit
  • Prometheus Pushgateway instance
  • MIDI driver support (rtmidi)

Platform-Specific Requirements

macOS:

brew install pkg-config

Linux:

# Debian/Ubuntu
sudo apt-get install libasound2-dev

# Fedora/RHEL
sudo dnf install alsa-lib-devel

Installation

go install github.com/hpdobrica/edrums-exporter@latest

Or build from source:

git clone https://github.com/hpdobrica/edrums-prometheus-exporter
cd edrums-prometheus-exporter
go build -o edrums-exporter ./cmd

Configuration

Interactive Setup

Run the configuration generator to create your config.yaml:

./edrums-exporter configure

The configuration wizard will guide you through:

  1. MIDI Port Selection: Choose from available MIDI input ports
  2. Prometheus Settings: Configure Pushgateway URL and push interval
  3. Drum Mapping: Hit each drum element to map MIDI notes to drum components

Configuration File

The generated config.yaml has the following structure:

prometheus:
  push_gateway_url: http://localhost:9091
  push_interval_sec: 5

midi_port: "Your MIDI Device Name"

drum_map:
  C2:
    - Bass
    - Regular
  D2:
    - Snare
    - Regular
  D#2:
    - Snare
    - Rim Shot
  # ... additional mappings

Drum Mapping

Each MIDI note maps to a drum element and variation:

Supported Elements:

  • Bass
  • Snare
  • Hi-hat
  • Tom 1/2/3
  • Ride
  • Crash 1/2

Supported Variations:

  • Regular
  • Rim Click
  • Rim Shot
  • Edge
  • Bell
  • Top
  • Foot (hi-hat)

Usage

Start the Exporter

./edrums-exporter

The exporter will:

  1. Connect to the configured MIDI port
  2. Start listening for MIDI note events
  3. Push metrics to Prometheus Pushgateway at the configured interval

Reconfigure

To update your configuration:

./edrums-exporter configure

The wizard will load existing settings as defaults, allowing you to keep or change each value.

Metrics

edrum_hit_velocity

A histogram metric tracking the distribution of hit velocities (0-127) for each drum element.

Labels:

  • note: MIDI note name (e.g., "C2", "D2")
  • element: Drum component (e.g., "Snare", "Hi-hat")
  • variation: Hit type (e.g., "Regular", "Rim Shot")
  • channel: MIDI channel number

Example:

edrum_hit_velocity{note="D2",element="Snare",variation="Regular",channel="0"} 85
edrum_hit_velocity{note="D#2",element="Snare",variation="Rim Shot",channel="0"} 102

Prometheus Setup

Run Pushgateway

docker run -d -p 9091:9091 prom/pushgateway

Configure Prometheus

Add to your prometheus.yml:

scrape_configs:
  - job_name: 'pushgateway'
    honor_labels: true
    static_configs:
      - targets: ['localhost:9091']

Example Queries

In adition to below queries, you can check out the grafana dashboard stored in grafana-dashboard.yaml.

Average Hit Velocity by Drum Element

avg by (element) (edrum_hit_velocity)

Hit Count by Drum Variation

sum by (element, variation) (edrum_hit_velocity_count)

Velocity Distribution Percentiles

histogram_quantile(0.95, sum by (le, element) (edrum_hit_velocity_bucket))

Troubleshooting

MIDI Port Not Found

Check available MIDI devices:

# macOS
ls /dev/cu.*

# Linux
aconnect -l

Ensure your drum kit is powered on and connected before running the exporter.

Pushgateway Connection Failed

Verify Pushgateway is running:

curl http://localhost:9091/metrics

Check the push_gateway_url in your config.yaml.

Note Not Detected

If a drum hit isn't detected during configuration:

  • Check that the drum module is in the correct MIDI mode
  • Verify MIDI channel settings match your configuration

Development

Project Structure

.
├── cmd/
│   └── main.go           # Main application entry point
├── pkg/
│   ├── config/
│   │   └── main.go       # Configuration loading
│   └── configmaker/
│       ├── generator.go  # Interactive config generator
│       └── portfinder.go # MIDI port detection
└── config.yaml           # Generated configuration file

Build

go build -o edrums-exporter ./cmd

Dependencies

  • github.com/prometheus/client_golang - Prometheus client library
  • gitlab.com/gomidi/midi/v2 - MIDI handling
  • github.com/cqroot/prompt - Interactive CLI prompts
  • gopkg.in/yaml.v3 - YAML configuration

License

MIT

About

Prometheus exporter for electronic drums

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages