У меня есть скрипт Python, который выбрасывает данные на localhost: 8093. Prometheus настроен на получение данных из этого источника, а Grafana настроен на использование Prometheus в качестве источника. Теперь я могу видеть переменные на порте 8093 (где мой сценарий генерирует данные), но я не могу видеть какие-либо значения в Grafana - я вижу предложения переменных при вводе запроса в Grafana, но они имеют значение NULL (N/ A) значения.
Я пытался проверить, поступают ли данные с 8093 на Прометей, но не смог проверить. Однако из 8 переменных одна приходит нормально. Остальные все отсутствуют (null).
Мой код, который выдает данные:
import json
import time
from statistics import median
import requests
from prometheus_client import (Enum, Gauge, Histogram, Summary,
start_http_server)
from exchanges_config import *
from self_health_check.utils import send_slack_notification
start_http_server(8093)
def notify_driver_health_check_issue(exception):
send_slack_notification(message="Some issue in driver_health_check!")
send_slack_notification(message=str(exception))
def notify_exchange_error(exchange, exception):
send_slack_notification(
message="Something wrong or mismatching in {}'s response -> {}".format(
exchange, exception
)
)
slack_notification_counter = 0
while True:
# get the response for all exchanges asap, all at once to avoid time difference
exmo_response = bitlish_response = bittrex_spot_price_zec_usd_response = \
bittrex_spot_price_zec_btc_response = bittrex_transaction_volume_response = gemini_zec_usd_response = \
gemini_zec_btc_response = bitfinex_zec_usd_response = bitfinex_zec_btc_response = \
binance_zec_btc_response = coinbase_zec_usd_response = \
kraken_zec_usd_response = coinjar_zec_btc_response = None
try:
exmo_response = requests.get(url=EXMO_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bitlish_response = requests.get(url=BITLISH_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bittrex_spot_price_zec_usd_response = requests.get(
url=BITTREX_ZEC_USD_SPOT_PRICE_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bittrex_spot_price_zec_btc_response = requests.get(
url=BITTREX_ZEC_BTC_SPOT_PRICE_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bittrex_transaction_volume_response = requests.get(
url=BITTREX_TRANSACTION_VOLUME_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
gemini_zec_usd_response = requests.get(
url=GEMINI_ZEC_USD_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
gemini_zec_btc_response = requests.get(
url=GEMINI_ZEC_BTC_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bitfinex_zec_usd_response = requests.get(
url=BITFINEX_ZEC_USD_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
bitfinex_zec_btc_response = requests.get(
url=BITFINEX_ZEC_BTC_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
binance_zec_btc_response = requests.get(
url=BINANCE_ZEC_BTC_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
coinbase_zec_usd_response = requests.get(url=COINBASE_ZEC_USD_URI, timeout=5, headers={
'AUTHORIZATION': 'Bearer abd90df5f27a7b170cd775abf89d632b350b7c1c9d53e08b340cd9832ce52c2c'})
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
kraken_zec_usd_response = requests.get(
url=KRAKEN_ZEC_USD_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
try:
coinjar_zec_btc_response = requests.get(
url=COINJAR_ZEC_BTC_URL, timeout=5)
except Exception as e:
notify_driver_health_check_issue(e)
pass
# Exmo
try:
exmo_data = exmo_response.json()
# setting transaction volume in USD
exmo_usd_transaction_volume = exmo_data['ZEC_USD']['vol_curr']
# setting zec_usd spot price
exmo_usd_spot_price = float(exmo_data['ZEC_USD']['last_trade'])
# setting transaction volume in BTC
exmo_btc_transaction_volume = exmo_data['ZEC_BTC']['vol_curr']
# setting zec_btc spot price
exmo_btc_spot_price = float(exmo_data['ZEC_BTC']['last_trade'])
# plotting usd and btc transaction volume and spot price
if exmo_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
EXMO_TRANSACTION_VOLUME_USD_PORT.state(set_state)
if exmo_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
EXMO_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
if exmo_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
EXMO_SPOT_PRICE_USD_PORT.state(set_state)
if exmo_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
EXMO_SPOT_PRICE_BTC_PORT.state(set_state)
except Exception as e:
if exmo_response is None:
send_slack_notification(message="Exmo response is None!")
else:
notify_exchange_error("Exmo", str(e))
# Bitlish
try:
bitlish_data = bitlish_response.json()
# setting transaction volume in USD
bitlish_usd_transaction_volume = bitlish_data['zecusd']['updated']
# setting zec_usd spot price
bitlish_usd_spot_price = float(bitlish_data['zecusd']['last'])
# setting transaction volume in BTC
bitlish_btc_transaction_volume = bitlish_data['zecbtc']['updated']
# setting zec_btc spot price
bitlish_btc_spot_price = float(bitlish_data['zecbtc']['last'])
# plotting usd and btc transaction volume and spot price
if bitlish_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITLISH_TRANSACTION_VOLUME_USD_PORT.state(set_state)
if bitlish_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITLISH_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
if bitlish_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITLISH_SPOT_PRICE_USD_PORT.state(set_state)
if bitlish_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITLISH_SPOT_PRICE_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Bitlish", str(e))
# Bittrex
try:
bittrex_spot_price_zec_btc_data = bittrex_spot_price_zec_btc_response.json()
bittrex_btc_spot_price = float(
bittrex_spot_price_zec_btc_data['result']['Last'])
bittrex_spot_price_zec_usd_data = bittrex_spot_price_zec_usd_response.json()
bittrex_usd_spot_price = float(
bittrex_spot_price_zec_usd_data['result']['Last'])
bittrex_transaction_volume_data = bittrex_transaction_volume_response.json()
for obj in bittrex_transaction_volume_data:
if obj["symbol"] == "ZEC-USD":
bittrex_usd_transaction_volume = obj['volume']
if bittrex_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITTREX_TRANSACTION_VOLUME_USD_PORT.state(set_state)
if obj["symbol"] == "ZEC-BTC":
bittrex_btc_transaction_volume = obj['volume']
if bittrex_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITTREX_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
if bittrex_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITTREX_SPOT_PRICE_USD_PORT.state(set_state)
if bittrex_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITTREX_SPOT_PRICE_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Bitrex", str(e))
# Gemini
try:
gemini_zec_usd_data = gemini_zec_usd_response.json()
gemini_zec_btc_data = gemini_zec_btc_response.json()
gemini_usd_spot_price = float(gemini_zec_usd_data['last'])
gemini_btc_spot_price = float(gemini_zec_btc_data['last'])
gemini_usd_transaction_volume = gemini_zec_usd_data['volume']['ZEC']
gemini_btc_transaction_volume = gemini_zec_btc_data['volume']['ZEC']
if gemini_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
GEMINI_SPOT_PRICE_USD_PORT.state(set_state)
if gemini_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
GEMINI_SPOT_PRICE_BTC_PORT.state(set_state)
if gemini_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
GEMINI_TRANSACTION_VOLUME_USD_PORT.state(set_state)
if gemini_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
GEMINI_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Gemini", str(e))
# Bitfinex
try:
bitfinex_zec_usd_data = bitfinex_zec_usd_response.json()
bitfinex_zec_btc_data = bitfinex_zec_btc_response.json()
bitfinex_usd_spot_price = float(bitfinex_zec_usd_data[0][-4])
bitfinex_btc_spot_price = float(bitfinex_zec_btc_data[0][-4])
bitfinex_usd_transaction_volume = bitfinex_zec_usd_data[0][-3]
bitfinex_btc_transaction_volume = bitfinex_zec_btc_data[0][-3]
if bitfinex_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITFINEX_SPOT_PRICE_USD_PORT.state(set_state)
if bitfinex_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BITFINEX_SPOT_PRICE_BTC_PORT.state(set_state)
if bitfinex_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITFINEX_TRANSACTION_VOLUME_USD_PORT.state(set_state)
if bitfinex_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BITFINEX_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Bitfinex", str(e))
# Binance
try:
binance_zec_btc_data = binance_zec_btc_response.json()
binance_btc_spot_price = float(binance_zec_btc_data['lastPrice'])
binance_btc_transaction_volume = float(binance_zec_btc_data['volume'])
if binance_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
BINANCE_SPOT_PRICE_BTC_PORT.state(set_state)
if binance_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
BINANCE_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Binance", str(e))
# Coinbase
try:
coinbase_zec_usd_data = coinbase_zec_usd_response.json()['data']
coinbase_usd_spot_price = float(coinbase_zec_usd_data['amount'])
if coinbase_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
COINBASE_SPOT_PRICE_USD_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Coinbase", str(e))
# Kraken
try:
kraken_zec_usd_data = kraken_zec_usd_response.json()[
'result']['XZECZUSD']
kraken_usd_spot_price = float(kraken_zec_usd_data['c'][0])
kraken_usd_transaction_volume = float(kraken_zec_usd_data['c'][1])
if kraken_usd_spot_price == 0:
set_state = '0'
else:
set_state = '1'
KRAKEN_SPOT_PRICE_USD_PORT.state(set_state)
if kraken_usd_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
KRAKEN_TRANSACTION_VOLUME_USD_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Kraken", str(e))
# Coinjar
try:
coinjar_zec_btc_data = coinjar_zec_btc_response.json()
coinjar_btc_spot_price = float(coinjar_zec_btc_data['last'])
coinjar_btc_transaction_volume = float(coinjar_zec_btc_data['volume'])
if coinjar_btc_spot_price == 0:
set_state = '0'
else:
set_state = '1'
COINJAR_SPOT_PRICE_BTC_PORT.state(set_state)
if coinjar_btc_transaction_volume == 0:
set_state = '0'
else:
set_state = '1'
COINJAR_TRANSACTION_VOLUME_BTC_PORT.state(set_state)
except Exception as e:
notify_exchange_error("Coinjar", str(e))
spot_price_usd = [exmo_usd_spot_price, bitlish_usd_spot_price,
bittrex_usd_spot_price, gemini_usd_spot_price, bitfinex_usd_spot_price, kraken_usd_spot_price]
spot_price_btc = [exmo_btc_spot_price, bitlish_btc_spot_price,
bittrex_btc_spot_price, gemini_btc_spot_price, bitfinex_btc_spot_price, binance_btc_spot_price]
spot_price_median_usd = median(spot_price_usd)
spot_price_median_btc = median(spot_price_btc)
# Create a config of exchange: price for many use-cases
spot_price_usd_all_exchanges = {
"Exmo": exmo_usd_spot_price,
"Bitlish": bitlish_usd_spot_price,
"Bittrex": bittrex_usd_spot_price,
"Gemini": gemini_usd_spot_price,
"Bitfinex": bitfinex_usd_spot_price,
"Coinbase": coinbase_usd_spot_price,
"Kraken": kraken_usd_spot_price
}
spot_price_btc_all_exchanges = {
"Exmo": exmo_btc_spot_price,
"Bitlish": bitlish_btc_spot_price,
"Bittrex": bittrex_btc_spot_price,
"Gemini": gemini_btc_spot_price,
"Bitfinex": bitfinex_btc_spot_price,
"Binance": binance_btc_spot_price,
"Coinjar": coinjar_btc_spot_price
}
for exchange_usd_price in spot_price_usd_all_exchanges.keys():
change_percentage = abs(
spot_price_usd_all_exchanges[exchange_usd_price] - spot_price_median_usd) / spot_price_median_usd * 100.0
USD_EXCHANGE[exchange_usd_price].set(change_percentage)
ABSOLUTE_PRICE_USD_EXCHANGE[exchange_usd_price].set(
spot_price_usd_all_exchanges[exchange_usd_price])
for exchange_btc_price in spot_price_btc_all_exchanges.keys():
change_percentage = abs(
spot_price_btc_all_exchanges[exchange_btc_price] - spot_price_median_btc) / spot_price_median_btc * 100.0
BTC_EXCHANGE[exchange_btc_price].set(change_percentage)
ABSOLUTE_PRICE_BTC_EXCHANGE[exchange_btc_price].set(
spot_price_btc_all_exchanges[exchange_btc_price])
# transaction volume
transaction_volume_usd_all_exchanges = {
"Exmo": exmo_usd_transaction_volume,
"Bitlish": bitlish_usd_transaction_volume,
"Bittrex": bittrex_usd_transaction_volume,
"Gemini": gemini_usd_transaction_volume,
"Bitfinex": bitfinex_usd_transaction_volume,
"Kraken": kraken_usd_transaction_volume
}
transaction_volume_btc_all_exchanges = {
"Exmo": exmo_btc_transaction_volume,
"Bitlish": bitlish_btc_transaction_volume,
"Bittrex": bittrex_btc_transaction_volume,
"Gemini": gemini_btc_transaction_volume,
"Bitfinex": bitfinex_btc_transaction_volume,
"Binance": binance_btc_transaction_volume,
"Coinjar": coinjar_btc_spot_price
}
for transaction_volume_usd in transaction_volume_usd_all_exchanges.keys():
ABSOLUTE_TRANSACTION_VOLUME_USD_EXCHANGE[transaction_volume_usd].set(
transaction_volume_usd_all_exchanges[transaction_volume_usd])
for transaction_volume_btc in transaction_volume_btc_all_exchanges.keys():
ABSOLUTE_TRANSACTION_VOLUME_BTC_EXCHANGE[transaction_volume_btc].set(
transaction_volume_btc_all_exchanges[transaction_volume_btc]
)
print(slack_notification_counter)
slack_notification_counter += 1
if slack_notification_counter % 100 == 0:
send_slack_notification(
message="{} iterations of exchanges health checks done!".format(slack_notification_counter))
time.sleep(150)
Данные Exmo все в порядке. Остальное нет. Вот что я испытываю в Графане:
Как видите, kraken_usd_spot_price_absolute
доступен, но когда я его выбираю, он равен нулю. Однако, если я делаю то же самое для exmo_usd_spot_price_absolute
, это работает.
Моя конфигурация для выброса данных выглядит следующим образом:
# Kraken Configs
KRAKEN_ZEC_USD_URL = "https://api.kraken.com/0/public/Ticker?pair=ZECUSD"
KRAKEN_SPOT_PRICE_USD_PORT = Enum('kraken_spot_price_usd_check',
'Kraken Spot Price USD Check', states=['1', '0'])
KRAKEN_TRANSACTION_VOLUME_USD_PORT = Enum(
'kraken_transaction_volume_usd_check', 'Kraken Transaction Volume USD Check', states=['1', '0'])
KRAKEN_USD_SPOT_PRICE_DEVIATION_GAUGE = Gauge('kraken_usd_spot_price_deviation_gauge',
'kraken_usd_spot_price_deviation_gauge gauge') # Gauge Configs for Spot Price Deviation
KRAKEN_USD_SPOT_PRICE_ABSOLUTE = Gauge(
'kraken_usd_spot_price_absolute', 'kraken_usd_spot_price_absolute_gauge')
KRAKEN_USD_TRANSACTION_VOLUME_ABSOLUTE = Gauge(
'kraken_usd_transaction_volume_absolute', 'kraken_usd_transaction_volume_absolute_gauge')
# Exmo Configs
EXMO_URL = "https://api.exmo.com/v1/ticker/"
EXMO_SPOT_PRICE_USD_PORT = Enum('exmo_spot_price_usd_check',
'Exmo Spot Price USD Check', states=['1', '0'])
EXMO_SPOT_PRICE_BTC_PORT = Enum('exmo_spot_price_btc_check',
'Exmo Spot Price BTC Check', states=['1', '0'])
EXMO_TRANSACTION_VOLUME_USD_PORT = Enum(
'exmo_transaction_volume_usd_check', 'Exmo Transaction Volume USD Check', states=['1', '0'])
EXMO_TRANSACTION_VOLUME_BTC_PORT = Enum(
'exmo_transaction_volume_btc_check', 'Exmo Transaction Volume BTC Check', states=['1', '0'])
EXMO_SPOT_PRICE_MEDIAN_DEVIATION_PORT = Histogram(
'exmo_spot_price_deviation_check', 'Exmo Spot Price Deviation Check')
EXMO_SUMMARY = Summary('request_latency_seconds', 'Description of summary')
EXMO_USD_SPOT_PRICE_DEVIATION_GAUGE = Gauge('exmo_usd_spot_price_deviation_gauge',
'exmo_usd_spot_price_deviation_gauge gauge')
EXMO_BTC_SPOT_PRICE_DEVIATION_GAUGE = Gauge('exmo_btc_spot_price_deviation_gauge',
'exmo_btc_spot_price_deviation_gauge gauge')
EXMO_USD_SPOT_PRICE_ABSOLUTE = Gauge(
'exmo_usd_spot_price_absolute', 'exmo_usd_spot_price_absolute_gauge')
EXMO_BTC_SPOT_PRICE_ABSOLUTE = Gauge(
'exmo_btc_spot_price_absolute', 'exmo_btc_spot_price_absolute_gauge')
EXMO_USD_TRANSACTION_VOLUME_ABSOLUTE = Gauge(
'exmo_usd_transaction_volume_absolute', 'exmo_usd_transaction_volume_absolute_gauge')
EXMO_BTC_TRANSACTION_VOLUME_ABSOLUTE = Gauge(
'exmo_btc_transaction_volume_absolute', 'exmo_btc_transaction_volume_absolute_gauge')
Я позаботился о периодах времени. Я проверил ровно последние минуты, и даже тогда я мог видеть только Exmo. Немного контекста, сначала было добавлено exmo, а затем и все остальное. Однако я перезапустил сценарий и Прометей. Я могу видеть переменные в 8093 году.
Я ожидаю увидеть все такие переменные в моей графической панели.