Skip to content

add infrahub-exporter #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
138 changes: 138 additions & 0 deletions docs/docs-exporter/readme.mdx
Original file line number Diff line number Diff line change
@@ -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
```
16 changes: 16 additions & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions docs/sidebars-exporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';

const sidebars: SidebarsConfig = {
exporterSidebar: [
'readme',
]
};

export default sidebars;