From 14ffe739a5a3b212b6b59a49003432a9e41196c2 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 16 Feb 2016 10:04:33 +0100 Subject: [PATCH 01/22] initial commit --- bigchaindb/core.py | 7 +++++++ bigchaindb/monitor.py | 11 +++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 bigchaindb/monitor.py diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 286336a0..e1382390 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -10,7 +10,9 @@ import bigchaindb import bigchaindb.config_utils from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair +from bigchaindb.monitor import Monitor +c = Monitor() class GenesisBlockAlreadyExistsError(Exception): pass @@ -67,6 +69,7 @@ class Bigchain(object): def reconnect(self): return r.connect(host=self.host, port=self.port, db=self.dbname) + @c.timer('create_transaction', rate=0.01) def create_transaction(self, current_owner, new_owner, tx_input, operation, payload=None): """Create a new transaction @@ -176,6 +179,7 @@ class Bigchain(object): public_key = PublicKey(public_key_base58) return public_key.verify(self.serialize(data), signature) + @c.timer('write_transaction', rate=0.01) def write_transaction(self, signed_transaction): """Write the transaction to bigchain. @@ -312,6 +316,7 @@ class Bigchain(object): return owned + @c.timer('validate_transaction', rate=0.01) def validate_transaction(self, transaction): """Validate a transaction. @@ -389,6 +394,7 @@ class Bigchain(object): exceptions.InvalidHash, exceptions.InvalidSignature): return False + @c.timer('create_block') def create_block(self, validated_transactions): """Creates a block given a list of `validated_transactions`. @@ -424,6 +430,7 @@ class Bigchain(object): return block + @c.timer('validate_block') # TODO: check that the votings structure is correctly constructed def validate_block(self, block): """Validate a block. diff --git a/bigchaindb/monitor.py b/bigchaindb/monitor.py new file mode 100644 index 00000000..5e88cffa --- /dev/null +++ b/bigchaindb/monitor.py @@ -0,0 +1,11 @@ +import statsd +from os import getppid +from platform import node + +class Monitor(statsd.StatsClient): + def __init__(self, *args, **kwargs): + if not kwargs: + kwargs = {} + if not kwargs.get('prefix'): + kwargs['prefix'] = '{hostname}_{pid}.'.format(hostname=node(), pid=getppid()) + super().__init__(*args, **kwargs) diff --git a/docker-compose.yml b/docker-compose.yml index fb9727a4..73f48f95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,33 @@ bigchaindb: - ~/.bigchaindb_docker:/root/.bigchaindb_docker links: - rethinkdb + - statsd:localhost environment: BIGCHAIN_DATABASE_HOST: rethinkdb BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config command: bigchaindb start + +influxdb: + image: tutum/influxdb + ports: + - "8083:8083" + - "8086:8086" + expose: + - "8090" + - "8099" + environment: + PRE_CREATE_DB: "telegraf" + +grafana: + build: ~/grafana-bigchaindb-docker + ports: + - "3000:3000" + links: + - influxdb:localhost + +statsd: + image: rhsimplex/docker-telegraf-statsd + expose: + - "8125/udp" + links: + - influxdb:localhost \ No newline at end of file From fc045d1174e4a52472d7c397598f5629b43983d4 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 17 Feb 2016 14:55:55 +0100 Subject: [PATCH 02/22] timing adjustments --- bigchaindb/core.py | 4 ++-- docker-compose.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 1c876a4c..fda96240 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -12,7 +12,7 @@ from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair from bigchaindb.monitor import Monitor -c = Monitor() +c = Monitor(host='statsd_1') class GenesisBlockAlreadyExistsError(Exception): pass @@ -317,7 +317,7 @@ class Bigchain(object): return owned - @c.timer('validate_transaction', rate=0.01) + @c.timer('validate_transaction')#, rate=0.01) def validate_transaction(self, transaction): """Validate a transaction. diff --git a/docker-compose.yml b/docker-compose.yml index 73f48f95..a529028c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,7 +50,7 @@ grafana: statsd: image: rhsimplex/docker-telegraf-statsd - expose: - - "8125/udp" + ports: + - "8125:8125/udp" links: - influxdb:localhost \ No newline at end of file From 2350ec156402ad3c479c73d47c05877045bae65d Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 17 Feb 2016 16:09:08 +0100 Subject: [PATCH 03/22] more measurements --- bigchaindb/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigchaindb/core.py b/bigchaindb/core.py index fda96240..9981eaf2 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -395,7 +395,6 @@ class Bigchain(object): exceptions.InvalidHash, exceptions.InvalidSignature): return False - @c.timer('create_block') def create_block(self, validated_transactions): """Creates a block given a list of `validated_transactions`. @@ -476,6 +475,7 @@ class Bigchain(object): except Exception: return False + @c.timer('write_block') def write_block(self, block, durability='soft'): """Write a block to bigchain. From f32425d6ff6d73437be2007439304b4bceaef50c Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Feb 2016 09:39:20 +0100 Subject: [PATCH 04/22] reorganize yml --- docker-compose-monitor.yml | 92 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 docker-compose-monitor.yml diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml new file mode 100644 index 00000000..34dc11f6 --- /dev/null +++ b/docker-compose-monitor.yml @@ -0,0 +1,92 @@ +rethinkdb-1: + image: rethinkdb + ports: + - "9999:8080" + - "28015:28015" + - "29015:29015" + volumes_from: + - rethinkdb-data-1 + +rethinkdb-data-1: + image: rethinkdb + volumes: + - /data + command: "true" + +bigchaindb-1: + build: . + volumes: + - ./bigchaindb:/usr/src/app/bigchaindb + - ./tests:/usr/src/app/tests + - ./docs:/usr/src/app/docs + - ./setup.py:/usr/src/app/setup.py + - ./setup.cfg:/usr/src/app/setup.cfg + - ./pytest.ini:/usr/src/app/pytest.ini + - ~/.bigchaindb_docker:/root/.bigchaindb_docker + links: + - rethinkdb-1:rethinkdb + - statsd:localhost + environment: + BIGCHAIN_DATABASE_HOST: rethinkdb + BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config + command: bigchaindb start + +rethinkdb-2: + image: rethinkdb + ports: + - "9998:8080" + - "28015:28015" + - "29015:29015" + links: + - rethinkdb-1:localhost + volumes_from: + - rethinkdb-data-2 + +rethinkdb-data-2: + image: rethinkdb + volumes: + - /data + command: "true" + +bigchaindb-2: + build: . + volumes: + - ./bigchaindb:/usr/src/app/bigchaindb + - ./tests:/usr/src/app/tests + - ./docs:/usr/src/app/docs + - ./setup.py:/usr/src/app/setup.py + - ./setup.cfg:/usr/src/app/setup.cfg + - ./pytest.ini:/usr/src/app/pytest.ini + - ~/.bigchaindb_docker:/root/.bigchaindb_docker + links: + - rethinkdb-2:rethinkdb + - statsd:localhost + environment: + BIGCHAIN_DATABASE_HOST: rethinkdb + BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config + command: bigchaindb start + +influxdb: + image: tutum/influxdb + ports: + - "8083:8083" + - "8086:8086" + expose: + - "8090" + - "8099" + environment: + PRE_CREATE_DB: "telegraf" + +grafana: + build: ~/grafana-bigchaindb-docker + ports: + - "3000:3000" + links: + - influxdb:localhost + +statsd: + image: rhsimplex/docker-telegraf-statsd + ports: + - "8125:8125/udp" + links: + - influxdb:localhost \ No newline at end of file From a037e7f0423b26783bd7bd176195cdbdcad52e6a Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Feb 2016 09:39:42 +0100 Subject: [PATCH 05/22] reorganize yml --- docker-compose.yml | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a529028c..646fc946 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,33 +24,7 @@ bigchaindb: - ~/.bigchaindb_docker:/root/.bigchaindb_docker links: - rethinkdb - - statsd:localhost environment: BIGCHAIN_DATABASE_HOST: rethinkdb BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config - command: bigchaindb start - -influxdb: - image: tutum/influxdb - ports: - - "8083:8083" - - "8086:8086" - expose: - - "8090" - - "8099" - environment: - PRE_CREATE_DB: "telegraf" - -grafana: - build: ~/grafana-bigchaindb-docker - ports: - - "3000:3000" - links: - - influxdb:localhost - -statsd: - image: rhsimplex/docker-telegraf-statsd - ports: - - "8125:8125/udp" - links: - - influxdb:localhost \ No newline at end of file + command: bigchaindb start \ No newline at end of file From b9279431cd10666e944bc165d4530aac2741429f Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Feb 2016 11:39:10 +0100 Subject: [PATCH 06/22] small changes --- bigchaindb/monitor.py | 3 +-- docker-compose-monitor.yml | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bigchaindb/monitor.py b/bigchaindb/monitor.py index 5e88cffa..d3a33472 100644 --- a/bigchaindb/monitor.py +++ b/bigchaindb/monitor.py @@ -1,5 +1,4 @@ import statsd -from os import getppid from platform import node class Monitor(statsd.StatsClient): @@ -7,5 +6,5 @@ class Monitor(statsd.StatsClient): if not kwargs: kwargs = {} if not kwargs.get('prefix'): - kwargs['prefix'] = '{hostname}_{pid}.'.format(hostname=node(), pid=getppid()) + kwargs['prefix'] = '{hostname}.'.format(hostname=node()) super().__init__(*args, **kwargs) diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml index 34dc11f6..92dfeb19 100644 --- a/docker-compose-monitor.yml +++ b/docker-compose-monitor.yml @@ -2,8 +2,8 @@ rethinkdb-1: image: rethinkdb ports: - "9999:8080" - - "28015:28015" - - "29015:29015" + - "28015" + - "29015" volumes_from: - rethinkdb-data-1 @@ -35,8 +35,8 @@ rethinkdb-2: image: rethinkdb ports: - "9998:8080" - - "28015:28015" - - "29015:29015" + - "28015" + - "29015" links: - rethinkdb-1:localhost volumes_from: From cd9048d861e4625d2be4cf11e541b8d73ae7614d Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 18 Feb 2016 16:18:45 +0100 Subject: [PATCH 07/22] validation tx queue, comments --- bigchaindb/block.py | 7 +++++++ bigchaindb/core.py | 2 ++ 2 files changed, 9 insertions(+) diff --git a/bigchaindb/block.py b/bigchaindb/block.py index ed1257e9..144ebef8 100644 --- a/bigchaindb/block.py +++ b/bigchaindb/block.py @@ -5,10 +5,16 @@ import queue import rethinkdb as r from bigchaindb import Bigchain +from bigchaindb.monitor import Monitor + logger = logging.getLogger(__name__) +# obviously the hostname should come from an environment variable or setting +# http://i.imgur.com/qciaOed.jpg +c = Monitor(host='statsd_1') + class Block(object): @@ -32,6 +38,7 @@ class Block(object): b = Bigchain() while True: + c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=0.01) tx = self.q_new_transaction.get() # poison pill diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 9981eaf2..c5221c26 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -12,6 +12,8 @@ from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair from bigchaindb.monitor import Monitor +# obviously the hostname should come from an environment variable or setting + c = Monitor(host='statsd_1') class GenesisBlockAlreadyExistsError(Exception): From 131d7fad14575a6123f6ecca45e47d65f7370d8b Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 10:17:16 +0100 Subject: [PATCH 08/22] setup changes --- bigchaindb/__init__.py | 10 ++++++++-- bigchaindb/block.py | 5 +++-- bigchaindb/commands/bigchain.py | 4 ++++ bigchaindb/core.py | 9 ++++----- bigchaindb/monitor.py | 20 ++++++++++++++++++++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/bigchaindb/__init__.py b/bigchaindb/__init__.py index aec03314..4bb76c44 100644 --- a/bigchaindb/__init__.py +++ b/bigchaindb/__init__.py @@ -1,7 +1,6 @@ import os import copy -from bigchaindb.core import Bigchain # noqa def e(key, default=None, conv=None): @@ -35,10 +34,17 @@ config = { 'private': e('BIGCHAIN_KEYPAIR_PRIVATE') }, 'keyring': [ - ] + ], + 'statsd': { + 'host': e('BIGCHAIN_STATSD_HOST', default='localhost'), + 'port': e('BIGCHAIN_STATSD_PORT', default=8125), + 'rate': e('BIGCHAIN_STATSD_SAMPLERATE', default=0.01) + } } # We need to maintain a backup copy of the original config dict in case # the user wants to reconfigure the node. Check ``bigchaindb.config_utils`` # for more info. _config = copy.deepcopy(config) +from bigchaindb.core import Bigchain # noqa + diff --git a/bigchaindb/block.py b/bigchaindb/block.py index 144ebef8..c4e7e17a 100644 --- a/bigchaindb/block.py +++ b/bigchaindb/block.py @@ -4,6 +4,7 @@ import queue import rethinkdb as r +import bigchaindb from bigchaindb import Bigchain from bigchaindb.monitor import Monitor @@ -13,7 +14,7 @@ logger = logging.getLogger(__name__) # obviously the hostname should come from an environment variable or setting # http://i.imgur.com/qciaOed.jpg -c = Monitor(host='statsd_1') +c = Monitor() class Block(object): @@ -38,7 +39,7 @@ class Block(object): b = Bigchain() while True: - c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=0.01) + c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=bigchaindb.config['statsd']['rate']) tx = self.q_new_transaction.get() # poison pill diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index 7ea95851..21d157e3 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -56,6 +56,10 @@ def run_configure(args, skip_if_exists=False): val = conf['database'][key] conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val + for key in ('host', 'port', 'rate'): + val = conf['statsd'][key] + conf['statsd'][key] = input('Statsd {}? (default `{}`): '.format(key, val)) or val + bigchaindb.config_utils.write_config(conf, config_path) print('Ready to go!') diff --git a/bigchaindb/core.py b/bigchaindb/core.py index c5221c26..8a962a1b 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -12,9 +12,8 @@ from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair from bigchaindb.monitor import Monitor -# obviously the hostname should come from an environment variable or setting +c = Monitor() -c = Monitor(host='statsd_1') class GenesisBlockAlreadyExistsError(Exception): pass @@ -72,7 +71,7 @@ class Bigchain(object): def reconnect(self): return r.connect(host=self.host, port=self.port, db=self.dbname) - @c.timer('create_transaction', rate=0.01) + @c.timer('create_transaction', rate=bigchaindb.config['statsd']['rate']) def create_transaction(self, current_owner, new_owner, tx_input, operation, payload=None): """Create a new transaction @@ -182,7 +181,7 @@ class Bigchain(object): public_key = PublicKey(public_key_base58) return public_key.verify(self.serialize(data), signature) - @c.timer('write_transaction', rate=0.01) + @c.timer('write_transaction', rate=bigchaindb.config['statsd']['rate']) def write_transaction(self, signed_transaction): """Write the transaction to bigchain. @@ -319,7 +318,7 @@ class Bigchain(object): return owned - @c.timer('validate_transaction')#, rate=0.01) + @c.timer('validate_transaction', rate=bigchaindb.config['statsd']['rate']) def validate_transaction(self, transaction): """Validate a transaction. diff --git a/bigchaindb/monitor.py b/bigchaindb/monitor.py index d3a33472..be5c27cd 100644 --- a/bigchaindb/monitor.py +++ b/bigchaindb/monitor.py @@ -1,10 +1,30 @@ import statsd from platform import node +import bigchaindb +from bigchaindb import config_utils + class Monitor(statsd.StatsClient): + """Set up statsd monitoring + + """ def __init__(self, *args, **kwargs): + """Overrides statsd client, fixing prefix to messages and loading configuration + + Args: + *args: arguments (identical to Statsclient) + **kwargs: keyword arguments (identical to Statsclient) + """ + config_utils.autoconfigure() + if not kwargs: kwargs = {} + + # set prefix, parameters from configuration file if not kwargs.get('prefix'): kwargs['prefix'] = '{hostname}.'.format(hostname=node()) + if not kwargs.get('host'): + kwargs['host'] = bigchaindb.config['statsd']['host'] + if not kwargs.get('port'): + kwargs['port'] = bigchaindb.config['statsd']['port'] super().__init__(*args, **kwargs) From 5445a043b8cb82b96da5266d20c307805c06a4fc Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 10:59:26 +0100 Subject: [PATCH 09/22] docker-compose-monitor.yml --- docker-compose-monitor.yml | 68 -------------------------------------- 1 file changed, 68 deletions(-) diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml index 92dfeb19..7c48bd0e 100644 --- a/docker-compose-monitor.yml +++ b/docker-compose-monitor.yml @@ -1,71 +1,3 @@ -rethinkdb-1: - image: rethinkdb - ports: - - "9999:8080" - - "28015" - - "29015" - volumes_from: - - rethinkdb-data-1 - -rethinkdb-data-1: - image: rethinkdb - volumes: - - /data - command: "true" - -bigchaindb-1: - build: . - volumes: - - ./bigchaindb:/usr/src/app/bigchaindb - - ./tests:/usr/src/app/tests - - ./docs:/usr/src/app/docs - - ./setup.py:/usr/src/app/setup.py - - ./setup.cfg:/usr/src/app/setup.cfg - - ./pytest.ini:/usr/src/app/pytest.ini - - ~/.bigchaindb_docker:/root/.bigchaindb_docker - links: - - rethinkdb-1:rethinkdb - - statsd:localhost - environment: - BIGCHAIN_DATABASE_HOST: rethinkdb - BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config - command: bigchaindb start - -rethinkdb-2: - image: rethinkdb - ports: - - "9998:8080" - - "28015" - - "29015" - links: - - rethinkdb-1:localhost - volumes_from: - - rethinkdb-data-2 - -rethinkdb-data-2: - image: rethinkdb - volumes: - - /data - command: "true" - -bigchaindb-2: - build: . - volumes: - - ./bigchaindb:/usr/src/app/bigchaindb - - ./tests:/usr/src/app/tests - - ./docs:/usr/src/app/docs - - ./setup.py:/usr/src/app/setup.py - - ./setup.cfg:/usr/src/app/setup.cfg - - ./pytest.ini:/usr/src/app/pytest.ini - - ~/.bigchaindb_docker:/root/.bigchaindb_docker - links: - - rethinkdb-2:rethinkdb - - statsd:localhost - environment: - BIGCHAIN_DATABASE_HOST: rethinkdb - BIGCHAINDB_CONFIG_PATH: /root/.bigchaindb_docker/config - command: bigchaindb start - influxdb: image: tutum/influxdb ports: From 82e18826953ed8eb0465b65357791532eb372db1 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 14:15:13 +0100 Subject: [PATCH 10/22] trim docker compose --- docker-compose-monitor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml index 7c48bd0e..ebede989 100644 --- a/docker-compose-monitor.yml +++ b/docker-compose-monitor.yml @@ -10,7 +10,7 @@ influxdb: PRE_CREATE_DB: "telegraf" grafana: - build: ~/grafana-bigchaindb-docker + build: rhsimplex/grafana-bigchaindb-docker ports: - "3000:3000" links: From 09f244e325bd0fee9b008d2c63c9f065ea4accfa Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 14:15:44 +0100 Subject: [PATCH 11/22] read inputs in correct place --- bigchaindb/commands/bigchain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index a27a012c..33d37822 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -59,9 +59,9 @@ def run_configure(args, skip_if_exists=False): val = conf['database'][key] conf['database'][key] = input('Database {}? (default `{}`): '.format(key, val)) or val - for key in ('host', 'port', 'rate'): - val = conf['statsd'][key] - conf['statsd'][key] = input('Statsd {}? (default `{}`): '.format(key, val)) or val + for key in ('host', 'port', 'rate'): + val = conf['statsd'][key] + conf['statsd'][key] = input('Statsd {}? (default `{}`): '.format(key, val)) or val bigchaindb.config_utils.write_config(conf, config_path) print('Ready to go!') From 63fb14dcc5ee5b897b511de2dfeee140f6bb984c Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 14:16:02 +0100 Subject: [PATCH 12/22] adjust tests accordingly --- tests/test_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index b3c1ae58..faa455d0 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -60,6 +60,7 @@ def mock_bigchaindb_backup_config(monkeypatch): config = { 'keypair': {}, 'database': {'host': 'host', 'port': 12345, 'name': 'adbname'}, + 'statsd': {'host': 'host', 'port': 12345, 'rate': 0.1}, } monkeypatch.setattr('bigchaindb._config', config) From f71a166e796c47ae18837ab4ea62722f2c825c03 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 14:17:06 +0100 Subject: [PATCH 13/22] trim docker-compose --- docker-compose-monitor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml index ebede989..ea4faf54 100644 --- a/docker-compose-monitor.yml +++ b/docker-compose-monitor.yml @@ -10,7 +10,7 @@ influxdb: PRE_CREATE_DB: "telegraf" grafana: - build: rhsimplex/grafana-bigchaindb-docker + image: rhsimplex/grafana-bigchaindb-docker ports: - "3000:3000" links: From b4a023a9d28d67692e86ce216be19e37cea544eb Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 22 Feb 2016 14:59:19 +0100 Subject: [PATCH 14/22] update README.md --- README.md | 17 +++++++++++++++++ bigchaindb/block.py | 2 -- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 948b879c..bd1a06e6 100644 --- a/README.md +++ b/README.md @@ -79,3 +79,20 @@ $ bigchaindb show-config ``` $ py.test -v ``` + +#### Monitoring + +BigchainDB uses [statsd](https://github.com/etsy/statsd) for monitoring. To fully take advantage of this functionality requires some additional infrastructure: an agent to listen for metrics (e.g. [telegraf](https://github.com/influxdata/telegraf)), a time-series database (e.g. [influxdb](https://influxdata.com/time-series-platform/influxdb/), and a frontend to display analytics (e.g. [Grafana](http://grafana.org/)). + +For ease of use, we've provided a docker compose file that sets up all these services for testing. Simply run in the BigchainDB directory: + +```sh +$ docker-compose -f docker-compose-monitor.yml build +$ docker-compose -f docker-compose-monitor.yml up +``` + +and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, start BigchainDB as above, and refresh the page after a few seconds. + +If you're not interested in monitoring, don't worry: BigchainDB will function just fine without any monitoring setup. + +Feel free to modify the [custom Grafana dashboard](https://github.com/rhsimplex/grafana-bigchaindb-docker/blob/master/bigchaindb_dashboard.js) to your liking! \ No newline at end of file diff --git a/bigchaindb/block.py b/bigchaindb/block.py index c4e7e17a..11b6b7ed 100644 --- a/bigchaindb/block.py +++ b/bigchaindb/block.py @@ -12,8 +12,6 @@ from bigchaindb.monitor import Monitor logger = logging.getLogger(__name__) -# obviously the hostname should come from an environment variable or setting -# http://i.imgur.com/qciaOed.jpg c = Monitor() From 9b662ff1991cb5125fa199f7af6ce0259db18ca2 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 22 Feb 2016 16:56:36 +0100 Subject: [PATCH 15/22] Add test for monitor --- tests/test_monitor.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/test_monitor.py diff --git a/tests/test_monitor.py b/tests/test_monitor.py new file mode 100644 index 00000000..a138b9b1 --- /dev/null +++ b/tests/test_monitor.py @@ -0,0 +1,14 @@ +from platform import node + + +def test_monitor_class_init_defaults(): + import bigchaindb + from bigchaindb.monitor import Monitor + monitor = Monitor() + assert monitor + assert len(monitor._addr) == 2 + # TODO get value from config + # assert monitor._addr[0] == bigchaindb.config['statsd']['host'] + assert monitor._addr[0] == '127.0.0.1' + assert monitor._addr[1] == bigchaindb.config['statsd']['port'] + assert monitor._prefix == node() + '.' From 5bc591c6c40c7965b48cf261ae4da5199305c2b8 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 23 Feb 2016 16:14:27 +0100 Subject: [PATCH 16/22] reorganize documentation --- README.md | 17 ----------------- docs/source/index.rst | 1 + docs/source/monitoring.md | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 docs/source/monitoring.md diff --git a/README.md b/README.md index bd1a06e6..948b879c 100644 --- a/README.md +++ b/README.md @@ -79,20 +79,3 @@ $ bigchaindb show-config ``` $ py.test -v ``` - -#### Monitoring - -BigchainDB uses [statsd](https://github.com/etsy/statsd) for monitoring. To fully take advantage of this functionality requires some additional infrastructure: an agent to listen for metrics (e.g. [telegraf](https://github.com/influxdata/telegraf)), a time-series database (e.g. [influxdb](https://influxdata.com/time-series-platform/influxdb/), and a frontend to display analytics (e.g. [Grafana](http://grafana.org/)). - -For ease of use, we've provided a docker compose file that sets up all these services for testing. Simply run in the BigchainDB directory: - -```sh -$ docker-compose -f docker-compose-monitor.yml build -$ docker-compose -f docker-compose-monitor.yml up -``` - -and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, start BigchainDB as above, and refresh the page after a few seconds. - -If you're not interested in monitoring, don't worry: BigchainDB will function just fine without any monitoring setup. - -Feel free to modify the [custom Grafana dashboard](https://github.com/rhsimplex/grafana-bigchaindb-docker/blob/master/bigchaindb_dashboard.js) to your liking! \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index f8ef2a32..d15ff99b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -21,6 +21,7 @@ Table of Contents models json-serialization developer-interface + monitoring contributing faq release-notes diff --git a/docs/source/monitoring.md b/docs/source/monitoring.md new file mode 100644 index 00000000..7fee3620 --- /dev/null +++ b/docs/source/monitoring.md @@ -0,0 +1,16 @@ +# Monitoring + +BigchainDB uses [statsd](https://github.com/etsy/statsd) for monitoring. To fully take advantage of this functionality requires some additional infrastructure: an agent to listen for metrics (e.g. [telegraf](https://github.com/influxdata/telegraf)), a time-series database (e.g. [influxdb](https://influxdata.com/time-series-platform/influxdb/), and a frontend to display analytics (e.g. [Grafana](http://grafana.org/)). + +For ease of use, we've provided a docker compose file that sets up all these services for testing. Simply run in the BigchainDB directory: + +```text +$ docker-compose -f docker-compose-monitor.yml build +$ docker-compose -f docker-compose-monitor.yml up +``` + +and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, start BigchainDB as above, and refresh the page after a few seconds. + +If you're not interested in monitoring, don't worry: BigchainDB will function just fine without any monitoring setup. + +Feel free to modify the [custom Grafana dashboard](https://github.com/rhsimplex/grafana-bigchaindb-docker/blob/master/bigchaindb_dashboard.js) to your liking! \ No newline at end of file From be72aafd949d5734dda2ac03df38f53eb528ee6e Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 23 Feb 2016 17:08:07 +0100 Subject: [PATCH 17/22] documentation links --- docs/source/monitoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/monitoring.md b/docs/source/monitoring.md index 7fee3620..db794a62 100644 --- a/docs/source/monitoring.md +++ b/docs/source/monitoring.md @@ -9,7 +9,7 @@ $ docker-compose -f docker-compose-monitor.yml build $ docker-compose -f docker-compose-monitor.yml up ``` -and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, start BigchainDB as above, and refresh the page after a few seconds. +and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, [start BigchainDB](installing.html#run-bigchaindb) and refresh the page after a few seconds. If you're not interested in monitoring, don't worry: BigchainDB will function just fine without any monitoring setup. From 65d18211fb417b64190c70dc92105b7c83f9610d Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 23 Feb 2016 17:52:07 +0100 Subject: [PATCH 18/22] pseudo TTY --- docker-compose-monitor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose-monitor.yml b/docker-compose-monitor.yml index ea4faf54..ee7fe3a4 100644 --- a/docker-compose-monitor.yml +++ b/docker-compose-monitor.yml @@ -11,6 +11,7 @@ influxdb: grafana: image: rhsimplex/grafana-bigchaindb-docker + tty: true ports: - "3000:3000" links: From 39e260f88930b2f95a07f57f7e35314167b12ba9 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 23 Feb 2016 18:38:57 +0100 Subject: [PATCH 19/22] put queue gauge in correct place --- bigchaindb/block.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigchaindb/block.py b/bigchaindb/block.py index 11b6b7ed..74d969fd 100644 --- a/bigchaindb/block.py +++ b/bigchaindb/block.py @@ -37,7 +37,6 @@ class Block(object): b = Bigchain() while True: - c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=bigchaindb.config['statsd']['rate']) tx = self.q_new_transaction.get() # poison pill @@ -58,6 +57,7 @@ class Block(object): b = Bigchain() while True: + c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=bigchaindb.config['statsd']['rate']) tx = self.q_tx_to_validate.get() # poison pill From 8fd45048a48e5983c9ec20472a34cdbe196f7d27 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 24 Feb 2016 11:17:34 +0100 Subject: [PATCH 20/22] add loading text to monitoring documentation --- docs/source/monitoring.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/source/monitoring.md b/docs/source/monitoring.md index db794a62..436a42aa 100644 --- a/docs/source/monitoring.md +++ b/docs/source/monitoring.md @@ -1,6 +1,6 @@ # Monitoring -BigchainDB uses [statsd](https://github.com/etsy/statsd) for monitoring. To fully take advantage of this functionality requires some additional infrastructure: an agent to listen for metrics (e.g. [telegraf](https://github.com/influxdata/telegraf)), a time-series database (e.g. [influxdb](https://influxdata.com/time-series-platform/influxdb/), and a frontend to display analytics (e.g. [Grafana](http://grafana.org/)). +BigchainDB uses [statsd](https://github.com/etsy/statsd) for monitoring. To fully take advantage of this functionality requires some additional infrastructure: an agent to listen for metrics (e.g. [telegraf](https://github.com/influxdata/telegraf)), a time-series database (e.g. [influxdb](https://influxdata.com/time-series-platform/influxdb/)), and a frontend to display analytics (e.g. [Grafana](http://grafana.org/)). For ease of use, we've provided a docker compose file that sets up all these services for testing. Simply run in the BigchainDB directory: @@ -9,7 +9,13 @@ $ docker-compose -f docker-compose-monitor.yml build $ docker-compose -f docker-compose-monitor.yml up ``` -and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, [start BigchainDB](installing.html#run-bigchaindb) and refresh the page after a few seconds. +and point a browser tab to `http://localhost:3000/dashboard/script/bigchaindb_dashboard.js`. Login and password are `admin` by default. If BigchainDB is running and processing transactions, you should see analytics—if not, [start BigchainDB](installing.html#run-bigchaindb) and load some test transactions: + +```text +$ bigchaindb-benchmark load +``` + +and refresh the page after a few seconds. If you're not interested in monitoring, don't worry: BigchainDB will function just fine without any monitoring setup. From 43b67b83183c4873d846ee8a95fca6b79fc25b1f Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 24 Feb 2016 11:43:57 +0100 Subject: [PATCH 21/22] more readable syntax --- bigchaindb/monitor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bigchaindb/monitor.py b/bigchaindb/monitor.py index be5c27cd..9094fea3 100644 --- a/bigchaindb/monitor.py +++ b/bigchaindb/monitor.py @@ -21,10 +21,10 @@ class Monitor(statsd.StatsClient): kwargs = {} # set prefix, parameters from configuration file - if not kwargs.get('prefix'): + if 'prefix' not in kwargs: kwargs['prefix'] = '{hostname}.'.format(hostname=node()) - if not kwargs.get('host'): + if 'host' not in kwargs: kwargs['host'] = bigchaindb.config['statsd']['host'] - if not kwargs.get('port'): + if 'port' not in kwargs: kwargs['port'] = bigchaindb.config['statsd']['port'] super().__init__(*args, **kwargs) From 667c9a22239d1ba3b4c537ca4a31525ddc8ac5ab Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 24 Feb 2016 11:51:17 +0100 Subject: [PATCH 22/22] readability refactor --- bigchaindb/block.py | 4 ++-- bigchaindb/core.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bigchaindb/block.py b/bigchaindb/block.py index 74d969fd..0b021969 100644 --- a/bigchaindb/block.py +++ b/bigchaindb/block.py @@ -12,7 +12,7 @@ from bigchaindb.monitor import Monitor logger = logging.getLogger(__name__) -c = Monitor() +monitor = Monitor() class Block(object): @@ -57,7 +57,7 @@ class Block(object): b = Bigchain() while True: - c.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=bigchaindb.config['statsd']['rate']) + monitor.gauge('tx_queue_gauge', self.q_tx_to_validate.qsize(), rate=bigchaindb.config['statsd']['rate']) tx = self.q_tx_to_validate.get() # poison pill diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 8a962a1b..e4074112 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -12,7 +12,7 @@ from bigchaindb import exceptions from bigchaindb.crypto import hash_data, PublicKey, PrivateKey, generate_key_pair from bigchaindb.monitor import Monitor -c = Monitor() +monitor = Monitor() class GenesisBlockAlreadyExistsError(Exception): @@ -71,7 +71,7 @@ class Bigchain(object): def reconnect(self): return r.connect(host=self.host, port=self.port, db=self.dbname) - @c.timer('create_transaction', rate=bigchaindb.config['statsd']['rate']) + @monitor.timer('create_transaction', rate=bigchaindb.config['statsd']['rate']) def create_transaction(self, current_owner, new_owner, tx_input, operation, payload=None): """Create a new transaction @@ -181,7 +181,7 @@ class Bigchain(object): public_key = PublicKey(public_key_base58) return public_key.verify(self.serialize(data), signature) - @c.timer('write_transaction', rate=bigchaindb.config['statsd']['rate']) + @monitor.timer('write_transaction', rate=bigchaindb.config['statsd']['rate']) def write_transaction(self, signed_transaction): """Write the transaction to bigchain. @@ -318,7 +318,7 @@ class Bigchain(object): return owned - @c.timer('validate_transaction', rate=bigchaindb.config['statsd']['rate']) + @monitor.timer('validate_transaction', rate=bigchaindb.config['statsd']['rate']) def validate_transaction(self, transaction): """Validate a transaction. @@ -431,7 +431,7 @@ class Bigchain(object): return block - @c.timer('validate_block') + @monitor.timer('validate_block') # TODO: check that the votings structure is correctly constructed def validate_block(self, block): """Validate a block. @@ -476,7 +476,7 @@ class Bigchain(object): except Exception: return False - @c.timer('write_block') + @monitor.timer('write_block') def write_block(self, block, durability='soft'): """Write a block to bigchain.