Merge branch 'delete-consul-template' of kazu634/itamae into master

This commit is contained in:
Kazuhiro MUSASHI 2020-09-23 23:45:45 +09:00 committed by Gitea
commit 0583e8f160
11 changed files with 19 additions and 123 deletions

View File

@ -1,10 +0,0 @@
# -------------------------------------------
# Specifying the default settings:
# -------------------------------------------
node.reverse_merge!({
'consul-template' => {
'base_binary_url' => 'https://releases.hashicorp.com/consul-template/',
'arch' => node['kernel']['machine'] =~ /x86_64/ ? 'amd64' : '386',
'tmp_path' => '/tmp/itamae_tmp/consul-template.zip'
}
})

View File

@ -1,6 +0,0 @@
include_recipe './attributes.rb'
include_recipe './prerequisites.rb'
include_recipe './install.rb'
include_recipe './setup.rb'

View File

@ -1,52 +0,0 @@
# -------------------------------------------
# Calculating the latest `consul-template` version:
# -------------------------------------------
download_url = ''
tag_version = ''
begin
require 'net/http'
uri = URI.parse('https://releases.hashicorp.com/consul-template/')
Timeout.timeout(3) do
response = Net::HTTP.get_response(uri)
if response.body =~ /consul-template_(\d+\.\d+\.\d+)/
tag_version = $1
download_url = \
"#{node['consul-template']['base_binary_url']}#{tag_version}/consul-template_#{tag_version}_linux_#{node['consul-template']['arch']}.zip"
end
end
rescue
# Abort the chef client process:
raise 'Cannot connect to https://releases.hashicorp.com/consul-template/'
end
# -------------------------------------------
# Main Part
# -------------------------------------------
# バージョン確認して、アップデート必要かどうか確認
result = run_command("consul-template --version 2>&1 | grep #{tag_version}", error: false)
if result.exit_status != 0
# Download:
execute "wget #{download_url} -O #{node['consul-template']['tmp_path']}"
# Unzip:
execute "unzip -qo #{node['consul-template']['tmp_path']}" do
cwd '/opt/consul/bin/'
end
file '/opt/consul/bin/consul-template' do
owner 'root'
group 'root'
mode '755'
end
# Create link:
link '/usr/local/bin/consul-template' do
user 'root'
to '/opt/consul/bin/consul-template'
end
end

View File

@ -1,14 +0,0 @@
# Ensure that `unzip` and `dnsmasq` are available:
%w( unzip ).each do |p|
package p do
action :install
end
end
%w( /opt/consul/bin ).each do |d|
directory d do
owner 'root'
group 'root'
mode '755'
end
end

View File

@ -1,9 +0,0 @@
# `consul-template`-related paths:
%w( /etc/consul-template.d ).each do |d|
directory d do
owner 'root'
group 'root'
mode '755'
end
end

View File

@ -1,2 +0,0 @@
- targets:{{range nodes}}
- {{.Address}}:60000{{end}}

View File

@ -0,0 +1,6 @@
{
"service": {
"name": "node_exporter",
"port": 60000
}
}

View File

@ -44,14 +44,12 @@ scrape_configs:
- targets: ['localhost:9090'] - targets: ['localhost:9090']
- job_name: 'node' - job_name: 'node'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: /node_exporter/metrics metrics_path: /node_exporter/metrics
file_sd_configs: consul_sd_configs:
- files: - server: 'localhost:8500'
- '/etc/prometheus.d/targets/targets.yml' services:
- 'node_exporter'
alerting: alerting:
alertmanagers: alertmanagers:

View File

@ -1,8 +0,0 @@
[program:prometheus-targets]
command=/usr/local/bin/consul-template -consul-addr 127.0.0.1:8500 -template "/etc/consul-template.d/prometheus-targets.tmpl:/etc/prometheus.d/targets/targets.yml"
stdout_logfile=/var/log/supervisor/prometheus-targets.log
redirect_stderr=true
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=5
autorestart=true
stopsignal=INT

View File

@ -7,6 +7,15 @@ remote_file '/etc/supervisor/conf.d/node_exporter.conf' do
notifies :restart, 'service[supervisor]' notifies :restart, 'service[supervisor]'
end end
# Deploy `consul` config for `node_exporter`:
remote_file '/etc/consul.d/service-node_exporter.json' do
owner 'root'
group 'root'
mode '644'
notifies :restart, 'service[supervisor]'
end
service 'supervisor' do service 'supervisor' do
action :nothing action :nothing
end end

View File

@ -21,22 +21,6 @@ remote_file '/etc/prometheus.d/targets/targets.yml' do
mode '644' mode '644'
end end
# Deploy template file for `consul-template` generating `prometheus` target file:
remote_file '/etc/consul-template.d/prometheus-targets.tmpl' do
owner 'root'
group 'root'
mode '644'
end
# Deploy `supervisor` configuration for `prometheus-targets`, genarating `prometheus` targets:
remote_file '/etc/supervisor/conf.d/prometheus-targets.conf' do
owner 'root'
group 'root'
mode '644'
notifies :restart, 'service[supervisor]'
end
# Deploy `supervisor` configuration for `prometheus`: # Deploy `supervisor` configuration for `prometheus`:
remote_file '/etc/supervisor/conf.d/prometheus.conf' do remote_file '/etc/supervisor/conf.d/prometheus.conf' do
owner 'root' owner 'root'