Add community prometheus cookbook
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
property :version, String, default: '0.32.0'
|
||||
property :binary, String, default: '/opt/prometheus/alertmanager'
|
||||
property :architecture, String, equal_to: %w(amd64 arm64), default: lazy {
|
||||
node['kernel']['machine'] == 'aarch64' ? 'arm64' : 'amd64'
|
||||
}
|
||||
property :binary_url, String, default: lazy { "https://github.com/prometheus/alertmanager/releases/download/v#{version}/alertmanager-#{version}.linux-#{architecture}.tar.gz" }
|
||||
property :checksum, String, default: lazy {
|
||||
{
|
||||
'amd64' => 'be72f50f6124ec53d944c0f100f8ec8108d969bade02fcc9f06a3068ff6c726f',
|
||||
'arm64' => '7812e12699694974f57ecc0b0400913c6c0d90190630d4332a7994a44982b1ed',
|
||||
}[architecture]
|
||||
}
|
||||
property :file_extension, String, default: ''
|
||||
property :source_repository, String, default: 'https://github.com/prometheus/alertmanager.git'
|
||||
property :source_revision, String, default: lazy { "v#{version}" }
|
||||
property :config_file, String, default: '/opt/prometheus/alertmanager.yml'
|
||||
property :storage_path, String, default: '/opt/prometheus/data'
|
||||
property :external_url, String, default: 'http://127.0.0.1/alert-manager/'
|
||||
property :log_level, String, default: 'debug'
|
||||
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
property :install_dir, String, default: '/opt/prometheus'
|
||||
property :log_dir, String, default: '/var/log/prometheus'
|
||||
property :user, String, default: 'prometheus'
|
||||
property :group, String, default: 'prometheus'
|
||||
property :use_existing_user, [true, false], default: false
|
||||
property :install_method, String, equal_to: %w(binary shell_binary source), default: 'binary'
|
||||
@@ -0,0 +1,71 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
property :version, String, default: '3.11.2'
|
||||
property :binary, String, default: '/opt/prometheus/prometheus'
|
||||
property :architecture, String, equal_to: %w(amd64 arm64), default: lazy {
|
||||
node['kernel']['machine'] == 'aarch64' ? 'arm64' : 'amd64'
|
||||
}
|
||||
property :binary_url, String, default: lazy { "https://github.com/prometheus/prometheus/releases/download/v#{version}/prometheus-#{version}.linux-#{architecture}.tar.gz" }
|
||||
property :checksum, String, default: lazy {
|
||||
{
|
||||
'amd64' => 'f643ea1ee90d109329302d27bddb1fb2e52655b1fa84e9e26f9a6f340da144a6',
|
||||
'arm64' => '4e40f115655a3021744137f49287846bc5a59e02835565748ff66b23e776a73d',
|
||||
}[architecture]
|
||||
}
|
||||
property :file_extension, String, default: ''
|
||||
property :source_repository, String, default: 'https://github.com/prometheus/prometheus.git'
|
||||
property :source_revision, String, default: lazy { "v#{version}" }
|
||||
property :config_file, String, default: '/opt/prometheus/prometheus.yml'
|
||||
property :storage_path, String, default: '/var/lib/prometheus'
|
||||
property :flags, Hash, default: lazy {
|
||||
legacy_flags = {
|
||||
'config.file' => config_file,
|
||||
'log.level' => 'info',
|
||||
'alertmanager.timeout' => '10s',
|
||||
'alertmanager.notification-queue-capacity' => 100,
|
||||
'alertmanager.url' => 'http://127.0.0.1/alert-manager/',
|
||||
'query.max-concurrency' => 20,
|
||||
'query.staleness-delta' => '5m',
|
||||
'query.timeout' => '2m',
|
||||
'storage.local.checkpoint-dirty-series-limit' => 5000,
|
||||
'storage.local.checkpoint-interval' => '5m',
|
||||
'storage.local.dirty' => false,
|
||||
'storage.local.index-cache-size.fingerprint-to-metric' => 10_485_760,
|
||||
'storage.local.index-cache-size.fingerprint-to-timerange' => 5_242_880,
|
||||
'storage.local.index-cache-size.label-name-to-label-values' => 10_485_760,
|
||||
'storage.local.index-cache-size.label-pair-to-fingerprints' => 20_971_520,
|
||||
'storage.local.memory-chunks' => 1_048_576,
|
||||
'storage.local.path' => storage_path,
|
||||
'storage.local.pedantic-checks' => false,
|
||||
'storage.local.retention' => '360h0m0s',
|
||||
'storage.local.series-sync-strategy' => 'adaptive',
|
||||
'storage.remote.influxdb-url' => '',
|
||||
'storage.remote.influxdb.database' => 'prometheus',
|
||||
'storage.remote.influxdb.retention-policy' => 'default',
|
||||
'storage.remote.opentsdb-url' => '',
|
||||
'storage.remote.timeout' => '30s',
|
||||
'web.console.libraries' => 'console_libraries',
|
||||
'web.console.templates' => 'consoles',
|
||||
'web.enable-remote-shutdown' => false,
|
||||
'web.external-url' => '',
|
||||
'web.listen-address' => ':9090',
|
||||
'web.telemetry-path' => '/metrics',
|
||||
'web.user-assets' => '',
|
||||
}
|
||||
legacy_flags['web.use-local-assets'] = false if Gem::Version.new(version) <= Gem::Version.new('0.16.2')
|
||||
legacy_flags
|
||||
}
|
||||
property :cli_options, Hash, default: lazy {
|
||||
{
|
||||
'config.file' => config_file,
|
||||
'log.level' => 'info',
|
||||
'query.max-concurrency' => 20,
|
||||
'query.lookback-delta' => '5m',
|
||||
'query.timeout' => '2m',
|
||||
'storage.tsdb.path' => storage_path,
|
||||
'storage.tsdb.retention.time' => '15d',
|
||||
'web.listen-address' => ':9090',
|
||||
'web.telemetry-path' => '/metrics',
|
||||
}
|
||||
}
|
||||
property :cli_flags, Array, default: ['web.enable-lifecycle']
|
||||
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_alertmanager_config
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_alertmanager'
|
||||
|
||||
property :template_cookbook, String, default: 'prometheus'
|
||||
property :template_source, String, default: 'alertmanager.yml.erb'
|
||||
property :notification_config, Hash, default: {}
|
||||
|
||||
default_action :create
|
||||
|
||||
action :create do
|
||||
template new_resource.config_file do
|
||||
cookbook new_resource.template_cookbook
|
||||
source new_resource.template_source
|
||||
mode '0644'
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
variables(notification_config: new_resource.notification_config)
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
file new_resource.config_file do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,89 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_alertmanager_install
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_alertmanager'
|
||||
|
||||
default_action :install
|
||||
|
||||
action_class do
|
||||
include PrometheusCookbook::Helpers
|
||||
end
|
||||
|
||||
action :install do
|
||||
user new_resource.user do
|
||||
system true
|
||||
shell '/bin/false'
|
||||
home new_resource.install_dir
|
||||
not_if { new_resource.use_existing_user || new_resource.user == 'root' }
|
||||
end
|
||||
|
||||
directory new_resource.install_dir do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
directory new_resource.log_dir do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
directory new_resource.storage_path do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
case new_resource.install_method
|
||||
when 'binary'
|
||||
package %w(tar bzip2)
|
||||
|
||||
ark install_dir_name(new_resource.install_dir) do
|
||||
url new_resource.binary_url
|
||||
checksum new_resource.checksum
|
||||
version new_resource.version
|
||||
prefix_root Chef::Config['file_cache_path']
|
||||
path install_dir_parent(new_resource.install_dir)
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
extension new_resource.file_extension unless new_resource.file_extension.empty?
|
||||
action :put
|
||||
end
|
||||
when 'shell_binary'
|
||||
package %w(tar bzip2)
|
||||
|
||||
remote_file "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}.tar.gz" do
|
||||
source new_resource.binary_url
|
||||
checksum new_resource.checksum
|
||||
action :create
|
||||
notifies :run, 'execute[install_alertmanager_archive]', :immediately
|
||||
end
|
||||
|
||||
execute 'install_alertmanager_archive' do
|
||||
command "tar -xzf #{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}.tar.gz -C #{new_resource.install_dir} --strip-components=1"
|
||||
action :nothing
|
||||
end
|
||||
when 'source'
|
||||
build_essential 'install compilation tools'
|
||||
|
||||
package %w(curl git-core mercurial gzip sed)
|
||||
|
||||
git "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}" do
|
||||
repository new_resource.source_repository
|
||||
revision new_resource.source_revision
|
||||
action :checkout
|
||||
end
|
||||
|
||||
bash 'compile_alertmanager_source' do
|
||||
cwd "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}"
|
||||
code "make && mv alertmanager #{new_resource.install_dir}"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,56 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_alertmanager_service
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_alertmanager'
|
||||
|
||||
default_action :create
|
||||
|
||||
action_class do
|
||||
include PrometheusCookbook::Helpers
|
||||
end
|
||||
|
||||
action :create do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
content alertmanager_unit_content(new_resource)
|
||||
action [:create, :enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :enable do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action :enable
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action :start
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
systemd_unit 'alertmanager.service' do
|
||||
action [:stop, :disable, :delete]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_config
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_prometheus'
|
||||
|
||||
property :template_cookbook, String, default: 'prometheus'
|
||||
property :template_source, String, default: 'prometheus.yml.erb'
|
||||
property :rule_filenames, [Array, nil], default: nil
|
||||
property :global_config, Hash, default: {
|
||||
'scrape_interval' => '60s',
|
||||
'evaluation_interval' => '60s',
|
||||
}
|
||||
property :allow_external_config, [true, false], default: false
|
||||
|
||||
default_action :create
|
||||
|
||||
action :create do
|
||||
config_resource = new_resource
|
||||
|
||||
with_run_context :root do
|
||||
template config_resource.config_file do
|
||||
cookbook config_resource.template_cookbook
|
||||
source config_resource.template_source
|
||||
mode '0644'
|
||||
owner config_resource.user
|
||||
group config_resource.group
|
||||
variables(
|
||||
global_config: config_resource.global_config,
|
||||
jobs: {},
|
||||
rule_filenames: config_resource.rule_filenames
|
||||
)
|
||||
not_if { config_resource.allow_external_config }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
file new_resource.config_file do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,98 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_install
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_prometheus'
|
||||
|
||||
default_action :install
|
||||
|
||||
action_class do
|
||||
include PrometheusCookbook::Helpers
|
||||
end
|
||||
|
||||
action :install do
|
||||
user new_resource.user do
|
||||
system true
|
||||
shell '/bin/false'
|
||||
home new_resource.install_dir
|
||||
not_if { new_resource.use_existing_user || new_resource.user == 'root' }
|
||||
end
|
||||
|
||||
directory new_resource.install_dir do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
directory new_resource.log_dir do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
directory new_resource.storage_path do
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
|
||||
case new_resource.install_method
|
||||
when 'binary'
|
||||
package %w(tar bzip2)
|
||||
|
||||
ark install_dir_name(new_resource.install_dir) do
|
||||
url new_resource.binary_url
|
||||
checksum new_resource.checksum
|
||||
version new_resource.version
|
||||
prefix_root Chef::Config['file_cache_path']
|
||||
path install_dir_parent(new_resource.install_dir)
|
||||
owner new_resource.user
|
||||
group new_resource.group
|
||||
extension new_resource.file_extension unless new_resource.file_extension.empty?
|
||||
action :put
|
||||
end
|
||||
when 'shell_binary'
|
||||
package %w(tar bzip2)
|
||||
|
||||
remote_file "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}.tar.gz" do
|
||||
source new_resource.binary_url
|
||||
checksum new_resource.checksum
|
||||
action :create
|
||||
notifies :run, 'execute[install_prometheus_archive]', :immediately
|
||||
end
|
||||
|
||||
execute 'install_prometheus_archive' do
|
||||
command "tar -xzf #{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}.tar.gz -C #{new_resource.install_dir} --strip-components=1"
|
||||
action :nothing
|
||||
end
|
||||
when 'source'
|
||||
build_essential 'install compilation tools'
|
||||
|
||||
package %w(curl git-core mercurial gzip sed)
|
||||
|
||||
git "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}" do
|
||||
repository new_resource.source_repository
|
||||
revision new_resource.source_revision
|
||||
action :checkout
|
||||
end
|
||||
|
||||
bash 'compile_prometheus_source' do
|
||||
cwd "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}"
|
||||
environment(
|
||||
'PATH' => "/usr/local/go/bin:#{ENV.fetch('PATH', nil)}",
|
||||
'GOPATH' => '/opt/go:/opt/go/src/github.com/prometheus/promu/vendor'
|
||||
)
|
||||
code <<~EOH
|
||||
make build
|
||||
mv prometheus #{new_resource.install_dir}
|
||||
cp -R console_libraries #{new_resource.install_dir}
|
||||
cp -R consoles #{new_resource.install_dir}
|
||||
EOH
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_job
|
||||
unified_mode true
|
||||
|
||||
property :scrape_interval, String
|
||||
property :scrape_timeout, String
|
||||
property :labels, Hash
|
||||
property :target, [Array, String], required: true
|
||||
property :metrics_path, String, default: '/metrics'
|
||||
property :config_file, String, default: '/opt/prometheus/prometheus.yml'
|
||||
property :allow_external_config, [true, false], default: false
|
||||
|
||||
default_action :create
|
||||
|
||||
action :create do
|
||||
job_resource = new_resource
|
||||
|
||||
with_run_context :root do
|
||||
edit_resource(:template, job_resource.config_file) do
|
||||
variables[:jobs] ||= {}
|
||||
variables[:jobs][job_resource.name] ||= {}
|
||||
variables[:jobs][job_resource.name]['scrape_interval'] = job_resource.scrape_interval
|
||||
variables[:jobs][job_resource.name]['scrape_timeout'] = job_resource.scrape_timeout
|
||||
variables[:jobs][job_resource.name]['target'] = job_resource.target
|
||||
variables[:jobs][job_resource.name]['metrics_path'] = job_resource.metrics_path
|
||||
variables[:jobs][job_resource.name]['labels'] = job_resource.labels
|
||||
|
||||
action :nothing
|
||||
delayed_action :create
|
||||
|
||||
not_if { job_resource.allow_external_config }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
file new_resource.config_file do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,56 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :prometheus_service
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_common'
|
||||
use '_partial/_prometheus'
|
||||
|
||||
default_action :create
|
||||
|
||||
action_class do
|
||||
include PrometheusCookbook::Helpers
|
||||
end
|
||||
|
||||
action :create do
|
||||
systemd_unit 'prometheus.service' do
|
||||
content prometheus_unit_content(new_resource)
|
||||
action [:create, :enable, :start]
|
||||
end
|
||||
end
|
||||
|
||||
action :enable do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action :enable
|
||||
end
|
||||
end
|
||||
|
||||
action :start do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action :start
|
||||
end
|
||||
end
|
||||
|
||||
action :restart do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action :restart
|
||||
end
|
||||
end
|
||||
|
||||
action :reload do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action :reload
|
||||
end
|
||||
end
|
||||
|
||||
action :stop do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action [:stop, :disable]
|
||||
end
|
||||
end
|
||||
|
||||
action :delete do
|
||||
systemd_unit 'prometheus.service' do
|
||||
action [:stop, :disable, :delete]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user