---
title: Charmhub | Deploy Prometheus Juju Exporter using Charmhub - The Open Operator
  Collection
description: Deploy the latest version of Prometheus Juju Exporter on any cloud.
url: https://charmhub.io/prometheus-juju-exporter/docs/h-migration
---

# Prometheus Juju Exporter

[Canonical BootStack Charmers](https://charmhub.io/publisher/bootstack-charmers "View all packages from Canonical BootStack Charmers")

* [Canonical BootStack Charmers](https://charmhub.io/publisher/bootstack-charmers "View all packages from Canonical BootStack Charmers")

Platform:

22.04

20.04

18.04

stable 23

```
juju deploy prometheus-juju-exporter
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

---

#### Relevant links

* [Homepage](https://github.com/canonical/charm-prometheus-juju-exporter)

---

Share your thoughts on this charm with the community on discourse.

[Join the discussion](https://discourse.charmhub.io/)

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

## [Prerequisites](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-prerequisites)

* A [deployed](https://charmhub.io/topics/canonical-observability-stack/tutorials/install-microk8s) cos-lite bundle in a Kubernetes environment
* Juju controller >= 3.0

Machines running Ubuntu >= 22.04. It might also be available for [focal](https://github.com/canonical/script-exporter-operator/issues/20) in the future.

## [Explanation](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-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](https://www.freedesktop.org/software/systemd/man/latest/systemd-detect-virt.html) in a custom script

## [Step-to-step](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-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](https://github.com/canonical/grafana-agent-operator/issues/11)
* Relate grafana-agent with script-exporter
* Relate the principal with script-exporter

## [Configuration files](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-configuration-files)

### [Script (systemd\_virt.sh)](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-script-systemd_virtsh)

```
#!/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)](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-prometheus-configuration-prometheusyaml)

```
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)](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-generic-configuration-script-exporteryaml)

```
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](https://charmhub.io/prometheus-juju-exporter/docs/h-migration#p-36781-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

---
