Commit fbc7797c authored by Alex Thomae's avatar Alex Thomae

Merge branch 'add-gelf-logging' into 'latest'

Adds GELF logging

See merge request docker/stellar-exporter!9
parents 0ad5479f fd61dece
Pipeline #71128720 canceled with stages
in 10 seconds
variables:
DOCKER_DRIVER: overlay2
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
PORT: 9308
stages:
- lint
......@@ -14,7 +15,7 @@ pylint:
stage: lint
script:
- curl -o .pylintrc https://tool.ix.ai/.pylintrc
- pip install prometheus_client pylint stellar-base mnemonic toml
- pip install prometheus_client pylint stellar-base mnemonic toml pygelf
- pylint --rcfile=.pylintrc src/*.py
build:
......@@ -23,7 +24,8 @@ build:
only:
- /^latest$/
- tags
- /(.*)-dev$/
script:
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker build -f Dockerfile -t ${IMAGE_TAG} .
- docker build -f Dockerfile -t ${IMAGE_TAG} --build-arg PORT="${PORT}" .
- docker push ${IMAGE_TAG}
FROM hub.ix.ai/docker/alpine:latest
LABEL ai.ix.maintainer="docker@ix.ai"
ENV LOGLEVEL=INFO
ARG PORT=9308
RUN apk add --no-cache python3-dev &&\
pip3 install stellar-base mnemonic toml
pip3 install --no-cache-dir stellar-base mnemonic toml
ENV LOGLEVEL=INFO PORT=${PORT}
COPY src/stellar-exporter.py /
EXPOSE 9308
EXPOSE ${PORT}
ENTRYPOINT ["python3", "/stellar-exporter.py"]
......@@ -12,4 +12,7 @@ docker run --rm -it -p 9308:9308 \
## Supported variables
* `ACCOUNTS` (no default) - comma separated list of the accounts monitor the balances
* `GELF_HOST` (no default) - if set, the exporter will also log to this [GELF](https://docs.graylog.org/en/3.0/pages/gelf.html) capable host on UDP
* `GELF_PORT` (defaults to `12201`) - the port to use for GELF logging
* `PORT` (defaults to `9308`) - the listen port for the exporter
* `LOGLEVEL` (defaults to `INFO`)
......@@ -4,6 +4,7 @@ import logging
import time
import os
import sys
import pygelf
from stellar_base.address import Address
from prometheus_client import start_http_server
from prometheus_client.core import REGISTRY, GaugeMetricFamily
......@@ -17,6 +18,22 @@ logging.basicConfig(
)
def configure_logging():
""" Configures the logging """
gelf_enabled: False
if os.environ.get('GELF_HOST'):
GELF = pygelf.GelfUdpHandler(
host=os.environ.get('GELF_HOST'),
port=int(os.environ.get('GELF_PORT', 12201)),
debug=True,
include_extra_fields=True
)
LOG.addHandler(GELF)
gelf_enabled = True
LOG.info('Initialized logging with GELF enabled: {}'.format(gelf_enabled))
class StellarCollector:
""" The StellarCollector class """
accounts = {}
......@@ -78,8 +95,10 @@ class StellarCollector:
if __name__ == '__main__':
LOG.info("Starting")
configure_logging()
PORT = int(os.environ.get('PORT', 9308))
LOG.info("Starting on port {}".format(PORT))
REGISTRY.register(StellarCollector())
start_http_server(9308)
start_http_server(PORT)
while True:
time.sleep(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment