- planet-notes
- planet-replication
- postgresql
+ - prometheus
+ - prometheus-server
- python
- rsyncd
- serverinfo
postgresql:
versions:
- 10
+ - name: prometheus
+ run_list:
+ - recipe[prometheus::default]
+ - name: prometheus-server
+ run_list:
+ - recipe[prometheus::server]
- name: python
run_list:
- recipe[python::default]
--- /dev/null
+# Prometheus Cookbook
+
+This cookbook configures prometheus, which we use for server monitoring at
+[prometheus.openstreetmap.org](https://prometheus.openstreetmap.org). The
+cookbook contains teo recipes:
+
+* default - installs and configures basic prometheus exporters on each machine
+* server - configures the central prometheus server
+
+Additionally two providers are defined - prometheus_exporter and
+prometheus_textfile_exporter, for configuring individual prometheus
+exporters.
--- /dev/null
+default[:prometheus][:exporters] = {}
--- /dev/null
+name "prometheus"
+maintainer "OpenStreetMap Administrators"
+maintainer_email "admins@openstreetmap.org"
+license "Apache-2.0"
+description "Installs and configures prometheus"
+
+version "1.0.0"
+supports "ubuntu"
+depends "networking"
--- /dev/null
+#
+# Cookbook:: prometheus
+# Recipe:: default
+#
+# Copyright:: 2020, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+prometheus_exporter "node" do
+ port 9100
+end
--- /dev/null
+#
+# Cookbook:: prometheus
+# Recipe:: server
+#
+# Copyright:: 2020, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+package "prometheus"
+
+clients = search(:node, "recipes:prometheus\\:\\:default").sort_by(&:name)
+
+template "/etc/prometheus/prometheus.yml" do
+ source "prometheus.yml.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables :clients => clients
+end
+
+service "prometheus" do
+ action [:enable, :start]
+ subscribes :reload, "template[/etc/prometheus/prometheus.yml]"
+end
--- /dev/null
+#
+# Cookbook:: prometheus
+# Resource:: prometheus_exporter
+#
+# Copyright:: 2020, OpenStreetMap Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+default_action :create
+
+property :exporter, :kind_of => String, :name_property => true
+property :port, :kind_of => Integer, :required => [:create]
+property :listen_switch, :kind_of => String, :default => "web.listen-address"
+property :package, :kind_of => String
+property :defaults, :kind_of => String
+property :service, :kind_of => String
+
+action :create do
+ package package_name
+
+ template defaults_name do
+ source "defaults.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables new_resource.to_hash.merge(:listen_address => listen_address)
+ end
+
+ service service_name do
+ action [:enable, :start]
+ subscribes :restart, "template[#{defaults_name}]"
+ end
+
+ node.default[:prometheus][:exporters][new_resource.exporter] = listen_address
+end
+
+action :delete do
+ service service_name do
+ action [:disable, :stop]
+ end
+
+ package package_name do
+ action :purge
+ end
+end
+
+action_class do
+ def package_name
+ new_resource.package || "prometheus-#{new_resource.exporter}-exporter"
+ end
+
+ def defaults_name
+ new_resource.defaults || "/etc/default/prometheus-#{new_resource.exporter}-exporter"
+ end
+
+ def listen_address
+ "#{node.internal_ipaddress}:#{new_resource.port}"
+ end
+
+ def service_name
+ new_resource.service || "prometheus-#{new_resource.exporter}-exporter"
+ end
+end
--- /dev/null
+# DO NOT EDIT - This file is being maintained by Chef
+
+ARGS="--<%= @listen_switch %>=<%= @listen_address %>"
--- /dev/null
+# DO NOT EDIT - This file is being maintained by Chef
+
+global:
+ scrape_interval: 15s
+ evaluation_interval: 15s
+
+scrape_configs:
+ - job_name: prometheus
+ scrape_interval: 5s
+ scrape_timeout: 5s
+ static_configs:
+ - targets:
+ - localhost:9090
+<% @clients.each do |client| -%>
+ - job_name: <%= client.name %>
+ static_configs:
+ - targets:
+<% client[:prometheus][:exporters].sort.each do |_,address| -%>
+ - <%= address %>
+<% end -%>
+<% end -%>
--- /dev/null
+require "serverspec"
+
+# Required by serverspec
+set :backend, :exec
+
+describe package("prometheus") do
+ it { should be_installed }
+end
+
+describe service("prometheus") do
+ it { should be_enabled }
+ it { should be_running }
+end
+
+describe port(9090) do
+ it { should be_listening.with("tcp6") }
+end
--- /dev/null
+require "serverspec"
+
+# Required by serverspec
+set :backend, :exec
+
+describe package("prometheus-node-exporter") do
+ it { should be_installed }
+end
+
+describe service("prometheus-node-exporter") do
+ it { should be_enabled }
+ it { should be_running }
+end
+
+describe port(9100) do
+ it { should be_listening.with("tcp6") }
+end