2 # Cookbook:: prometheus
3 # Resource:: prometheus_collector
5 # Copyright:: 2020, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 default_action :create
22 property :collector, :kind_of => String, :name_property => true
23 property :interval, :kind_of => [Integer, String], :required => [:create]
24 property :options, :kind_of => [String, Array]
25 property :environment, :kind_of => Hash, :default => {}
28 systemd_service service_name do
29 description "Prometheus #{new_resource.collector} collector"
31 environment new_resource.environment
32 standard_output "file:/var/lib/prometheus/node-exporter/#{new_resource.collector}.new"
33 standard_error "journal"
34 exec_start "#{executable_path} #{executable_options}"
35 exec_start_post "/bin/mv /var/lib/prometheus/node-exporter/#{new_resource.collector}.new /var/lib/prometheus/node-exporter/#{new_resource.collector}.prom"
37 protect_system "strict"
39 read_write_paths "/var/lib/prometheus/node-exporter"
40 no_new_privileges true
43 systemd_timer service_name do
44 description "Prometheus #{new_resource.collector} collector"
46 on_unit_active_sec new_resource.interval
49 service "#{service_name}.timer" do
50 action [:enable, :start]
51 subscribes :restart, "systemd_timer[#{service_name}]"
56 service "#{service_name}.timer" do
57 action [:disable, :stop]
60 systemd_timer service_name do
64 systemd_service service_name do
71 "prometheus-#{new_resource.collector}-collector"
75 "/opt/prometheus/collectors/#{new_resource.collector}/#{new_resource.collector}_collector"
78 def executable_options
79 Array(new_resource.options).join(" ")