Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Merge branch 'fix-pipeline' into 'master'
Browse files Browse the repository at this point in the history
Fixes the build pipeline. Also, updates the versions in requirements.txt

See merge request ix.ai/stellar-exporter!13
  • Loading branch information
tlex committed Jan 5, 2020
2 parents 3d98064 + 3d5ca5b commit 73ec549
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |



Expand Down
8 changes: 4 additions & 4 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
38 changes: 20 additions & 18 deletions src/stellar-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -97,7 +99,7 @@ def collect(self):

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)
Expand Down

0 comments on commit 73ec549

Please sign in to comment.