Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Latest commit

 

History

145 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prometheus Exporter for Azure

build Go Reference Go Report Card

Installation

The application uses DefaultAzureCredential to authenticate using the developer's az identity.

azure-exporter container images are being signed by Sigstore and may be verified:

cosign verify \
--key=./cosign.pub \
ghcr.io/dazwilkin/azure-exporter:07b175c3d70e8092f7d8bbc906d02163e46c020e

Go

Uses azidentity.NewDefaultAzureCredential, please az login to ensure credentials are available before running:

SUBSCRIPTION="..." # Azure Subscription ID

PORT="8080"

go run github.com/DazWilkin/azure-exporter \
--endpoint="0.0.0.0:${PORT}" \
--path="/metrics"

NOTE

  1. go run . works too
  2. --endpoint defaults to 0.0.0.0:9476 and --path defaults to /metrics so both arguments are redundant

Container

When running in a (Linux) container, the exporter is unable to obtain CLI (az login) credentials.

Please create a Service Principal and use its credentials:

First, you'll need a certificate and key:

NAME="azure-exporter" # Or...

openssl req \
-x509 \
-newkey rsa:4096 \
-keyout ${NAME}.key \
-out ${NAME}.crt \
-sha256 \
-days 365 \
-nodes \
-subj "/CN=${NAME}"

In a subsequent step, the Azure CLI will set AZURE_CLIENT_CERTIFICATE_PATH to point to a file that contains both the key and cert:

NAME="azure-exporter" # Or...

cat ${NAME}.key >> ${NAME}.key+crt
cat ${NAME}.crt >> ${NAME}.key+crt

Then:

SUBSCRIPTION="..."
GROUP="..."

NAME="azure-exporter" # Or...

az ad sp create-for-rbac \
--name=${NAME} \
--role="Reader" \
--scopes="/subscriptions/${SUBSCRIPTION}/resourceGroups/${GROUP}" \
--cert=@${PWD}/${NAME}.crt

Yields:

{
  "appId": "{AZURE_CLIENT_ID}",
  "displayName": "{NAME}",
  "password": null,
  "tenant": "{AZURE_TENANT_ID}"
}

Then, using the above-generated values for the environment variables shown below, you can run the container:

SUBSCRIPTION="..." # Azure Subscription ID

AZURE_CLIENT_ID="..." # Use values from Service Principal
AZURE_TENANT_ID="..."
AZURE_CLIENT_CERTIFICATE_PATH="${PWD}/azure-exporter.key+crt"

PORT="8080"

podman run \
--interactive --tty --rm \
--name=azure-exporter \
--env=SUBSCRIPTION=${SUBSCRIPTION} \
--env=AZURE_CLIENT_ID=${AZURE_CLIENT_ID} \
--env=AZURE_TENANT_ID=${AZURE_TENANT_ID} \
--env=AZURE_CLIENT_CERTIFICATE_PATH=/secrets/azure-exporter.key+crt \
--volume=${AZURE_CLIENT_CERTIFICATE_PATH}:/secrets/azure-exporter.key+crt \
--publish=${PORT}:${PORT}/tcp \
ghcr.io/dazwilkin/azure-exporter:07b175c3d70e8092f7d8bbc906d02163e46c020e \
--endpoint=0.0.0.0:${PORT} \
--path="/metrics"

Metrics

Name Type Description
azure_account_current_balance Gauge Azure current account balance
azure_container_apps_total Gauge Number of Azure Container Apps deployed
azure_exporter_build_info Counter Describes build info
azure_exporter_start_time Gauge The time (UNIX epoch) when the exporter started
azure_resource_groups_total Gauge Number of Azure Resource Groups

Prometheus

AlertManager

For example:

groups:
- name: azure_exporter
  rules:
  - alert: azure_container_apps_running
    expr: min_over_time(azure_container_apps_total{}[15m]) > 0
    for: 6h
    labels:
      severity: page
    annotations:
      summary: "Azure Container Apps ({{ $value }}) running (resource group: {{ $labels.resourcegroup }})"

Sigstore

azure-exporter container images are being signed by Sigstore and may be verified:

cosign verify \
--key=./cosign.pub \
ghcr.io/dazwilkin/azure-exporter:07b175c3d70e8092f7d8bbc906d02163e46c020e

NOTE cosign.pub may be downloaded here

To install cosign:

go install github.com/sigstore/cosign/cmd/cosign@latest

Similar Exporters



Buy Me A Coffee

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages