add new nimbus-stats role for publishing nimbus fleet status

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-04-17 19:25:11 +02:00
parent 9ec6d1b4a9
commit 9fcbc6014f
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
10 changed files with 922 additions and 1 deletions

View File

@ -0,0 +1,2 @@
---
nimbus_stats_domain: nimbus-test-status.status.im

View File

@ -2,8 +2,9 @@
- name: Configure Nimbus master
hosts: nimbus-master
roles:
# - { role: origin-cert }
- { role: origin-cert }
# - { role: infra-role-eth2-testnet-site }
- { role: nimbus-stats, tags: nimbus-stats }
- { role: infra-role-beacon-node,
beacon_node_network: 'testnet0',
beacon_node_build_flavour: 'rlpx',

View File

@ -0,0 +1,7 @@
# Description
This role defined a simple service which lists the current state of the nodes in the fleet.
# Context
For more details see: https://github.com/status-im/infra-nimbus/issues/1

View File

@ -0,0 +1,13 @@
---
nimbus_stats_domain: ~
nimbus_stats_web_root: /var/www/nimbus
nimbus_stats_json_name: nimbus_stats.json
nimbus_stats_json: '{{ nimbus_stats_web_root }}/{{ nimbus_stats_json_name }}'
nimbus_stats_script: /usr/local/bin/collect_nimbus_stats.py
nimbus_stats_cron_script: /usr/local/bin/save_nimbus_stats.py
# necessary to query for ES lb
consul_base_url: 'http://localhost:8500/v1/catalog'
consul_service_name: elasticsearch-lb
consul_service_tag: status-logs-search
consul_query_url: '{{ consul_base_url }}/service/{{ consul_service_name }}?tag={{ consul_service_tag }}'

View File

@ -0,0 +1,116 @@
#!/usr/bin/env python3
import os
import json
import socket
import requests
from datetime import datetime
from optparse import OptionParser
from elasticsearch import Elasticsearch
ENV = os.environ
class ES:
def __init__(self, host, port, page_size):
self.page_size = page_size
self.es = Elasticsearch([host], port=port, timeout=30)
def make_query(self, fleet, program, message, after):
return {
'query': { 'bool': {
'must': [
{ 'match': { 'fleet': fleet } },
{ 'match': { 'program': program } },
{ 'match_phrase': { 'message': message } },
{ 'range': { '@timestamp': { 'gt': after } } },
],
}, },
'sort': [
{ '@timestamp': { 'order': 'desc' } },
],
}
def _index(self):
return
def get_logs(self, query):
return self.es.search(
index=self._index(),
body=query,
size=self.page_size
)
def get_first_for_node(logs):
data = {}
for log_obj in logs:
log = log_obj['_source']
host_obj = data.setdefault(log['logsource'], {})
prog_obj = host_obj.setdefault(log['program'], {})
prog_obj[log['message']] = json.loads(log['raw'])
return data
HELP_DESCRIPTION='This script collects latest log entries for provided messages from all nodes in a Nimbus fleet'
HELP_EXAMPLE='Example: collect -i logstash-2019.03.01 output.json'
DEFAULT_MESSAGES = [
'Fork chosen',
'Attestation received',
'Slot start',
]
def parse_opts():
parser = OptionParser(description=HELP_DESCRIPTION, epilog=HELP_EXAMPLE)
parser.add_option('-i', '--index', dest='es_index',
default='logstash-'+datetime.today().strftime('%Y.%m.%d'),
help='Patter for matching indices. (%default)')
parser.add_option('-H', '--host', dest='es_host', default='localhost',
help='ElasticSearch host. (%default)')
parser.add_option('-P', '--port', dest='es_port', default=9200,
help='ElasticSearch port. (%default)')
parser.add_option('-p', '--program', default='*beacon-node-*',
help='Program to query for. (%default)')
parser.add_option('-s', '--since', default='now-30m',
help='Period for which to query logs. (%default)')
parser.add_option('-S', '--page-size', default=10000,
help='Size of results page. (%default)')
parser.add_option('-m', '--messages', default=DEFAULT_MESSAGES,
help='Messages to query for. (%default)')
parser.add_option('-f', '--fleet', default='nimbus.test',
help='Fleet to query for. (%default)')
parser.add_option('-o', '--output-file',
help='File to which write the resulting JSON.')
return parser.parse_args()
def main():
(opts, args) = parse_opts()
es = ES(opts.es_host, opts.es_port, opts.page_size)
logs = []
#print('Querying: {}'.format(opts.fleet))
for msg in opts.messages:
#print(' - MSG: {}'.format(msg))
query = es.make_query(opts.fleet, opts.program, msg, opts.since)
rval = es.get_logs(query)
#print(' + Found: {}'.format(rval['hits']['total']))
logs.extend(rval['hits']['hits'])
data = get_first_for_node(logs)
# add metadata for easier debugging
output = {
'meta': {
'hostname': socket.gethostname(),
'timestamp': datetime.utcnow().isoformat(),
},
'data': data,
}
if opts.output_file:
with open(opts.output_file, 'w') as f:
json.dump(data, f, indent=4)
else:
print(json.dumps(data, indent=4))
if __name__ == '__main__':
main()

View File

@ -0,0 +1,674 @@
{
"master-01.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet0-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:52:15+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "AC705460",
"newHeadEpoch": 912,
"newHeadSlot": 14601
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:55:57+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 14609,
"beacon_block_root": "01E1CB8E",
"source_epoch": 195,
"target_root": "01E1CB8E",
"source_root": "C8D2A0BE",
"shard": 1,
"previous_crosslink_epoch": 501,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "b1615efd"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:20+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 14603,
"scheduledSlot": 14604,
"slot": 14604
}
},
"docker/beacon-node-rlpx-testnet1-2": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "DF799E87",
"newHeadEpoch": 0,
"newHeadSlot": 0
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-4": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "DF799E87",
"newHeadEpoch": 0,
"newHeadSlot": 0
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:52:12+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "1CDC4A78",
"newHeadEpoch": 1132,
"newHeadSlot": 18121
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:14+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18142,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 14,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ae9389dd"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:12+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-3": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "DF799E87",
"newHeadEpoch": 0,
"newHeadSlot": 0
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet0-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:58+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "0F3431DE",
"newHeadEpoch": 912,
"newHeadSlot": 14602
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:04+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 14603,
"scheduledSlot": 14604,
"slot": 14604
}
},
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "05C1AFB5",
"newHeadEpoch": 1132,
"newHeadSlot": 18125
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18142,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 14,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ae9389dd"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-09.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "BE458F0F",
"newHeadEpoch": 422,
"newHeadSlot": 6764
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:54:33+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18141,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 13,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "a1712fbe"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:54:22+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18147
}
},
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 16:04:44+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "53431DE8",
"newHeadEpoch": 1132,
"newHeadSlot": 18126
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 16:04:48+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18130,
"beacon_block_root": "3E9E73CD",
"source_epoch": 0,
"target_root": "3E9E73CD",
"source_root": "00000000",
"shard": 2,
"previous_crosslink_epoch": 278,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "8c8f8c31"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 16:04:44+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18134,
"scheduledSlot": 18135,
"slot": 18168
}
}
},
"node-05.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "3E9E73CD",
"newHeadEpoch": 1132,
"newHeadSlot": 18117
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18142,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 14,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ae9389dd"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "E3506242",
"newHeadEpoch": 269,
"newHeadSlot": 4304
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-07.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "5541D16E",
"newHeadEpoch": 1132,
"newHeadSlot": 18124
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "C2D268AB",
"newHeadEpoch": 1132,
"newHeadSlot": 18112
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18142,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 14,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ae9389dd"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-03.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "463ECDDD",
"newHeadEpoch": 422,
"newHeadSlot": 6765
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 16:17:33+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "EBC78610",
"newHeadEpoch": 562,
"newHeadSlot": 9001
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 16:17:17+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18193,
"beacon_block_root": "ED29F25E",
"source_epoch": 0,
"target_root": "ED29F25E",
"source_root": "00000000",
"shard": 1,
"previous_crosslink_epoch": 0,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ac2c6ced"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 16:17:33+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18193,
"scheduledSlot": 18194,
"slot": 18194
}
}
},
"node-08.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "2B28030D",
"newHeadEpoch": 1133,
"newHeadSlot": 18130
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:12+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18141,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 13,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "a1712fbe"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "813B9C76",
"newHeadEpoch": 1132,
"newHeadSlot": 18127
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:12+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18141,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 13,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "a1712fbe"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-02.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "3CB0BF7F",
"newHeadEpoch": 1133,
"newHeadSlot": 18137
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:12+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18141,
"beacon_block_root": "05C1AFB5",
"source_epoch": 0,
"target_root": "05C1AFB5",
"source_root": "00000000",
"shard": 13,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "b42d7df8"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
},
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "E00C2167",
"newHeadEpoch": 1131,
"newHeadSlot": 18106
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 16:17:33+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18193,
"beacon_block_root": "ED29F25E",
"source_epoch": 0,
"target_root": "ED29F25E",
"source_root": "00000000",
"shard": 1,
"previous_crosslink_epoch": 0,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "ac2c6ced"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-01.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-0": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:51:45+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "6722198F",
"newHeadEpoch": 1132,
"newHeadSlot": 18114
},
"Attestation received": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:16+00:00",
"msg": "Attestation received",
"tid": 1,
"attestationData": {
"slot": 18143,
"beacon_block_root": "1CDC4A78",
"source_epoch": 0,
"target_root": "1CDC4A78",
"source_root": "00000000",
"shard": 15,
"previous_crosslink_epoch": 277,
"previous_crosslink_data_root": "00000000",
"crosslink_data_root": "00000000"
},
"signature": "9701401a"
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:00+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18142,
"scheduledSlot": 18143,
"slot": 18143
}
}
},
"node-06.do-ams3.nimbus.test": {
"docker/beacon-node-rlpx-testnet1-1": {
"Fork chosen": {
"lvl": "INF",
"ts": "2019-04-17 15:52:11+00:00",
"msg": "Fork chosen",
"tid": 1,
"newHeadBlockRoot": "3ADBB6BA",
"newHeadEpoch": 1133,
"newHeadSlot": 18129
},
"Slot start": {
"lvl": "DBG",
"ts": "2019-04-17 15:52:13+00:00",
"msg": "Slot start",
"tid": 1,
"lastSlot": 18140,
"scheduledSlot": 18141,
"slot": 18143
}
}
}
}

