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:
- remote: https://gitlab.com/ix.ai/ci-templates/raw/master/python-project.yml
test:
extends:
- .tags-template
stage: test
image: python:latest
variables:
......
......@@ -6,12 +6,10 @@ WORKDIR /app
COPY src/ /app
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 && \
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 9308
EXPOSE 9188
ENTRYPOINT ["python3", "/app/stellar-exporter.py"]
......@@ -12,19 +12,21 @@ A [Prometheus](https://prometheus.io) exporter for [Stellar](https://www.stellar
docker run --rm -it -p 9308:9308 \
-e LOGLEVEL=DEBUG \
-e GELF_HOST=graylog \
-e ACCOUNTS='AAAAA,BBBBB' \
--name stellar-exporter \
registry.gitlab.com/ix.ai/stellar-exporter:latest
```
## Supported variables
| **Variable** | **Default** | **Mandatory** | **Description** |
|:-------------|:-----------:|:-------------:|:-----------------------------------------------------------------------------------------------------------------------|
| `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) |
| `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 |
| `GELF_PORT` | `12201` | **NO** | Ignored, if `GELF_HOST` is unset. The UDP port for GELF logging |
| `PORT` | `9308` | **NO** | The port for prometheus metrics |
| **Variable** | **Default** | **Mandatory** | **Description** |
|:--------------|:------------------------------:|:-------------:|:-----------------------------------------------------------------------------------------------------------------------|
| `ACCOUNTS` | - | **YES** | comma separated list of the accounts monitor the balances |
| `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/` |
| `LOGLEVEL` | `INFO` | **NO** | [Logging Level](https://docs.python.org/3/library/logging.html#levels) |
| `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 |
| `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
prometheus_client
prometheus_client==0.7.1
pygelf
stellar-base
stellar-sdk
toml
stellar-base==1.1.2.0
stellar-sdk==2.1.0
toml==0.10.0
......@@ -5,7 +5,7 @@ import time
import os
import sys
import pygelf
from stellar_base.address import Address
from stellar_sdk.server import Server
from prometheus_client import start_http_server
from prometheus_client.core import REGISTRY, GaugeMetricFamily
......@@ -41,29 +41,31 @@ class StellarCollector:
settings = {}
def __init__(self):
server = os.environ.get('HORIZON_URL') if os.environ.get('HORIZON_URL') else 'https://horizon.stellar.org/'
self.settings = {
'accounts': os.environ.get("ACCOUNTS", '').split(','),
'server': Server(horizon_url=server),
}
def get_accounts(self):
""" Connects to the Stellar network and retrieves the account information """
for account in self.settings['accounts']:
a = Address(address=account, network='public')
a.get()
for balance in a.balances:
if balance.get('asset_code'):
currency = balance.get('asset_code')
elif balance.get('asset_type') == 'native':
currency = 'XLM'
else:
currency = balance.get('asset_type')
self.accounts.update({
'{}-{}'.format(account, currency): {
'account': account,
'currency': currency,
'balance': float(balance.get('balance'))
}
})
balances = self.settings['server'].accounts().account_id(account).call().get('balances')
if isinstance(balances, list):
for balance in balances:
if balance.get('asset_code'):
currency = balance.get('asset_code')
elif balance.get('asset_type') == 'native':
currency = 'XLM'
else:
currency = balance.get('asset_type')
self.accounts.update({
'{}-{}'.format(account, currency): {
'account': account,
'currency': currency,
'balance': float(balance.get('balance'))
}
})
LOG.debug('Found the following accounts: {}'.format(self.accounts))
......@@ -97,7 +99,7 @@ class StellarCollector:
if __name__ == '__main__':
configure_logging()
PORT = int(os.environ.get('PORT', 9308))
PORT = int(os.environ.get('PORT', 9188))
LOG.info("Starting on port {}".format(PORT))
REGISTRY.register(StellarCollector())
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