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
# Run systemd-detect-virt to get the virtualization type
virt_type=$(systemd-detect-virt)
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <cloud_name> <customer>"
exit 1
fi
cloud_name=$1
customer=$2
# Convert the output into a Prometheus metric
if [[ $? -eq 0 ]]; then
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"
else
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=\"metal\"} 1"
fi
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