View File

@ -0,0 +1,6 @@
---
- name: reload nginx
service: name=nginx state=reloaded
- name: Save iptables rules
shell: iptables-save > /etc/iptables/rules.v4

View File

@ -0,0 +1,75 @@
---
- name: Make sure python3 is installed
apt:
name:
- python3
- python3-pip
- name: Install ElasticSearch python module
pip:
name: elasticsearch
executable: pip3
- name: Find out the name of ES load balancer
uri:
url: '{{ consul_query_url }}'
register: es_lbs
- name: Install stat collecting script
copy:
src: collect.py
dest: '{{ nimbus_stats_script }}'
mode: 0755
register: nimbus_script
- name: Create the cron script
copy:
dest: '{{ nimbus_stats_cron_script }}'
mode: 0755
content: |
#!/usr/bin/env bash
exec {{ nimbus_stats_script }} \
-H {{ es_lbs.json[0].ServiceAddress }} \
-o {{ nimbus_stats_json }}
- name: Create www directory
file:
path: '{{ nimbus_stats_web_root }}'
state: directory
group: www-data
mode: 0755
- name: Run the script before Nginx configuration
command: '{{ nimbus_stats_cron_script }}'
when: nimbus_script.changed
- name: Create nginx config
template:
src: proxy.conf.j2
dest: '/etc/nginx/sites-available/{{ nimbus_stats_domain | mandatory }}.conf'
notify:
- reload nginx
- name: Enable site
file:
src: '/etc/nginx/sites-available/{{ nimbus_stats_domain | mandatory }}.conf'
dest: '/etc/nginx/sites-enabled/{{ nimbus_stats_domain | mandatory }}.conf'
state: link
- name: Enable HTTPS port
iptables:
comment: 'HTTPS'
chain: INPUT
jump: ACCEPT
source: '0.0.0.0/0'
protocol: tcp
destination_port: 443
notify:
- Save iptables rules
- name: Create a cron job for updating stats
cron:
name: Nimbus Fleet Stats
minute: '*/5'
user: root
job: '{{ nimbus_stats_cron_script }}'

View File

@ -0,0 +1,19 @@
server {
listen 80;
server_name {{ nimbus_stats_domain }};
return 302 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name {{ nimbus_stats_domain }};
ssl_certificate /certs/origin.crt;
ssl_certificate_key /certs/origin.key;
root {{ nimbus_stats_web_root }};
location = / {
try_files /{{ nimbus_stats_json_name }} =404;
}
}

View File

@ -52,6 +52,14 @@ module "nimbus-master" {
]
}
resource "cloudflare_record" "nimbus-test-stats" {
domain = "${var.public_domain}"
name = "nimbus-test-stats"
type = "A"
proxied = true
value = "${module.nimbus-master.public_ips[0]}"
}
resource "cloudflare_record" "serenity-testnets" {
domain = "${var.public_domain}"
name = "serenity-testnets"