diff --git a/data/common/common.yaml b/data/common/common.yaml --- a/data/common/common.yaml +++ b/data/common/common.yaml @@ -2866,6 +2866,8 @@ elasticsearch::config::path::data: /srv/elasticsearch elasticsearch::config::path::logs: /var/log/elasticsearch +elasticsearch::config::http::port: 9200 +elasticsearch::config::prometheus::indices: false elasticsearch::config: cluster.name: "%{alias('elasticsearch::config::cluster::name')}" @@ -2874,6 +2876,8 @@ cluster.initial_master_nodes: "%{alias('elasticsearch::config::cluster::initial_master_nodes')}" path.data: "%{alias('elasticsearch::config::path::data')}" path.logs: "%{alias('elasticsearch::config::path::logs')}" + http.port: "%{alias('elasticsearch::config::http::port')}" + prometheus.indices: "%{alias('elasticsearch::config::prometheus::indices')}" logstash::listen_network: "%{lookup('internal_network')}" logstash::elasticsearch::hosts: "%{alias('elasticsearch::hosts')}" @@ -4291,3 +4295,5 @@ ip: 192.168.100.128 opnsense::prometheus::port: 9100 opnsense::prometheus::metrics_path: /metrics + +prometheus::elasticsearch::exporter::version: "%{lookup('elastic::elk_version')}.0" diff --git a/data/deployments/staging/common.yaml b/data/deployments/staging/common.yaml --- a/data/deployments/staging/common.yaml +++ b/data/deployments/staging/common.yaml @@ -257,3 +257,4 @@ - search-esnode0 elasticsearch::jvm_options::heap_size: 8g +elasticsearch::config::prometheus::indices: true diff --git a/site-modules/profile/manifests/elasticsearch.pp b/site-modules/profile/manifests/elasticsearch.pp --- a/site-modules/profile/manifests/elasticsearch.pp +++ b/site-modules/profile/manifests/elasticsearch.pp @@ -11,6 +11,9 @@ $path_data = lookup('elasticsearch::config::path::data') $jvm_options = lookup('elasticsearch::jvm_options') + # for the prometheus exporter + $elasticsearch_http_port = lookup('elasticsearch::config::http::port') + $elasticsearch_cluster_name = lookup('elasticsearch::config::cluster::name') apt::pin { 'elasticsearch': packages => 'elasticsearch elasticsearch-oss', @@ -78,4 +81,13 @@ File[$path_data], ], } + + include profile::prometheus::elasticsearch + + profile::prometheus::export_scrape_config {"elasticsearch_${::fqdn}": + job => 'elasticsearch', + target => "${::fqdn}:${elasticsearch_http_port}", + scheme => 'http', + metrics_path => '/_prometheus/metrics', + } } diff --git a/site-modules/profile/manifests/prometheus/elasticsearch.pp b/site-modules/profile/manifests/prometheus/elasticsearch.pp new file mode 100644 --- /dev/null +++ b/site-modules/profile/manifests/prometheus/elasticsearch.pp @@ -0,0 +1,31 @@ +# Deployment of prometheus elasticsearch exporter + +class profile::prometheus::elasticsearch { + include profile::prometheus::base + + $version = lookup('prometheus::elasticsearch::exporter::version') + + $archive_url = "https://github.com/vvanholl/elasticsearch-prometheus-exporter/releases/download/${version}/prometheus-exporter-${version}.zip" + $archive_path = '/usr/share/elasticsearch/plugins/prometheus-exporter' + + file { $archive_path: + ensure => directory, + owner => 'elasticsearch', + group => 'elasticsearch', + mode => '0755', + require => Package['elasticsearch'] + } + -> archive { 'prometheus-elasticsearch-exporter': + path => "/tmp/prometheus-exporter-${version}.zip", + source => $archive_url, + extract => true, + extract_path => '/usr/share/elasticsearch/plugins/prometheus-exporter', + creates => "${archive_path}/plugin-descriptor.properties", + cleanup => true, + user => 'root', + group => 'root', + require => Package['elasticsearch'], + } + + Archive['prometheus-elasticsearch-exporter'] ~> Service['elasticsearch'] +}