Skip to content
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
26 changes: 8 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
services:

xray-config:
build:
context: ./xray-config
dockerfile: Dockerfile
image: compassvpn/xray-config:1
restart: always
env_file:
- env_file
Expand All @@ -12,16 +10,16 @@ services:
volumes:
- "/etc/machine-id:/host/etc/machine-id"
- "acme:/root/.acme.sh/"
ports:
- "5000:5000"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "1"

xray:
build:
context: ./xray
dockerfile: Dockerfile
image: compassvpn/xray:1
volumes:
- "/var/log:/var/log"
cap_add:
Expand All @@ -45,9 +43,7 @@ services:
- "443:443/udp"

nginx:
build:
context: ./nginx
dockerfile: Dockerfile
image: compassvpn/nginx:1
volumes:
- "acme:/root/.acme.sh/"
- "/var/log:/var/log"
Expand All @@ -73,9 +69,7 @@ services:
max-file: "1"

xray-exporter:
build:
context: ./xray-exporter
dockerfile: Dockerfile
image: compassvpn/xray-exporter:1
restart: always
depends_on:
- xray
Expand All @@ -92,9 +86,7 @@ services:
max-file: "1"

metric-forwarder:
build:
context: ./metric-forwarder
dockerfile: Dockerfile
image: compassvpn/metric-forwarder:3
restart: always
env_file:
- env_file
Expand Down Expand Up @@ -138,9 +130,7 @@ services:
max-file: "1"

fail2ban:
build:
context: ./fail2ban
dockerfile: Dockerfile
image: compassvpn/fail2ban:1
restart: always
network_mode: host
environment:
Expand Down
44 changes: 31 additions & 13 deletions metric-forwarder/common.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
import os
import json
import yaml
from utils import get_public_ip

instance_location_info = get_public_ip(extra=True)

instance_ip = instance_location_info['ip']

DONOR = os.environ['DONOR']
METRIC_PUSH_METHOD = os.environ.get('METRIC_PUSH_METHOD', 'pushgateway')

remote_write_url = os.environ['GRAFANA_AGENT_REMOTE_WRITE_URL']
if not remote_write_url.endswith("/push"):
remote_write_url += "/push"
DONOR = os.environ['DONOR']

# Convert to YAML and save to file
def generate_config():
if METRIC_PUSH_METHOD == "grafana_agent":
remote_write_url = os.environ['GRAFANA_AGENT_REMOTE_WRITE_URL']
if not remote_write_url.endswith("/push"):
remote_write_url += "/push"
remote_write_item = {
"url": remote_write_url,
"basic_auth": {
"username": os.environ['GRAFANA_AGENT_REMOTE_WRITE_USER'],
"password": os.environ['GRAFANA_AGENT_REMOTE_WRITE_PASSWORD']
}
}
else:
# pushgateway
remote_write_item = {
"url": os.environ['PUSHGATEWAY_URL']
}
if os.environ.get('PUSHGATEWAY_AUTH_TOKEN', "") != "":
remote_write_item["authorization"] = {
"type": "Bearer",
"credentials": os.environ["PUSHGATEWAY_AUTH_TOKEN"]
}
else:
remote_write_item["basic_auth"] = {
"username": os.environ['PUSHGATEWAY_AUTH_USER'],
"password": os.environ['PUSHGATEWAY_AUTH_PASSWORD']
}

config = {
"server": {
"log_level": "warn"
},
"metrics": {
"wal_directory": "/tmp/grafana-agent-wal",
"global": {
"scrape_interval": "5m"
"scrape_interval": os.environ['METRIC_INTERVAL']
},
"configs": [
{
"name": "default",
"remote_write": [
{
"url": remote_write_url,
"basic_auth": {
"username": os.environ['GRAFANA_AGENT_REMOTE_WRITE_USER'],
"password": os.environ['GRAFANA_AGENT_REMOTE_WRITE_PASSWORD']
}
}
remote_write_item
],
"scrape_configs": [
{
Expand Down
17 changes: 5 additions & 12 deletions metric-forwarder/run.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import os
import platform
import threading
from time import sleep
import requests
from prometheus_client.parser import text_string_to_metric_families
from requests.auth import HTTPBasicAuth
import unicodedata


# initial wait
print("initial 30 seconds wait...", flush=True)
# sleep(30)

METRIC_PUSH_METHOD = os.environ.get('METRIC_PUSH_METHOD', 'pushgateway')
METRIC_PUSH_METHOD = os.environ.get('METRIC_PUSH_METHOD')

if METRIC_PUSH_METHOD == "pushgateway":
from pushgateway import run_jobs
run_jobs()

else:
elif METRIC_PUSH_METHOD == "grafana_agent":
# grafana_agent method
from grafana_agent import start
start()

else:
sleep(3)

while True:
print("entering endless loop.", flush=True)
sleep(1000)