Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: Energi Core daemon monitoring, suits other Bitcoin forks #5894

Merged
merged 14 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions collectors/python.d.plugin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ include dns_query_time/Makefile.inc
include dockerd/Makefile.inc
include dovecot/Makefile.inc
include elasticsearch/Makefile.inc
include energid/Makefile.inc
include example/Makefile.inc
include exim/Makefile.inc
include fail2ban/Makefile.inc
Expand Down
13 changes: 13 additions & 0 deletions collectors/python.d.plugin/energid/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: GPL-3.0-or-later

# THIS IS NOT A COMPLETE Makefile
# IT IS INCLUDED BY ITS PARENT'S Makefile.am
# IT IS REQUIRED TO REFERENCE ALL FILES RELATIVE TO THE PARENT

# install these files
dist_python_DATA += energid/energid.chart.py
dist_pythonconfig_DATA += energid/energid.conf

# do not install these files, but include them in the distribution
dist_noinst_DATA += energid/README.md energid/Makefile.inc

60 changes: 60 additions & 0 deletions collectors/python.d.plugin/energid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# energid

A collector for [Energi Core](https://github.com/energicryptocurrency/energi) node instance monitoring.

As Energi Core Gen 1 & 2 are based on the original Bitcoin code and
supports very similar JSON RPC, there is quite high chance the module works
with many others forks including bitcoind itself.

Introduces several new charts:

1. **Blockchain Index**
* blocks
* headers

2. **Blockchain Difficulty**
* diff

3. **MemPool** in MiB
* Max
* Usage
* TX Size

4. **Secure Memory** in KiB
* Total
* Locked
* Used

5. **Network**
* Connections

6. **UTXO** (Unspent Transaction Output)
* UTXO
* Xfers (related transactions)

Configuration is needed in most cases of secure deployment to specify RPC credentials.
However, Energi, Bitcoin and Dash daemons are checked on startup by default.

It may be desired to increase retry count for production use due to possibly long
daemon startup.

## Configuration

Sample:
```yaml
energi:
host: '127.0.0.1'
port: 9796
user: energi
pass: energi

bitcoin:
host: '127.0.0.1'
port: 8332
user: bitcoin
pass: bitcoin
```

---

[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fcollectors%2Fpython.d.plugin%2Fenergid%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
162 changes: 162 additions & 0 deletions collectors/python.d.plugin/energid/energid.chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# -*- coding: utf-8 -*-
# Description: Energi Core / Bitcoin netdata python.d module
# Author: Andrey Galkin <andrey@futoin.org> (andvgal)
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This module is designed for energid, but it should work with many other Bitcoin forks
# which support more or less standard JSON-RPC.
#

import json

from bases.FrameworkServices.UrlService import UrlService

update_every = 5

ORDER = [
'blockindex',
'difficulty',
'mempool',
'secmem',
'network',
'timeoffset',
'utxo',
'xfers',
]

CHARTS = {
'blockindex': {
'options': [None, 'Blockchain Index', 'count', 'blockchain', 'energi.blockindex', 'area'],
'lines': [
['blockchain_blocks', 'blocks', 'absolute'],
['blockchain_headers', 'headers', 'absolute'],
]
},
'difficulty': {
'options': [None, 'Blockchain Difficulty', 'difficulty', 'blockchain', 'energi.difficulty', 'line'],
'lines': [
['blockchain_difficulty', 'Diff', 'absolute'],
],
},
'mempool': {
'options': [None, 'MemPool', 'MiB', 'memory', 'energid.mempool', 'area'],
'lines': [
['mempool_max', 'Max', 'absolute', None, 1024*1024],
['mempool_current', 'Usage', 'absolute', None, 1024*1024],
['mempool_txsize', 'TX Size', 'absolute', None, 1024*1024],
],
},
'secmem': {
'options': [None, 'Secure Memory', 'KiB', 'memory', 'energid.secmem', 'area'],
'lines': [
['secmem_total', 'Total', 'absolute', None, 1024],
['secmem_locked', 'Locked', 'absolute', None, 1024],
['secmem_used', 'Used', 'absolute', None, 1024],
],
},
'network': {
'options': [None, 'Network', 'count', 'network', 'energid.network', 'line'],
'lines': [
['network_connections', 'Connections', 'absolute'],
],
},
'timeoffset': {
'options': [None, 'Network', 'seconds', 'network', 'energid.timeoffset', 'line'],
'lines': [
['network_timeoffset', 'offseet', 'absolute'],
],
},
'utxo': {
'options': [None, 'UTXO', 'count', 'UTXO', 'energid.utxo', 'line'],
'lines': [
['utxo_count', 'UTXO', 'absolute'],
],
},
'xfers': {
'options': [None, 'UTXO', 'count', 'UTXO', 'energid.xfers', 'line'],
'lines': [
['utxo_xfers', 'Xfers', 'absolute'],
],
},
}

METHODS = {
'getblockchaininfo': lambda r: {
'blockchain_blocks': r['blocks'],
'blockchain_headers': r['headers'],
'blockchain_difficulty': r['difficulty'],
},
'getmempoolinfo': lambda r: {
'mempool_txcount': r['size'],
'mempool_txsize': r['bytes'],
'mempool_current': r['usage'],
'mempool_max': r['maxmempool'],
},
'getmemoryinfo': lambda r: dict([
('secmem_' + k, v) for (k,v) in r['locked'].items()
]),
'getnetworkinfo': lambda r: {
'network_timeoffset' : r['timeoffset'],
'network_connections': r['connections'],
},
'gettxoutsetinfo': lambda r: {
'utxo_count' : r['txouts'],
'utxo_xfers' : r['transactions'],
'utxo_size' : r['disk_size'],
'utxo_amount' : r['total_amount'],
},
}

JSON_RPC_VERSION = '1.1'

class Service(UrlService):
def __init__(self, configuration=None, name=None):
UrlService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.host = self.configuration.get('host', '127.0.0.1')
self.port = self.configuration.get('port', 9796)
self.url = '{scheme}://{host}:{port}'.format(
scheme=self.configuration.get('scheme', 'http'),
host=self.host,
port=self.port,
)
ilyam8 marked this conversation as resolved.
Show resolved Hide resolved
self.method = 'POST'
self.header = {
'Content-Type': 'application/json',
}

def _get_data(self):
#
# Bitcoin family speak JSON-RPC version 1.0 for maximum compatibility,
# but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
# unspecified (HTTP errors and contents of 'error').
#
# 1.0 spec: https://www.jsonrpc.org/specification_v1
# 2.0 spec: https://www.jsonrpc.org/specification
#
# The call documentation: https://github.com/energicryptocurrency/core-api-documentation
#
batch = []

for i, method in enumerate(METHODS):
batch.append({
'version': JSON_RPC_VERSION,
'id': i,
'method': method,
'params': [],
})

result = self._get_raw_data(body=json.dumps(batch))

if not result:
return None

result = json.loads(result.decode('utf-8'))
ilyam8 marked this conversation as resolved.
Show resolved Hide resolved
data = dict()

for i, (_, handler) in enumerate(METHODS.items()):
r = result[i]
data.update(handler(r['result']))
ilyam8 marked this conversation as resolved.
Show resolved Hide resolved

return data
90 changes: 90 additions & 0 deletions collectors/python.d.plugin/energid/energid.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# netdata python.d.plugin configuration for energid
#
# This file is in YaML format. Generally the format is:
#
# name: value
#
# There are 2 sections:
# - global variables
# - one or more JOBS
#
# JOBS allow you to collect values from multiple sources.
# Each source will have its own set of charts.
#
# JOB parameters have to be indented (using spaces only, example below).

# ----------------------------------------------------------------------
# Global Variables
# These variables set the defaults for all JOBs, however each JOB
# may define its own, overriding the defaults.

# update_every sets the default data collection frequency.
# If unset, the python.d.plugin default is used.
# update_every: 1

# priority controls the order of charts at the netdata dashboard.
# Lower numbers move the charts towards the top of the page.
# If unset, the default for python.d.plugin is used.
# priority: 60000

# penalty indicates whether to apply penalty to update_every in case of failures.
# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
# penalty: yes

# autodetection_retry sets the job re-check interval in seconds.
# The job is not deleted if check fails.
# Attempts to start the job are made once every autodetection_retry.
# This feature is disabled by default.
# autodetection_retry: 0

# ----------------------------------------------------------------------
# JOBS (data collection sources)
#
# The default JOBS share the same *name*. JOBS with the same name
# are mutually exclusive. Only one of them will be allowed running at
# any time. This allows autodetection to try several alternatives and
# pick the one that works.
#
# Any number of jobs is supported.
#
# All python.d.plugin JOBS (for all its modules) support a set of
# predefined parameters. These are:
#
# job_name:
# name: myname # the JOB's name as it will appear at the
# # dashboard (by default is the job_name)
# # JOBs sharing a name are mutually exclusive
# update_every: 1 # the JOB's data collection frequency
# priority: 60000 # the JOB's order on the dashboard
# penalty: yes # the JOB's penalty
# autodetection_retry: 0 # the JOB's re-check interval in seconds
#
# Additionally to the above, energid also supports the following:
#
# host: 'IP or HOSTNAME' # type <str> the RPC host to connect to
# port: PORT # type <int> the RPC port to connect to
# user: 'RPC username' # type <str> the RPC username to use
# pass: 'RPC password' # type <str> the RPC password to use
#
# ----------------------------------------------------------------------
# AUTO-DETECTION JOBS
# only one of them will run (they have the same name)
#

# Defaults:
# host: '127.0.0.1'
# user:
# pass:
#
ilyam8 marked this conversation as resolved.
Show resolved Hide resolved

# Energi mainnet
energi:
port: 9796

# Most likely supported Bitcoin mainnet
bitcoin:
port: 8332

# Most likely supported Dash mainnet
dash:
port: 9998
1 change: 1 addition & 0 deletions collectors/python.d.plugin/python.d.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ chrony: no
# dockerd: yes
# dovecot: yes
# elasticsearch: yes
# energi: yes

# this is just an example
example: no
Expand Down