Skip to content

feat: Replace prometheus with metricbeat by extending the elastic_stack role #628

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

Draft
wants to merge 9 commits into
base: v1.0-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ansible/roles/elastic_beats/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
hosts: ["unix:///var/run/docker.sock"]
period: 10s
enabled: true

- module: prometheus
period: 10s
hosts: ["{{ private_ip }}:{{ prometheus_port }}"]
metrics_path: "/metrics"
namespace: "drive_tenderdash"
output_conf:
elasticsearch:
hosts:
Expand Down
7 changes: 7 additions & 0 deletions ansible/roles/elastic_beats/vars/tenderdash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ platform_filebeat_inputs:
fields:
- from: "json.level"
to: "log.level"

metricbeat_modules:
- module: prometheus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be defined in configuration

period: 10s
hosts: ["{{ private_ip }}:{{ prometheus_port }}"]
metrics_path: "/metrics"
namespace: "drive_tenderdash"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "Parse round number from Tenderdash logs",
"processors": [
{
"grok": {
"field": "message",
"patterns": ["Processed proposal with .* for height: %{NUMBER:height}, round: %{NUMBER:round}"]
}
}
]
}
33 changes: 33 additions & 0 deletions ansible/roles/elastic_stack/files/watches/error_logs_watch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"search": {
"request": {
"indices": ["logs-*"],
"body": {
"query": {
"bool": {
"should": [
{ "match": { "log.level": "ERROR" }},
{ "match": { "log.level": "FATAL" }}
],
"minimum_should_match": 1
}
}
}
}
}
},
"actions": {
"log_alert": {
"logging": {
"text": "Alert triggered: {{ctx.payload}}"
}
}
}
}

41 changes: 41 additions & 0 deletions ansible/roles/elastic_stack/files/watches/high_round_watch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"search": {
"request": {
"indices": ["logs-*"],
"body": {
"query": {
"bool": {
"must": [
{
"match": {
"message": "Processed proposal"
}
},
{
"range": {
"round": {
"gt": 5
}
}
}
]
}
}
}
}
}
},
"actions": {
"log_alert": {
"logging": {
"text": "Alert triggered: {{ctx.payload}}"
}
}
}
}
46 changes: 46 additions & 0 deletions ansible/roles/elastic_stack/files/watches/no_logs_watch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"trigger": {
"schedule": {
"interval": "5m"
}
},
"input": {
"search": {
"request": {
"indices": ["logs-*"],
"body": {
"query": {
"bool": {
"must_not": {
"exists": {
"field": "message"
}
},
"filter": {
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"eq": 0
}
}
},
"actions": {
"log_alert": {
"logging": {
"text": "Alert triggered: {{ctx.payload}}"
}
}
}
}
27 changes: 27 additions & 0 deletions ansible/roles/elastic_stack/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,30 @@
ansible.builtin.import_tasks: configure_cluster.yml
run_once: true
delegate_to: '{{ play_hosts | first }}'


- name: Upload and apply Tenderdash log parsing pipeline
ansible.builtin.uri:
url: "{{ elasticsearch_url }}/logstash/_pipeline/process_proposal_pipeline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be defined

method: PUT
body: "{{ lookup('file', 'files/pipelines/process_proposal_pipeline.json') }}"
body_format: json
user: "{{ elastic_username }}"
password: "{{ elastic_password }}"
when: inventory_hostname in groups['elasticsearch']

- name: Create Elasticsearch Watches
ansible.builtin.uri:
url: "{{ elasticsearch_url }}/_watcher/watch/{{ item.name }}"
method: PUT
body: "{{ lookup('file', item.file) }}"
body_format: json
user: "{{ elastic_username }}"
password: "{{ elastic_password }}"
loop:
- { name: 'error_logs_watch', file: 'files/watches/error_logs_watch.json' }
- { name: 'high_round_watch', file: 'files/watches/high_round_watch.json' }
- { name: 'no_logs_watch', file: 'files/watches/no_logs_watch.json' }
loop_control:
label: "{{ item.name }}"
when: inventory_hostname in groups['elasticsearch']
1 change: 1 addition & 0 deletions ansible/roles/elastic_stack/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bundle_path: '{{ elastic_path }}/bundle'
certs_path: '{{ elastic_path }}/certificates'
data_path: '{{ elastic_path }}/data'
kibana_port: 5601
elasticsearch_url: "http://{{ hostvars[inventory_hostname].private_ip }}:9200"