The Charm Store will undergo scheduled database maintenance on July 5, 2026 22:00 to July 6, 02:00 UTC. During this time, you may be unable to access charm and bundle metadata or publish updates. No user action is required and services will automatically resume once maintenance is complete.

Prometheus Juju Exporter

Platform:

Ubuntu
22.04 20.04 18.04
Channel Revision Published Runs on
latest/stable 23 17 Dec 2024
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04
latest/candidate 23 17 Dec 2024
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04
latest/edge 38 23 Apr 2025
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04
latest/edge 37 23 Apr 2025
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04
latest/edge 24 20 Feb 2025
Ubuntu 22.04 Ubuntu 20.04 Ubuntu 18.04
juju deploy prometheus-juju-exporter

How to migrate from p-j-e to script exporter

Prerequisites

  • A deployed cos-lite bundle in a Kubernetes environment
  • Juju controller >= 3.0

Machines running Ubuntu >= 22.04. It might also be available for focal in the future.

Explanation

The charm script-exporter is a subordinate charm that allows the execution of a custom script that generates a custom prometheus metric.

The metrics that p-j-e generates are to detect the type of juju machines e.g: lxd, kvm, qemu or bare metal. The same can be done by using systemd-detect-virt in a custom script

Step-to-step

  • Deploy charm grafana-agent
  • Deploy charm script-exporter-operator
  • Relate any principal application with grafana-agent. Note that grafana-agent should be related with just one principal on the same machine due technical limitations
  • Relate grafana-agent with script-exporter
  • Relate the principal with script-exporter

Configuration files

Script (systemd_virt.sh)

#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "Usage: $0 <cloud_name> <customer>"
    exit 1
fi

cloud_name=$1
customer=$2


# Run systemd-detect-virt to get the virtualization type
virt_type=$(systemd-detect-virt 2>/dev/null)
ret=$?

if [[ $ret -ne 0 || "$virt_type" == "none" ]]; then
    virt_type="metal"
fi

# Convert the output into a Prometheus metric

echo "# HELP system_virtualization_type Virtualization type detected by systemd-detect-virt"
echo "# TYPE system_virtualization_type gauge"
echo "system_virtualization_type{cloud_name=\"$cloud_name\",customer=\"$customer\",hostname=\"$(hostname)\",type=\"$virt_type\"} 1"

exit 0

Prometheus configuration (prometheus.yaml)

scrape_configs:
  - job_name: 'script_systemd_virt' # job name, arbitrary
    metrics_path: /probe
    params:
      script: [systemd_virt] # the name of the script as specified in the *config_file*
      prefix: [script] # a custom prefix for this metric
    static_configs:
      - targets:
        - 127.0.0.1

Generic configuration (script-exporter.yaml)

scripts:
  - name: systemd_virt # Name of the script, arbitrary
    command: /etc/script-exporter-script # any available shell command, or `/etc/script-exporter-script` for the custom one
    args:
      - "Foo" # cloud_name
      - "Bar" # customer

Set the charm configurations

juju config script-exporter script_file=@systemd_virt.sh
juju config script-exporter config_file=@script-exporter.yaml
juju config script-exporter prometheus_config_file=@prometheus.yaml

After that you should be able to see the metric on prometheus with the same fields that used to have on p-j-e


Help improve this document in the forum (guidelines). Last updated 1 year, 2 months ago.