-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Labels refactoring and additional error handling. * Update README.md
- Loading branch information
1 parent
0b42f98
commit b903183
Showing
13 changed files
with
243 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,34 @@ | ||
from helpers import strip_url | ||
from settings import cfg, logger | ||
from helpers import strip_url, validate_protocol, generate_labels_from_metadata | ||
from settings import logger | ||
from time import perf_counter | ||
import requests | ||
|
||
|
||
class doge_collector(): | ||
|
||
def __init__(self, https_url, provider): | ||
self.https_url = https_url | ||
self.labels = [ | ||
'https_url', 'provider', 'blockchain', 'network_name', | ||
'network_type' | ||
] | ||
self.labels_values = [ | ||
https_url, provider, cfg.blockchain, cfg.network_name, | ||
cfg.network_type | ||
] | ||
def __init__(self, rpc_metadata): | ||
validate_protocol(rpc_metadata['url'], "https") | ||
self.url = rpc_metadata['url'] | ||
self.labels, self.labels_values = generate_labels_from_metadata(rpc_metadata) | ||
|
||
def probe(self, metrics): | ||
try: | ||
payload = {'version': '1.1', 'method': "getinfo", 'id': 1} | ||
start = perf_counter() | ||
response = requests.post(self.https_url, json=payload).json() | ||
response = requests.post(self.url, json=payload).json() | ||
latency = (perf_counter() - start) * 1000 | ||
|
||
if response: | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, True) | ||
metrics['ws_rpc_latency'].add_metric(self.labels_values, | ||
latency) | ||
metrics['ws_rpc_block_height'].add_metric( | ||
self.labels_values, response['result']['blocks']) | ||
metrics['ws_rpc_total_difficulty'].add_metric( | ||
self.labels_values, response['result']['difficulty']) | ||
metrics['ws_rpc_latency'].add_metric(self.labels_values, latency) | ||
metrics['ws_rpc_block_height'].add_metric(self.labels_values, response['result']['blocks']) | ||
metrics['ws_rpc_total_difficulty'].add_metric(self.labels_values, response['result']['difficulty']) | ||
else: | ||
logger.error("Bad response from client {}: {}".format( | ||
strip_url(self.https_url), exc)) | ||
logger.error("Bad response from client {}: {}".format(strip_url(self.url), exc)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) | ||
except requests.RequestException as exc: | ||
logger.error("Health check failed for {}: {}".format( | ||
strip_url(self.https_url), exc)) | ||
logger.error("Health check failed for {}: {}".format(strip_url(self.url), exc)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) | ||
except Exception as exc: | ||
logger.error("Health check failed for {}: {}".format( | ||
strip_url(self.https_url), exc)) | ||
logger.error("Health check failed for {}: {}".format(strip_url(self.url), exc)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,35 @@ | ||
from helpers import strip_url | ||
from settings import cfg, logger | ||
from helpers import strip_url, validate_protocol, generate_labels_from_metadata | ||
from settings import logger | ||
from time import perf_counter | ||
import requests | ||
|
||
|
||
class filecoin_collector(): | ||
|
||
def __init__(self, https_url, provider): | ||
self.https_url = https_url | ||
self.labels = [ | ||
'https_url', 'provider', 'blockchain', 'network_name', | ||
'network_type' | ||
] | ||
self.labels_values = [ | ||
https_url, provider, cfg.blockchain, cfg.network_name, | ||
cfg.network_type | ||
] | ||
def __init__(self, rpc_metadata): | ||
validate_protocol(rpc_metadata['url'], "https") | ||
self.url = rpc_metadata['url'] | ||
|
||
self.labels, self.labels_values = generate_labels_from_metadata(rpc_metadata) | ||
|
||
def probe(self, metrics): | ||
try: | ||
payload = { | ||
'jsonrpc': '2.0', | ||
'method': "Filecoin.ChainHead", | ||
'id': 1 | ||
} | ||
payload = {'jsonrpc': '2.0', 'method': "Filecoin.ChainHead", 'id': 1} | ||
start = perf_counter() | ||
response = requests.post(self.https_url, json=payload).json() | ||
response = requests.post(self.url, json=payload) | ||
latency = (perf_counter() - start) * 1000 | ||
|
||
if response: | ||
if response.ok: | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, True) | ||
metrics['ws_rpc_latency'].add_metric(self.labels_values, | ||
latency) | ||
metrics['ws_rpc_block_height'].add_metric( | ||
self.labels_values, response['result']['Height']) | ||
metrics['ws_rpc_latency'].add_metric(self.labels_values, latency) | ||
metrics['ws_rpc_block_height'].add_metric(self.labels_values, response.json()['result']['Height']) | ||
else: | ||
logger.error("Bad response from client {}: {}".format( | ||
strip_url(self.https_url), exc)) | ||
logger.error("Bad response from client while fetching Filecoin.ChainHead method for {}: {}".format( | ||
strip_url(self.url), response)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) | ||
except requests.RequestException as exc: | ||
logger.error("Health check failed for {}: {}".format( | ||
strip_url(self.https_url), exc)) | ||
logger.error("Health check failed for {}: {}".format(strip_url(self.url), exc)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) | ||
except Exception as e: | ||
logger.error("Health check failed for {}: {}".format( | ||
strip_url(self.https_url), e)) | ||
logger.error("Health check failed for {}: {}".format(strip_url(self.url), e)) | ||
metrics['ws_rpc_health'].add_metric(self.labels_values, False) |
Oops, something went wrong.