Compare commits
11 Commits
@@ -1,11 +1,9 @@
|
||||
next-version: 1.0.0
|
||||
mode: ContinuousDeployment
|
||||
assembly-versioning-scheme: MajorMinorPatch
|
||||
assembly-file-versioning-scheme: MajorMinorPatch
|
||||
|
||||
branches:
|
||||
master:
|
||||
regex: ^master$
|
||||
mode: ContinuousDelivery
|
||||
main:
|
||||
regex: ^main$
|
||||
increment: Patch
|
||||
tag: ''
|
||||
is-release-branch: true
|
||||
BIN
.gitea/readme/icon.png
Normal file
BIN
.gitea/readme/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
34
.gitea/workflows/analyze.yml
Normal file
34
.gitea/workflows/analyze.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Analyze code
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "dev"
|
||||
paths:
|
||||
- "src**"
|
||||
- "requirements.txt"
|
||||
pull_request:
|
||||
branches:
|
||||
- "dev"
|
||||
- "main"
|
||||
paths:
|
||||
- "src**"
|
||||
- "requirements.txt"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze code
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint --exit-zero $(git ls-files 'src/*.py')
|
||||
75
.gitea/workflows/analyze_and_publish.yml
Normal file
75
.gitea/workflows/analyze_and_publish.yml
Normal file
@@ -0,0 +1,75 @@
|
||||
name: Analyze code and publish script
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
paths:
|
||||
- "src**"
|
||||
- "requirements.txt"
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze code
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint --exit-zero $(git ls-files 'src/*.py')
|
||||
publish:
|
||||
name: Publish script
|
||||
needs: analyze
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 10.0.x
|
||||
- name: Setup GitVersion
|
||||
uses: gittools/actions/gitversion/setup@v4.2.0
|
||||
with:
|
||||
versionSpec: 6.4.x
|
||||
- name: Determine version
|
||||
uses: gittools/actions/gitversion/execute@v4.2.0
|
||||
id: gitversion
|
||||
with:
|
||||
configFilePath: ./.gitea/config/gitversion.yml
|
||||
- name: Create package root directory
|
||||
run: |
|
||||
mkdir package
|
||||
mkdir package/ipsec_exporter
|
||||
cp -r src/* package/ipsec_exporter/
|
||||
cp requirements.txt package/requirements.txt
|
||||
- name: Create .TAR.GZ archive
|
||||
uses: ksm2/archive-action@v1
|
||||
with:
|
||||
format: "tar.gz"
|
||||
name: ipsec_exporter_${{steps.gitversion.outputs.SemVer}}
|
||||
root-directory: "package"
|
||||
- name: Create .ZIP archive
|
||||
uses: ksm2/archive-action@v1
|
||||
with:
|
||||
format: "zip"
|
||||
name: ipsec_exporter_${{steps.gitversion.outputs.SemVer}}
|
||||
root-directory: "package"
|
||||
- name: Create Release
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
tag_name: ${{steps.gitversion.outputs.SemVer}}
|
||||
name: ${{steps.gitversion.outputs.SemVer}}
|
||||
files: |-
|
||||
ipsec_exporter_${{steps.gitversion.outputs.SemVer}}.tar.gz
|
||||
ipsec_exporter_${{steps.gitversion.outputs.SemVer}}.zip
|
||||
|
||||
26
.github/workflows/pull_request_dev.yml
vendored
26
.github/workflows/pull_request_dev.yml
vendored
@@ -1,26 +0,0 @@
|
||||
name: Chack code on dev pull request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "dev"
|
||||
paths:
|
||||
- "ipsec_exporter.py"
|
||||
- "src/*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint $(git ls-files '*.py')
|
||||
26
.github/workflows/pull_request_master.yml
vendored
26
.github/workflows/pull_request_master.yml
vendored
@@ -1,26 +0,0 @@
|
||||
name: Chack code on master pull request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
paths:
|
||||
- "ipsec_exporter.py"
|
||||
- "src/*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint $(git ls-files '*.py')
|
||||
26
.github/workflows/push_dev.yml
vendored
26
.github/workflows/push_dev.yml
vendored
@@ -1,26 +0,0 @@
|
||||
name: Chack code on dev push
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "dev"
|
||||
paths:
|
||||
- "ipsec_exporter.py"
|
||||
- "src/*"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint $(git ls-files '*.py')
|
||||
101
.github/workflows/push_master.yml
vendored
101
.github/workflows/push_master.yml
vendored
@@ -1,101 +0,0 @@
|
||||
name: Check code and publish on master push
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
paths:
|
||||
- "src/*.py"
|
||||
- "*.py"
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Code check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.10"
|
||||
- name: Setup GitVersion
|
||||
uses: gittools/actions/gitversion/setup@v0.9.7
|
||||
with:
|
||||
versionSpec: 5.x
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install prometheus_client
|
||||
pip install pylint
|
||||
- name: Analysing the code with pylint
|
||||
run: pylint --exit-zero $(git ls-files '*.py')
|
||||
- name: Determine Version
|
||||
uses: gittools/actions/gitversion/execute@v0.9.7
|
||||
id: gitversion
|
||||
with:
|
||||
useConfigFile: true
|
||||
configFilePath: ./.github/config/gitversion.yml
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: src
|
||||
path: |
|
||||
./
|
||||
!./.github/
|
||||
!./.gitignore
|
||||
!./.git/
|
||||
outputs:
|
||||
version: ${{ steps.gitversion.outputs.SemVer }}
|
||||
publish:
|
||||
name: Publish
|
||||
needs: check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download artifact
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: src
|
||||
path: ./data/
|
||||
- name: Create zip
|
||||
uses: ihiroky/archive-action@v1
|
||||
with:
|
||||
root_dir: ./data/
|
||||
file_path: ipsec_exporter_${{ needs.check.outputs.version }}.zip
|
||||
- name: Create tar.gz
|
||||
uses: ihiroky/archive-action@v1
|
||||
with:
|
||||
root_dir: ./data/
|
||||
file_path: ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ needs.check.outputs.version }}
|
||||
release_name: ${{ needs.check.outputs.version }}
|
||||
body_path: ./RELEASE.md
|
||||
draft: false
|
||||
prerelease: false
|
||||
- name: Upload zip archive
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./ipsec_exporter_${{ needs.check.outputs.version }}.zip
|
||||
asset_name: ipsec_exporter_${{ needs.check.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload tar.gz archive
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
|
||||
asset_name: ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
|
||||
asset_content_type: application/gzip
|
||||
|
||||
107
README.md
107
README.md
@@ -1,2 +1,105 @@
|
||||
# IPsecExporter
|
||||
Prometheus IPsec metrics exporter for Libreswan
|
||||
<p align="center"><img src=".gitea/readme/icon.png"/></p>
|
||||
|
||||
<h1 align="center">IPsec Exporter</h1>
|
||||
|
||||
<h3 align="center"><b>Metrics exporter for Libreswan IPsec VPN for use with Prometheus and Grafana</b></h3>
|
||||
|
||||
<p align="center">Metrics exporter written in Python for IPsec VPN server set up with <a href="https://github.com/hwdsl2/setup-ipsec-vpn">these scripts</a> (probably works with any Libreswan IPsec server).</p>
|
||||
|
||||
---
|
||||
|
||||
## Informations
|
||||
|
||||
> [!Warning]
|
||||
> App is no longer maintained. Last time, it was updated on April 2024. There is no guarantee that it works with newer versions of Libreswan. I leave the repository mainly as a sample of my work.
|
||||
|
||||
## Features
|
||||
|
||||
- Read metrics from Libreswan status commands and export them to the Prometheus server
|
||||
- Set read interval
|
||||
- Define custom metrics and metrics sources
|
||||
|
||||
## Installation
|
||||
|
||||
Download latest package version from <a href="https://repos.mateuszskoczek.com/MateuszSkoczek/IPsecExporter/releases">Releases</a> tab, unpack, install requirements and you good to go
|
||||
|
||||
**Requirements**
|
||||
|
||||
- Prometheus server set up
|
||||
- Python installed
|
||||
- PIP packages:
|
||||
- `argparse`
|
||||
- `prometheus_client`
|
||||
|
||||
You can also use `requirements.txt` file to install PIP dependencies
|
||||
|
||||
```
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
python ipsec_exporter [additional_options]
|
||||
```
|
||||
|
||||
**Additional options:**
|
||||
|
||||
- `--address <address>`, `-a <address>` - Prometheus server address (default: `0.0.0.0`)
|
||||
- `--port <port>`, `-p <port>` - Prometheus server port (default: `9446`)
|
||||
- `--interval <interval>`, `-i <interval>` - metrics read interval (in seconds, default: `1`)
|
||||
|
||||
**Run as service:**
|
||||
|
||||
You can just run command and leave terminal on, but you probably want to run exporter as a service.
|
||||
|
||||
1. Create new service file in `/etc/systemd/system/` and use text editor of your choice to edit it (as root user or with `sudo`): `vim /etc/systemd/system/ipsec_exporter.service`
|
||||
2. Paste the text below and adapt it to your setup
|
||||
|
||||
```
|
||||
[Unit]
|
||||
Description=Metrics exporter for Libreswan IPsec VPN for use with Prometheus
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
ExecStart=python /path/to/app/directory/ipsec_exporter -a 0.0.0.0 -p 9446 -i 10
|
||||
Type=simple
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
3. Save the file
|
||||
4. Reload services (as root user or with `sudo`): `systemctl daemon-reload`
|
||||
5. Enable service (as root user or with `sudo`): `systemctl enable ipsec_exporter`
|
||||
6. Start service (as root user or with `sudo`): `systemctl start ipsec_exporter`
|
||||
|
||||
## Custom metrics
|
||||
|
||||
You can define your own metrics and metrics sources in `main` method of `App` class in `ipsec_exporter/app.py` file.
|
||||
|
||||
**Regular command-based metrics source:**
|
||||
|
||||
1. Define metrics source: `source = CommandMetricsSource("command")`
|
||||
2. Define metrics with regular expression (regular expression have to contain wildcard "VALUE"): `source.add_metric("metric_name", r"current\.states\.(?P<type>\w+)=(?P<VALUE>\d+)")`
|
||||
3. Add metric source: `server.add_metrics_source(source)`
|
||||
|
||||
Exporter will extract all metrics from command output, basing on regular expressions.
|
||||
|
||||
**Fully custom metrics source:**
|
||||
|
||||
1. Create new metric class that inherits from a `CustomMetric` class
|
||||
2. You can define what you want in it, but it must meet several requirements (there is example in `ipsec_exporter/metric.py` - `IPsecTrafficCustomMetric`):
|
||||
- It has to have constructor (`__init__(self, name: str, description: str = "")`), inside of which you will define labels and call superconstructor (`super().__init__(name, labels, description)`)
|
||||
- It has to have update method (`update(self)` - this method will be called cyclically based on the interval), inside of which at the start you will clear `gauge` attribute (`self.gauge.clear()`) and set labels values (`self.gauge.labels(l1, l2).set(value)`)
|
||||
3. Define metrics source: `source = CustomMetricsSource()`
|
||||
4. Add metric to the source: `source.add_metric(ExampleCustomMetric("metric_name"))`
|
||||
5. Add metric source: `server.add_metrics_source(source)`
|
||||
|
||||
## Attribution
|
||||
|
||||
You can copy this repository and create your own version of the app freely. However, it would be nice if you included URL to this repository in the description to your repository or in README file.
|
||||
|
||||
**Other sources:**
|
||||
|
||||
- Icon by <a href="icons8.com">Icons8</a>
|
||||
@@ -1,3 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
- Initial version
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
argparse
|
||||
prometheus_client
|
||||
@@ -1,4 +1,4 @@
|
||||
from src.app import App
|
||||
from app import App
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
@@ -1,7 +1,7 @@
|
||||
from argparse import *
|
||||
from src.prometheus_metrics_server import *
|
||||
from src.metrics_source import *
|
||||
from src.metric import *
|
||||
from prometheus_metrics_server import *
|
||||
from metrics_source import *
|
||||
from metric import *
|
||||
|
||||
class App:
|
||||
args: Namespace
|
||||
|
||||
@@ -5,7 +5,6 @@ import os
|
||||
from prometheus_client import Gauge
|
||||
|
||||
|
||||
|
||||
class Metric:
|
||||
gauge: Gauge
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from src.metric import Metric, CommandMetric, CustomMetric
|
||||
from metric import Metric, CommandMetric, CustomMetric
|
||||
import os
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
import prometheus_client
|
||||
from src.metrics_source import MetricsSource
|
||||
from metrics_source import MetricsSource
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user