Skip to content

Filament Usage History

Donkie edited this page Nov 25, 2024 · 4 revisions

Spoolman has built-in support for Prometheus metrics. This lets you store a detailed history of your filament usage, which you can then view using tools like Grafana.

image

This is a very simplified instruction how to setup a sample instance of Prometheus and Grafana using Docker. If you want to use this long-term, please look into resources how to host these services properly.

It doesn't matter if you've installed Spoolman using the Docker or Standalone method to follow this guide.


Step 1: Prepare Docker Compose File

Create a new directory to host your Prometheus and Grafana configuration and data.

Create two new directories in this directory, name them prometheus-data and grafana-data. Give them read/write access. sudo chmod 777 prometheus-data grafana-data

Create a docker-compose.yml file with the following content:

version: '3.8'

services:
  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus-data:/prometheus
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
    ports:
      - "3000:3000"
    volumes:
      - ./grafana-data:/var/lib/grafana

Step 2: Configure Prometheus

Create a prometheus.yml file in the same directory as the docker-compose.yml with the following content. The localhost:7912 should point to your Spoolman instance, and might be changed depending on your install.

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'spoolman'
    static_configs:
      - targets: ['localhost:7912']

Step 3: Start Services

Run the following command to start Prometheus and Grafana:

docker-compose up -d

Prometheus will be accessible at http://localhost:9090 and Grafana at http://localhost:3000.


Configure Spoolman to output metrics

Set the Spoolman env variable SPOOLMAN_METRICS_ENABLED=true. This can be done in the .env file if you use the Standalone install, or in the docker-compose.yml if you use the Docker install.

Restart Spoolman after the change.


Create a Simple Grafana Panel to Show Data from Prometheus

  1. Access Grafana
    Navigate to http://localhost:3000 and log in with the default credentials (admin/admin).

  2. Add Prometheus as a Data Source

    • Go to Connections > Add new connection.
    • Find Prometheus in the list and click it.
    • Click Add new data source.
    • Set the server URL to http://prometheus:9090 and click Save & test. It should give a green box saying it was successful.
  3. Create a New Dashboard

    • Go to the main menu and select Dashboards > New Dashboard.
    • Click Add visualization.
  4. Configure the Panel

    • In the Query editor, select the Prometheus data source.
    • Towards the bottom of the page, click the Select metric dropdown, then choose spoolman_spool_weight_used.
    • Click the blue Run queries button, some data should now show up in the graph.
    • Adjust visualization settings as needed (e.g., graph, gauge).
  5. Save the Dashboard

    • Click Save dashboard, provide a name, and click Save.

Now, your Grafana dashboard will display the desired metrics from Prometheus!