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