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.
22 default_action :create
24 property :collector, :kind_of => String, :name_property => true
25 property :interval, :kind_of => [Integer, String], :required => [:create]
26 property :user, :kind_of => String
27 property :options, :kind_of => [String, Array]
28 property :environment, :kind_of => Hash, :default => {}
29 property :proc_subset, String
30 property :capability_bounding_set, [String, Array]
31 property :private_devices, [true, false]
32 property :private_users, [true, false]
33 property :protect_clock, [true, false]
34 property :protect_kernel_modules, [true, false]
37 systemd_service service_name do
38 description "Prometheus #{new_resource.collector} collector"
39 user new_resource.user
40 dynamic_user new_resource.user.nil?
42 environment new_resource.environment
43 standard_output "file:/var/lib/prometheus/node-exporter/#{new_resource.collector}.new"
44 standard_error "journal"
45 exec_start "#{executable_path} #{executable_options}"
46 exec_start_post "/bin/mv /var/lib/prometheus/node-exporter/#{new_resource.collector}.new /var/lib/prometheus/node-exporter/#{new_resource.collector}.prom"
48 proc_subset new_resource.proc_subset if new_resource.property_is_set?(:proc_subset)
49 capability_bounding_set new_resource.capability_bounding_set if new_resource.property_is_set?(:capability_bounding_set)
50 private_devices new_resource.private_devices if new_resource.property_is_set?(:private_devices)
51 private_users new_resource.private_users if new_resource.property_is_set?(:private_users)
52 protect_clock new_resource.protect_clock if new_resource.property_is_set?(:protect_clock)
53 protect_kernel_modules new_resource.protect_kernel_modules if new_resource.property_is_set?(:protect_kernel_modules)
54 read_write_paths ["/var/lib/prometheus/node-exporter", "/var/lock", "/var/log"]
57 systemd_timer service_name do
58 description "Prometheus #{new_resource.collector} collector"
60 on_unit_active_sec new_resource.interval
63 service "#{service_name}.timer" do
64 action [:enable, :start]
65 subscribes :restart, "systemd_timer[#{service_name}]"
70 service "#{service_name}.timer" do
71 action [:disable, :stop]
74 systemd_timer service_name do
78 systemd_service service_name do
82 file "/var/lib/prometheus/node-exporter/#{new_resource.collector}.prom" do
89 "prometheus-#{new_resource.collector}-collector"
93 "/opt/prometheus-exporters/collectors/#{new_resource.collector}/#{new_resource.collector}_collector"
96 def executable_options
97 Array(new_resource.options).join(" ")