From d883e6b24e5de9172c739ff7e2de307cb685fa91 Mon Sep 17 00:00:00 2001 From: Pete Crocker Date: Sat, 19 Jul 2025 10:19:52 +0100 Subject: [PATCH] add infrahub-exporter --- .DS_Store | Bin 6148 -> 6148 bytes docs/docs-exporter/readme.mdx | 138 ++++++++++++++++++++++++++++++++++ docs/docusaurus.config.ts | 16 ++++ docs/sidebars-exporter.ts | 9 +++ 4 files changed, 163 insertions(+) create mode 100644 docs/docs-exporter/readme.mdx create mode 100644 docs/sidebars-exporter.ts diff --git a/.DS_Store b/.DS_Store index e89a6bbac1989fa8cd235b90585f1cedfa1e1628..09b305d6bb51de59a59901d9957fa31cb3299cc5 100644 GIT binary patch delta 84 zcmZoMXfc=|#>B!ku~2NHo+2a1#(>?7i#IScF>*}iVd|N@g{gtV)X+#r!N}5hvJJES n=6B)qu~2NHo+2ar#(>?7jO>$nSb8>Ru+C@N*l>YqGdl-A2T;joL5}at Vlles)IT(O|k%56_bA-qmW&mOI5K;gD diff --git a/docs/docs-exporter/readme.mdx b/docs/docs-exporter/readme.mdx new file mode 100644 index 0000000..e6d49bd --- /dev/null +++ b/docs/docs-exporter/readme.mdx @@ -0,0 +1,138 @@ +--- +title: Infrahub Exporter +--- + +Infrahub Exporter is a service that exports metrics and service discovery information from Infrahub to monitoring systems like Prometheus and OpenTelemetry. + +## Overview + +Infrahub Exporter acts as a bridge between your Infrahub instance and monitoring tools, providing: + +1. **Metrics Export**: Collects and exposes metrics from Infrahub nodes for monitoring +2. **Service Discovery**: Provides dynamic service discovery for Prometheus based on Infrahub data +3. **OpenTelemetry Integration**: Supports sending metrics to OpenTelemetry collectors + +## Features + +- **Prometheus Integration**: Exposes metrics in Prometheus format +- **OpenTelemetry Support**: Sends metrics to OTLP-compatible collectors +- **Dynamic Service Discovery**: Generates Prometheus service discovery files based on GraphQL queries +- **Flexible Configuration**: Configurable via YAML with environment variable overrides +- **Caching**: Efficient data retrieval with caching to reduce load on Infrahub +- **Resilience**: Automatic retries and error handling for API calls + +## Installation + +### Using Poetry + +```bash +# Clone the repository +git clone https://github.com/opsmill/infrahub-exporter.git +cd infrahub-exporter + +# Install dependencies +poetry install + +# Run the exporter +poetry run python -m infrahub_exporter --config path/to/config.yml +``` + +### Using Docker + +```bash +docker run -v $(pwd)/config.yml:/app/config.yml -p 8001:8001 opsmill/infrahub-exporter:latest +``` + +## Configuration + +Create a `config.yml` file with the following structure: + +```yaml +# Infrahub connection settings +infrahub: + address: "http://localhost:8000" # Infrahub server address + token: "your-api-token" # Infrahub SDK API key + branch: main # Which branch to fetch + +# Poll interval in seconds +poll_interval_seconds: 30 + +# HTTP server configuration +listen_address: "0.0.0.0" +listen_port: 8001 + +# Log level +log_level: "INFO" + +# Exporter configuration +exporters: + # Prometheus exporter + prometheus: + enabled: true + + # OTLP exporter + otlp: + enabled: false + endpoint: "http://otel-collector:4317" + timeout_seconds: 10 + +# Service Discovery for Prometheus +service_discovery: + enabled: true + queries: + - name: "devices" + file_path: "./queries/devices.gql" + endpoint_path: "devices" + refresh_interval_seconds: 60 + target_field: "primary_address.node.address.ip" + label_mappings: + "device_name": "name.value" + "location": "site.node.name.value" + "role": "role.value" + "platform": "platform.node.name.value" + +# Data sources for metrics +metrics: + kind: + - kind: InfraDevice + include: + - name + - description + - platform + - role + - status + filters: + - site__name__value: "dc1" + - role__value: "edge" +``` + +## Usage + +### Prometheus Integration + +Add the following to your Prometheus configuration: + +```yaml +scrape_configs: + - job_name: 'infrahub' + scrape_interval: 30s + static_configs: + - targets: ['infrahub-exporter:8001'] + + - job_name: 'infrahub-sd' + http_sd_configs: + - url: http://infrahub-exporter:8001/sd/devices + refresh_interval: 60s +``` + +### OpenTelemetry Integration + +Configure the OTLP exporter in your config.yml: + +```yaml +exporters: + otlp: + enabled: true + endpoint: "http://otel-collector:4317" + timeout_seconds: 10 +``` diff --git a/docs/docusaurus.config.ts b/docs/docusaurus.config.ts index c6b84f7..5c61235 100644 --- a/docs/docusaurus.config.ts +++ b/docs/docusaurus.config.ts @@ -200,6 +200,16 @@ const config: Config = { sidebarPath: './sidebars-service-catalog.ts', }, ], + [ + '@docusaurus/plugin-content-docs', + { + id: 'docs-exporter', + path: 'docs-exporter', + routeBasePath: 'exporter', + sidebarCollapsed: false, + sidebarPath: './sidebars-exporter.ts', + }, + ], [ '@docusaurus/plugin-google-tag-manager', { @@ -284,6 +294,12 @@ const config: Config = { label: "Ansible", docsPluginId: "docs-ansible", }, + { + type: "docSidebar", + sidebarId: "exporterSidebar", + label: "Infrahub Exporter", + docsPluginId: "docs-exporter", + }, { type: "docSidebar", sidebarId: "syncSidebar", diff --git a/docs/sidebars-exporter.ts b/docs/sidebars-exporter.ts new file mode 100644 index 0000000..37730b3 --- /dev/null +++ b/docs/sidebars-exporter.ts @@ -0,0 +1,9 @@ +import type {SidebarsConfig} from '@docusaurus/plugin-content-docs'; + +const sidebars: SidebarsConfig = { + exporterSidebar: [ + 'readme', + ] +}; + +export default sidebars;