Commit 73ec549f authored by Alex Thomae's avatar Alex Thomae

Merge branch 'fix-pipeline' into 'master'

Fixes the build pipeline. Also, updates the versions in requirements.txt

See merge request !13
parents 3d98064e 3d5ca5bc
Pipeline #107149437 passed with stages
in 25 minutes and 51 seconds
...@@ -7,6 +7,8 @@ include: ...@@ -7,6 +7,8 @@ include:
- remote: https://gitlab.com/ix.ai/ci-templates/raw/master/python-project.yml - remote: https://gitlab.com/ix.ai/ci-templates/raw/master/python-project.yml
test: test:
extends:
- .tags-template
stage: test stage: test
image: python:latest image: python:latest
variables: variables:
......
...@@ -6,12 +6,10 @@ WORKDIR /app ...@@ -6,12 +6,10 @@ WORKDIR /app
COPY src/ /app COPY src/ /app
RUN apk --no-cache upgrade && \ RUN apk --no-cache upgrade && \
apk add --no-cache python3-dev gcc musl-dev libffi-dev make && \ apk add --no-cache python3 python3-dev gcc musl-dev libffi-dev make && \
pip3 install --no-cache-dir -r requirements.txt && \ pip3 install --no-cache-dir -r requirements.txt && \
apk del --no-cache --purge gcc musl-dev libffi-dev make apk del --no-cache --purge python3-dev gcc musl-dev libffi-dev make
COPY src/stellar-exporter.py / EXPOSE 9188
EXPOSE 9308
ENTRYPOINT ["python3", "/app/stellar-exporter.py"] ENTRYPOINT ["python3", "/app/stellar-exporter.py"]
...@@ -12,19 +12,21 @@ A [Prometheus](https://prometheus.io) exporter for [Stellar](https://www.stellar ...@@ -12,19 +12,21 @@ A [Prometheus](https://prometheus.io) exporter for [Stellar](https://www.stellar
docker run --rm -it -p 9308:9308 \ docker run --rm -it -p 9308:9308 \
-e LOGLEVEL=DEBUG \ -e LOGLEVEL=DEBUG \
-e GELF_HOST=graylog \ -e GELF_HOST=graylog \
-e ACCOUNTS='AAAAA,BBBBB' \
--name stellar-exporter \ --name stellar-exporter \
registry.gitlab.com/ix.ai/stellar-exporter:latest registry.gitlab.com/ix.ai/stellar-exporter:latest
``` ```
## Supported variables ## Supported variables
| **Variable** | **Default** | **Mandatory** | **Description** | | **Variable** | **Default** | **Mandatory** | **Description** |
|:-------------|:-----------:|:-------------:|:-----------------------------------------------------------------------------------------------------------------------| |:--------------|:------------------------------:|:-------------:|:-----------------------------------------------------------------------------------------------------------------------|
| `ACCOUNTS` | - | **YES** | comma separated list of the accounts monitor the balances | | `ACCOUNTS` | - | **YES** | comma separated list of the accounts monitor the balances |
| `LOGLEVEL` | `INFO` | **NO** | [Logging Level](https://docs.python.org/3/library/logging.html#levels) | | `HORIZON_URL` | `https://horizon.stellar.org/` | **NO** | The URL of the horizon server. For the Test network you can use `https://horizon-testnet.stellar.org/` |
| `GELF_HOST` | - | **NO** | if set, the exporter will also log to this [GELF](https://docs.graylog.org/en/3.0/pages/gelf.html) capable host on UDP | | `LOGLEVEL` | `INFO` | **NO** | [Logging Level](https://docs.python.org/3/library/logging.html#levels) |
| `GELF_PORT` | `12201` | **NO** | Ignored, if `GELF_HOST` is unset. The UDP port for GELF logging | | `GELF_HOST` | - | **NO** | if set, the exporter will also log to this [GELF](https://docs.graylog.org/en/3.0/pages/gelf.html) capable host on UDP |
| `PORT` | `9308` | **NO** | The port for prometheus metrics | | `GELF_PORT` | `12201` | **NO** | Ignored, if `GELF_HOST` is unset. The UDP port for GELF logging |
| `PORT` | `9188` | **NO** | The port for prometheus metrics |
......
pbkdf2 pbkdf2
prometheus_client prometheus_client==0.7.1
pygelf pygelf
stellar-base stellar-base==1.1.2.0
stellar-sdk stellar-sdk==2.1.0
toml toml==0.10.0
...@@ -5,7 +5,7 @@ import time ...@@ -5,7 +5,7 @@ import time
import os import os
import sys import sys
import pygelf import pygelf
from stellar_base.address import Address from stellar_sdk.server import Server
from prometheus_client import start_http_server from prometheus_client import start_http_server
from prometheus_client.core import REGISTRY, GaugeMetricFamily from prometheus_client.core import REGISTRY, GaugeMetricFamily
...@@ -41,29 +41,31 @@ class StellarCollector: ...@@ -41,29 +41,31 @@ class StellarCollector:
settings = {} settings = {}
def __init__(self): def __init__(self):
server = os.environ.get('HORIZON_URL') if os.environ.get('HORIZON_URL') else 'https://horizon.stellar.org/'
self.settings = { self.settings = {
'accounts': os.environ.get("ACCOUNTS", '').split(','), 'accounts': os.environ.get("ACCOUNTS", '').split(','),
'server': Server(horizon_url=server),
} }
def get_accounts(self): def get_accounts(self):
""" Connects to the Stellar network and retrieves the account information """ """ Connects to the Stellar network and retrieves the account information """
for account in self.settings['accounts']: for account in self.settings['accounts']:
a = Address(address=account, network='public') balances = self.settings['server'].accounts().account_id(account).call().get('balances')
a.get() if isinstance(balances, list):
for balance in a.balances: for balance in balances:
if balance.get('asset_code'): if balance.get('asset_code'):
currency = balance.get('asset_code') currency = balance.get('asset_code')
elif balance.get('asset_type') == 'native': elif balance.get('asset_type') == 'native':
currency = 'XLM' currency = 'XLM'
else: else:
currency = balance.get('asset_type') currency = balance.get('asset_type')
self.accounts.update({ self.accounts.update({
'{}-{}'.format(account, currency): { '{}-{}'.format(account, currency): {
'account': account, 'account': account,
'currency': currency, 'currency': currency,
'balance': float(balance.get('balance')) 'balance': float(balance.get('balance'))
} }
}) })
LOG.debug('Found the following accounts: {}'.format(self.accounts)) LOG.debug('Found the following accounts: {}'.format(self.accounts))
...@@ -97,7 +99,7 @@ class StellarCollector: ...@@ -97,7 +99,7 @@ class StellarCollector:
if __name__ == '__main__': if __name__ == '__main__':
configure_logging() configure_logging()
PORT = int(os.environ.get('PORT', 9308)) PORT = int(os.environ.get('PORT', 9188))
LOG.info("Starting on port {}".format(PORT)) LOG.info("Starting on port {}".format(PORT))
REGISTRY.register(StellarCollector()) REGISTRY.register(StellarCollector())
TEST = os.environ.get('TEST', False) TEST = os.environ.get('TEST', False)
......
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