18 Commits
dev ... 1.0.2

6 changed files with 54 additions and 36 deletions

View File

@@ -1,10 +1,11 @@
name: Chack code and publish on master push name: Check code and publish on master push
on: on:
push: push:
branches: branches:
- "master" - "master"
paths: paths:
- "src/*.py"
- "*.py" - "*.py"
jobs: jobs:
@@ -14,53 +15,69 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Set up Python with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v3 uses: actions/setup-python@v3
with: with:
python-version: "3.10" 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 --exit-zero $(git ls-files '*.py')
publish:
needs: check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup GitVersion - name: Setup GitVersion
uses: gittools/actions/gitversion/setup@v0.9.7 uses: gittools/actions/gitversion/setup@v0.9.7
with: with:
versionSpec: 5.x 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 - name: Determine Version
uses: gittools/actions/gitversion/execute@v0.9.7 uses: gittools/actions/gitversion/execute@v0.9.7
id: gitversion id: gitversion
with: with:
useConfigFile: true useConfigFile: true
configFilePath: ./.github/config/gitversion.yml 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 - name: Create zip
uses: ihiroky/archive-action@v1 uses: ihiroky/archive-action@v1
with: with:
root_dir: ./ root_dir: ./data/
file_path: ipsec_exporter_${{steps.gitversion.outputs.version}}.zip file_path: ipsec_exporter_${{ needs.check.outputs.version }}.zip
- name: Create tar.gz - name: Create tar.gz
uses: ihiroky/archive-action@v1 uses: ihiroky/archive-action@v1
with: with:
root_dir: ./ root_dir: ./data/
file_path: ipsec_exporter_${{steps.gitversion.outputs.version}}.tar.gz file_path: ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
- name: Create Release - name: Create Release
id: create_release id: create_release
uses: actions/create-release@v1 uses: actions/create-release@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{steps.gitversion.outputs.version}} tag_name: ${{ needs.check.outputs.version }}
release_name: ${{steps.gitversion.outputs.version}} release_name: ${{ needs.check.outputs.version }}
body_path: ./RELEASE.md body_path: ./data/RELEASE.md
draft: false draft: false
prerelease: false prerelease: false
- name: Upload zip archive - name: Upload zip archive
@@ -69,8 +86,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ipsec_exporter_${{steps.gitversion.outputs.version}}.zip asset_path: ./ipsec_exporter_${{ needs.check.outputs.version }}.zip
asset_name: ipsec_exporter_${{steps.gitversion.outputs.version}}.zip asset_name: ipsec_exporter_${{ needs.check.outputs.version }}.zip
asset_content_type: application/zip asset_content_type: application/zip
- name: Upload tar.gz archive - name: Upload tar.gz archive
uses: actions/upload-release-asset@v1 uses: actions/upload-release-asset@v1
@@ -78,7 +95,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./ipsec_exporter_${{steps.gitversion.outputs.version}}.tar.gz asset_path: ./ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
asset_name: ipsec_exporter_${{steps.gitversion.outputs.version}}.tar.gz asset_name: ipsec_exporter_${{ needs.check.outputs.version }}.tar.gz
asset_content_type: application/gzip asset_content_type: application/gzip

View File

@@ -2,4 +2,4 @@ from src.app import App
if __name__ == "__main__": if __name__ == "__main__":
app = App() app = App()
app.main() app.main()

View File

@@ -1,6 +1,7 @@
from argparse import * from argparse import *
from src.prometheus_metrics_server import * from src.prometheus_metrics_server import *
from src.metrics_source import * from src.metrics_source import *
from src.metric import *
class App: class App:
args: Namespace args: Namespace
@@ -39,4 +40,4 @@ class App:
server.add_metrics_source(custom_metrics_source) server.add_metrics_source(custom_metrics_source)
server.run() server.run()

View File

@@ -1,8 +1,8 @@
from abc import abstractmethod from abc import abstractmethod
from prometheus_client import *
from re import Pattern from re import Pattern
import re import re
import os import os
from prometheus_client import Gauge
@@ -71,4 +71,4 @@ class IPsecTrafficCustomMetric(CustomMetric):
out_value = result.groupdict()["OUT_VALUE"] out_value = result.groupdict()["OUT_VALUE"]
self.gauge.labels(lease, connection, "in").set(int(in_value)) self.gauge.labels(lease, connection, "in").set(int(in_value))
self.gauge.labels(lease, connection, "out").set(int(out_value)) self.gauge.labels(lease, connection, "out").set(int(out_value))

View File

@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from src.metric import * from src.metric import Metric, CommandMetric, CustomMetric
import os import os
@@ -40,4 +40,4 @@ class CustomMetricsSource(MetricsSource):
def update(self): def update(self):
for metric in self._metrics: for metric in self._metrics:
metric.update() metric.update()

View File

@@ -1,6 +1,6 @@
import prometheus_client
import time import time
from src.metrics_source import * import prometheus_client
from src.metrics_source import MetricsSource
@@ -29,4 +29,4 @@ class PrometheusMetricsServer:
while True: while True:
for source in self._metrics_sources: for source in self._metrics_sources:
source.update() source.update()
time.sleep(self.interval) time.sleep(self.interval)