20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'modules/prometheus/manifests/node_file_count.pp', line 20
define prometheus::node_file_count (
Array[String] $paths,
Stdlib::AbsolutePath $outfile,
String $metric = 'node_files_total',
Wmflib::Ensure $ensure = 'present',
) {
if !($outfile =~ /\.prom$/) {
fail("\$outfile should end with '.prom' but is [${outfile}]")
}
if !($metric =~ /^node_[a-z_]*_total$/) {
fail("\$metric should begin with 'node_' then lowercase chars or _ and end with '_total' but is [${metric}]")
}
ensure_packages(['python3-prometheus-client'])
if (!defined(File['/usr/local/bin/prometheus-file-count'])) {
file { '/usr/local/bin/prometheus-file-count':
ensure => $ensure,
mode => '0555',
owner => 'root',
group => 'root',
source => 'puppet:///modules/prometheus/usr/local/bin/prometheus-file-count.py',
}
}
# Collect every minute
$safe_title = regsubst($title, ' ', '_', 'G')
systemd::timer::job { $safe_title:
ensure => $ensure,
description => 'Regular job to collect file count metrics',
user => 'root',
command => inline_template("/usr/local/bin/prometheus-file-count --outfile <%= @outfile %> --metric <%= @metric %> <%= @paths.map{ | i | '\"' + i + '\"' }.join(' ') %>"),
interval => {'start' => 'OnCalendar', 'interval' => 'minutely'},
require => Class['prometheus::node_exporter'],
}
}
|