Skip to content

Commit

Permalink
Fixing image
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmattox committed Jun 8, 2024
1 parent 32c71b3 commit e460341
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 9 deletions.
246 changes: 245 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,245 @@
# Prometheus-Tunnel
# Prometheus Tunnel

[![Go Report Card](https://goreportcard.com/badge/github.com/supporttools/prometheus-tunnel)](https://goreportcard.com/report/github.com/supporttools/prometheus-tunnel)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/supporttools/prometheus-tunnel/CI)](https://github.com/supporttools/prometheus-tunnel/actions)
[![Docker Pulls](https://img.shields.io/docker/pulls/supporttools/prometheus-tunnel)](https://hub.docker.com/r/supporttools/prometheus-tunnel)
[![Helm Chart Version](https://img.shields.io/badge/helm%20chart-v0.1.0-blue)](https://charts.support.tools)
[![GitHub Release](https://img.shields.io/github/v/release/supporttools/prometheus-tunnel)](https://github.com/supporttools/prometheus-tunnel/releases/latest)
[![License](https://img.shields.io/github/license/supporttools/prometheus-tunnel)](LICENSE)

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSupportTools%2FPrometheus-Tunnel.svg?type=large&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FSupportTools%2FPrometheus-Tunnel?ref=badge_large&issueType=license)

Prometheus Tunnel is a reverse proxy server that forwards requests to a remote Prometheus exporter. This project includes functionality for metrics collection and health checks, making it easy to monitor and manage your Prometheus exporter.

## Table of Contents

- [Features](#features)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Building from Source](#building-from-source)
- [Using Docker](#using-docker)
- [Using Helm](#using-helm)
- [Configuration](#configuration)
- [Prometheus Metrics](#prometheus-metrics)
- [Health Checks](#health-checks)
- [Prometheus Alert Rules](#prometheus-alert-rules)
- [Development](#development)
- [Running Tests](#running-tests)
- [Static Analysis Tools](#static-analysis-tools)
- [Contributing](#contributing)
- [License](#license)
- [Community and Support](#community-and-support)
- [Example Use Cases](#example-use-cases)

## [Features](#features)

- **Reverse Proxy**: Forwards incoming requests to a specified Prometheus exporter.
- **Metrics Collection**: Collects and exposes metrics for request count, duration, and response statuses.
- **Health Checks**: Provides endpoints for health and readiness checks.
- **Dockerized**: Easily deployable as a Docker container.
- **Helm Chart**: Package and deploy the application using Helm.

## [Quick Start](#quick-start)

Install the Prometheus Tunnel using Helm:

```bash
helm repo add supporttools https://charts.support.tools
helm upgrade --install prometheus-tunnel-server01 supporttools/prometheus-tunnel \
--namespace monitoring \
--create-namespace \
--set settings.serverIP=192.168.0.3 \
--set settings.serverPort=9182 \
--set settings.name=server01
```

Note, please replace the following:

- `prometheus-tunnel-server01` with the name of the Helm release.
- `server_name` with the name of the remote Prometheus exporter (e.g., `server01`).
- `192.168.0.3` with the IP address of external Prometheus exporter.
- `9100` with the port of external Prometheus exporter.

## Installation

### Prerequisites

- Go 1.22 or higher
- Docker
- Kubernetes (optional, for deployment)
- Helm (optional, for deployment)

### Building from Source

1. Clone the repository:

```bash
git clone https://github.com/supporttools/prometheus-tunnel.git
cd prometheus-tunnel
```

2. Build the binary:

```bash
go build -o prometheus-tunnel .
```

3. Run the application:

```bash
./prometheus-tunnel
```

### Using Docker

1. Build the Docker image:

```bash
docker build -t supporttools/prometheus-tunnel:latest .
```

2. Run the Docker container:

```bash
docker run -p 8080:8080 -e SERVER_IP=your-prometheus-exporter-ip -e SERVER_PORT=your-prometheus-exporter-port supporttools/prometheus-tunnel:latest
```

### Using Helm

1. Add the Helm repository:

```bash
helm add repo supporttools https://charts.support.tools
```

2. Deploy using Helm:

```bash
helm upgrade --install prometheus-tunnel supporttools/prometheus-tunnel \
--namespace monitoring \
--create-namespace \
--values values.yaml
```

## Configuration

### Environment Variables

- `SERVER_IP`: IP address of the Prometheus exporter.
- `SERVER_PORT`: Port of the Prometheus exporter.
- `METRICS_PORT`: Port for exposing Prometheus metrics (default: 9182).
- `DEBUG`: Enable debug logging (default: false).

## Prometheus Metrics

The following metrics are exposed:

- `proxy_total_requests`: Total number of requests received.
- `proxy_request_duration_seconds`: Histogram of request durations.
- `proxy_response_status_total`: Count of responses by status code.

## Health Checks

- `/healthz`: Health check endpoint.
- `/readyz`: Readiness check endpoint.
- `/version`: Version information endpoint.

## Prometheus Alert Rules

Here is a sample `PrometheusRule` for monitoring the Prometheus Tunnel:

```yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: prometheus-tunnel
labels:
prometheus: prometheus-tunnel
spec:
groups:
- name: prometheus-tunnel.rules
rules:
- alert: HighRequestRate
expr: rate(proxy_total_requests[5m]) > 100
for: 5m
labels:
severity: warning
annotations:
summary: "High Request Rate"
description: "The request rate has exceeded 100 requests per minute."
- alert: SlowRequestDuration
expr: histogram_quantile(0.99, rate(proxy_request_duration_seconds_bucket[5m])) > 1
for: 5m
labels:
severity: warning
annotations:
summary: "Slow Request Duration"
description: "99th percentile request duration is greater than 1 second."
- alert: HighErrorRate
expr: rate(proxy_response_status_total{status=~"5.."}[5m]) > 10
for: 5m
labels:
severity: critical
annotations:
summary: "High Error Rate"
description: "The rate of 5xx errors has exceeded 10 errors per minute."
- alert: HighLatency
expr: rate(proxy_request_duration_seconds_sum[5m]) / rate(proxy_request_duration_seconds_count[5m]) > 0.5
for: 5m
labels:
severity: critical
annotations:
summary: "High Request Latency"
description: "The average request latency is greater than 0.5 seconds."
- alert: HighRequestVolume
expr: sum(rate(proxy_total_requests[5m])) by (job) > 1000
for: 5m
labels:
severity: warning
annotations:
summary: "High Request Volume"
description: "The total request volume has exceeded 1000 requests per minute."
```

## Development

### Running Tests

To run the tests locally:

```bash
go test -v ./...
```

### Static Analysis Tools

To run static analysis tools:

```bash
golint ./...
staticcheck ./...
gosec ./...
```

## Contributing

Contributions are welcome! Please fork the repository and create a pull request.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

## Community and Support

For support and community interaction, you can join our Slack channel or open an issue on GitHub.

## Example Use Cases

- Prometheus servers managed by Argocd or FluxCD where editing the scape_configs to add external exporters is difficult.
- Air-gapped environments where the Prometheus exporter is not directly accessible from the cluster and a HTTP/Socks Proxy is required.
- Monitoring a Prometheus exporter that is behind a firewall and only accessible via a VPN.
9 changes: 9 additions & 0 deletions charts/prometheus-tunnel/questions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ questions:
description: "IP address of the server to which the tunnel will be established."
label: "Server IP Address"
type: string
group: "Server Settings"

- variable: settings.serverPort
default: 9182
description: "Port on the server to which the tunnel will be established."
label: "Server Port"
type: int
group: "Server Settings"

- variable: settings.rules
default: true
description: "Enable Prometheus alerting rules."
label: "Enable Prometheus Alerting Rules"
type: bool
group: "Alerting Settings"
13 changes: 12 additions & 1 deletion charts/prometheus-tunnel/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: "prometheus-tunnel"
name: "{{ .Release.Name }}"
labels:
app: "prometheus-tunnel"
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
spec:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "{{ .Values.service.port }}"
Expand All @@ -13,6 +18,9 @@ spec:
selector:
matchLabels:
app: "prometheus-tunnel"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
template:
metadata:
annotations:
Expand All @@ -21,6 +29,9 @@ spec:
prometheus.io/path: "/metrics"
labels:
app: "prometheus-tunnel"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
10 changes: 9 additions & 1 deletion charts/prometheus-tunnel/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ kind: PodMonitor
metadata:
labels:
app: prometheus-tunnel
name: prometheus-tunnel
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
name: "{{ .Release.Name }}"
spec:
podMetricsEndpoints:
- interval: 15s
port: metrics
selector:
matchLabels:
app: prometheus-tunnel
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
8 changes: 7 additions & 1 deletion charts/prometheus-tunnel/templates/prometheusrule.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{{ if .Values.settings.rules }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: prometheus-tunnel
name: "{{ .Release.Name }}"
labels:
prometheus: prometheus-tunnel
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
spec:
groups:
- name: prometheus-tunnel.rules
Expand Down Expand Up @@ -52,3 +57,4 @@ spec:
annotations:
summary: "High Request Volume"
description: "The total request volume has exceeded 1000 requests per minute."
{{ end }}
10 changes: 9 additions & 1 deletion charts/prometheus-tunnel/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: "prometheus-tunnel"
name: "{{ .Release.Name }}"
labels:
app: "prometheus-tunnel"
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "{{ .Values.service.port }}"
Expand All @@ -17,3 +21,7 @@ spec:
name: metrics
selector:
app: "prometheus-tunnel"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"

6 changes: 5 additions & 1 deletion charts/prometheus-tunnel/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: prometheus-tunnel
name: "{{ .Release.Name }}"
labels:
app: prometheus-tunnel
release: "{{ .Release.Name }}"
prometheus-tunnel/serverIP: "{{ .Values.settings.serverIP }}"
prometheus-tunnel/serverPort: "{{ .Values.settings.serverPort }}"
prometheus-tunnel/name: "{{ .Values.settings.name }}"
automountServiceAccountToken: true
Loading

0 comments on commit e460341

Please sign in to comment.