Compare commits

...

50 Commits

Author SHA1 Message Date
ec52f8f388 OP#470 add dir 2026-02-27 15:18:08 +01:00
f1cb23c414 OP#459 update Readme 2026-02-24 18:31:05 +01:00
a8ba414237 OP#459 update Readme 2026-02-24 18:28:51 +01:00
b091635ce5 OP#414 update gitea url 2026-02-06 16:09:24 +01:00
066ba16121 OP#375 remove .vscode 2026-01-28 13:50:54 +01:00
12ww1160
bbc97f212e add button 2025-12-14 16:44:07 +01:00
12ww1160
79ee62961c add TOC 2025-12-14 16:42:33 +01:00
12ww1160
bf05f7165f add TOC 2025-12-14 16:38:05 +01:00
12ww1160
f307158ef2 OP#195 update Readme 2025-12-13 15:59:24 +01:00
12ww1160
2f5fbbcde8 OP#195 update Readme 2025-12-13 15:55:35 +01:00
12ww1160
9636aea81a OP#195 add sonar badge 2025-12-13 13:33:03 +01:00
12ww1160
0ff1f053e6 OP#195 change class names 2025-12-13 13:25:01 +01:00
12ww1160
92285116d4 OP#195 new module confdrdoid_prometheus 2025-12-13 13:22:02 +01:00
12ww1160
468f484544 update pruning script 2025-12-07 18:03:52 +01:00
12ww1160
c44902c7c3 add variable to prune.env 2025-12-07 17:49:14 +01:00
12ww1160
2cfa007c17 add remote read 2025-12-07 16:18:47 +01:00
12ww1160
89a6b52ed3 fix the remote url to reflect the new name 2025-12-04 15:51:21 +01:00
12ww1160
61b5310305 OP#189 add the services 2025-12-04 14:45:26 +01:00
12ww1160
fd566a0af8 OP#189 add the services 2025-12-04 14:30:24 +01:00
12ww1160
340306b15f OP#189 add the services 2025-12-04 14:22:33 +01:00
12ww1160
639d4b0099 OP#189 add the services 2025-12-04 14:16:06 +01:00
12ww1160
dcbad998f4 OP#189 update readme 2025-12-04 13:37:23 +01:00
12ww1160
eb9473f2d4 OP#189 update readme 2025-12-04 13:35:53 +01:00
12ww1160
c4a685101e OP#188 add env file 2025-12-04 13:23:59 +01:00
12ww1160
7f1e0daded OP#188 add env file 2025-12-04 13:11:43 +01:00
12ww1160
11eeeb4c2b OP#188 fix variable 2025-12-04 12:28:19 +01:00
12ww1160
3b20a4a566 OP#188 create file 2025-12-04 12:15:20 +01:00
12ww1160
de0a84737e OP#188 create proper boolean 2025-12-04 12:01:57 +01:00
12ww1160
747b0f22d1 OP#188 create directory 2025-12-04 11:59:41 +01:00
12ww1160
933d97d038 OP#186 remove local remote write 2025-12-04 10:54:47 +01:00
12ww1160
aea5d0188c OP#186 remove local remote write 2025-12-04 10:53:19 +01:00
12ww1160
b29fdba120 OP#186 remove local remote write 2025-12-04 10:49:37 +01:00
12ww1160
2a937468a2 OP#188 fix the config 2025-12-03 16:57:53 +01:00
12ww1160
dbea18d23a OP#188 comment out the service options as they do not seem to work, Prometheus as service does not respond then 2025-12-03 16:45:31 +01:00
12ww1160
40d2158e42 OP#188 comment out the service options as they do not seem to work, Prometheus as service does not respond then 2025-12-03 16:45:17 +01:00
12ww1160
f0f5de8ffe OP#188 comment out the service options as they do not seem to work, Prometheus as service does not respond then 2025-12-03 16:39:02 +01:00
12ww1160
d4a81ae31f OP#188 remove Jenksinfile from public mirror 2025-12-03 16:03:36 +01:00
12ww1160
c1e40ea302 OP#188 remove Jenksinfile from public mirror 2025-12-03 15:59:00 +01:00
12ww1160
d92a12cea5 OP#188 remove Jenksinfile from public mirror 2025-12-03 15:57:10 +01:00
12ww1160
11969d7dbe OP#188 remove Jenksinfile from public mirror 2025-12-03 15:47:28 +01:00
12ww1160
b760db13d8 OP#188 update Jenksinfile for correct flow 2025-12-03 15:41:19 +01:00
12ww1160
eca339f345 OP#188 add Readme part 2025-12-03 15:35:03 +01:00
12ww1160
c4480a81b8 OP#188 add Readme partl 2025-12-03 15:34:46 +01:00
12ww1160
5967b2b3fc OP#188 add option to allow external remote write in gerenal 2025-12-03 15:29:56 +01:00
12ww1160
b4c889aa10 OP#180 update README and jenkinsfile for remote mirror 2025-12-03 12:51:48 +01:00
12ww1160
8a03b183cc OP#180 add more tsdb options 2025-12-03 12:44:13 +01:00
12ww1160
c68146d3b6 OP#179 add more tsdb options 2025-12-03 12:37:30 +01:00
12ww1160
1c95467582 OP#179 add service control units for memory consumption 2025-12-03 12:24:44 +01:00
Arne Teuke
c1f8eb8adf add setting for WAL segment size - https://gitlab.confdroid.com/internal/confdroid_management/-/issues/260 2025-10-18 17:36:20 +02:00
Arne Teuke
ea7d764664 add setting for WAL segment size - https://gitlab.confdroid.com/internal/confdroid_management/-/issues/260 2025-10-18 17:33:33 +02:00
20 changed files with 448 additions and 94 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
Gemfile.lock Gemfile.lock
FileList FileList
.scannerwork .scannerwork
.vscode

2
.puppet-lint.rc Normal file
View File

@@ -0,0 +1,2 @@
--no-variable_scope-check
--no-top_scope_facts

View File

@@ -1,9 +0,0 @@
{
"cSpell.words": [
"changeme",
"reqpackage",
"rpms",
"sslcacert",
"sslverify"
]
}

35
Jenkinsfile vendored
View File

@@ -69,7 +69,7 @@ pipeline {
withCredentials([string(credentialsId: 'sonar-token', variable: 'SONAR_TOKEN')]) { withCredentials([string(credentialsId: 'sonar-token', variable: 'SONAR_TOKEN')]) {
sh ''' sh '''
/opt/sonar-scanner/bin/sonar-scanner \ /opt/sonar-scanner/bin/sonar-scanner \
-Dsonar.projectKey=prometheus_cd \ -Dsonar.projectKey=confdroid_prometheus \
-Dsonar.sources=. \ -Dsonar.sources=. \
-Dsonar.host.url=https://sonarqube.confdroid.com \ -Dsonar.host.url=https://sonarqube.confdroid.com \
-Dsonar.token=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN
@@ -90,16 +90,37 @@ pipeline {
sh ''' sh '''
git config user.name "Jenkins Server" git config user.name "Jenkins Server"
git config user.email jenkins@confdroid.com git config user.email jenkins@confdroid.com
git rm -r --cached .vscode || echo "No .vscode to remove from git"
git add -A && git commit -am "Recommit for updates in build $BUILD_NUMBER" || echo "No changes to commit" git add -A && git commit -am "Recommit for updates in build $BUILD_NUMBER" || echo "No changes to commit"
git push -o merge_request.create \ git push origin HEAD:master
-o merge_request.target=master \ '''
-o merge_request.title="Auto-merge for build $BUILD_NUMBER" \ }
-o merge_request.description="Automated changes from Jenkins build $BUILD_NUMBER" \ }
-o merge_request.merge_when_pipeline_succeeds=true \ }
origin jenkins-build-$BUILD_NUMBER
stage('Mirror to Gitea') {
steps {
withCredentials([usernamePassword(
credentialsId: 'Jenkins-gitea',
usernameVariable: 'GITEA_USER',
passwordVariable: 'GITEA_TOKEN')]) {
script {
// Checkout from GitLab (already done implicitly)
sh '''
git checkout master
git pull origin master
git branch -D development
git branch -D jenkins-build-$BUILD_NUMBER
git rm -f Jenkinsfile
git rm -r --cached .vscode || echo "No .vscode to remove from git"
git commit --amend --no-edit --allow-empty
git remote add master https://sourcecode.confdroid.com/confdroid/confdroid_prometheus.git
git -c credential.helper="!f() { echo username=${GITEA_USER}; echo password=${GITEA_TOKEN}; }; f" \
push master --mirror
''' '''
} }
} }
} }
} }
} }
}

View File

@@ -1,20 +1,37 @@
# Readme # Readme
[![Build Status](https://jenkins.confdroid.com/buildStatus/icon?job=prometheus_cd)](https://jenkins.confdroid.com/job/prometheus_cd/) [![Build Status](https://jenkins.confdroid.com/buildStatus/icon?job=confdroid_prometheus)](https://jenkins.confdroid.com/job/confdroid_prometheus/)
[![Security Issues](https://sonarqube.confdroid.com/api/project_badges/measure?project=confdroid_prometheus&metric=software_quality_security_issues&token=sqb_3d09bf2c3c7ef13bd7ba77aceb330a82fbb36cdf)](https://sonarqube.confdroid.com/dashboard?id=confdroid_prometheus)
- [Readme](#readme)
- [Synopsis](#synopsis)
- [WARNING](#warning)
- [Features](#features)
- [Puppet Documentation](#puppet-documentation)
- [Dependencies](#dependencies)
- [Deployment](#deployment)
- [SELINUX](#selinux)
- [Known Problems](#known-problems)
- [Support](#support)
- [Tests](#tests)
- [Contact Us](#contact-us)
- [Feedback](#feedback)
- [Disclaimer](#disclaimer)
[[_TOC_]]
## Synopsis ## Synopsis
Prometheus is an open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach. Prometheus is an open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.
`prometheus_cd` is a Puppet module to automate installation and configuration of prometheus and node exporter. `confdroid_prometheus` is a Puppet module to automate installation and configuration of prometheus, optionally node exporter, tsdb pruning and more.
This module supports either managing prometheus or node_exporter or both. You need to set the parameters `$manage_prometheus`and / or `$manage_node_exporter`to true ( false by default) This module supports either managing prometheus or node_exporter or both. You need to set the parameters `$manage_prometheus`and / or `$manage_node_exporter`to true ( false by default)
## WARNING ## WARNING
***Attention: Never use this puppet module on systems which have been previously configured manually. It is impossible to predict how and what would have been configured, hence previous configurations outside the scope of this module may be overwritten! Automated configurations require a test environment to verify that the module suits the purpose intended by the user, as well as tune the parameters, before deploying into live production*** ***Attention: Never use this puppet module on systems which have been previously configured manually. It is impossible to predict how and what would have been configured, hence previous configurations outside the scope of this module may be overwritten! Automated configurations require a test environment to verify that the module suits the purpose intended by the user, as well as tune the parameters, before deploying into live production***
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/grizzly_coda)
## Features ## Features
INSTALLATION INSTALLATION
@@ -31,11 +48,22 @@ CONFIGURATION
Configurable options: Configurable options:
- --storage.tsdb.retention.time via `$ps_retention_time` - --storage.tsdb.retention.time via `$ps_retention_time`
- --storage.tsdb.retention.size via `$ps_retention_size` - --storage.tsdb.retention.size via `$ps_retention_size`
- --storage.tsdb.wal-segment-size via `ps_wal_seg_size`
- --storage.tsdb.min-block-duration via `ps_min_block_dur`
- --storage.tsdb.max-block-duration via `ps_max_block_dur`
- authentication user via `$ps_auth_user` - authentication user via `$ps_auth_user`
- authentication password via `$ps_auth_pass` - authentication password via `$ps_auth_pass`
- web authentication password via `$ps_web_pass` ( different format required) - web authentication password via `$ps_web_pass` ( different format required)
- external remote write ( writing to a remote instance like pg-adapter):
- `ps_write_external` true enables it
- `ps_external_url` must be a valid full url
- `ps_auth_ext_user`must be a valid user
- `ps_auth_ext_pass`must be a valid password
- pruning local blocks
- `ps_enable_pruning` true enables it
- `ps_pruning_dir` the directory where the pruning script should live
## Repo Documentation ## Puppet Documentation
See the full Puppet documentation including parameters in `docs/index.html` See the full Puppet documentation including parameters in `docs/index.html`
@@ -83,6 +111,10 @@ All files and directories are configured with correct selinux context. If selinu
[contact Us](https://confdroid.com/contact/) [contact Us](https://confdroid.com/contact/)
## Feedback
Having suggestions or feature requests? head over to our
[feedback collection](https://feedback.confdroid.com) and add an item for public votes or discussion.
## Disclaimer ## Disclaimer
ConfDroid as entity is entirely independent from Puppet. We provide custom configuration modules, written for specific purposes and specific environments. ConfDroid as entity is entirely independent from Puppet. We provide custom configuration modules, written for specific purposes and specific environments.

View File

@@ -1,10 +1,10 @@
# prometheus_cd::firewall::iptables.pp # confdroid_prometheus::firewall::iptables.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages the firewall rules for the prometheus_cd module. # @summary Class manages the firewall rules for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::firewall::iptables ( class confdroid_prometheus::firewall::iptables (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
if ($ps_prom_host == $fqdn) and ($ps_manage_fw == true) { if ($ps_prom_host == $fqdn) and ($ps_manage_fw == true) {
# main port # main port
firewall { "${ps_fw_prefix}${$ps_main_port} main port": firewall { "${ps_fw_prefix}${$ps_main_port} main port":

View File

@@ -1,8 +1,8 @@
# prometheus_cd::init.pp # confdroid_prometheus::init.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class initializes the prometheus_cd module. # @summary Class initializes the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd { class confdroid_prometheus {
include prometheus_cd::params include confdroid_prometheus::params
} }

View File

@@ -1,9 +1,15 @@
# prometheus_cd::main::config.pp # confdroid_prometheus::main::config.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages the module logic for the prometheus_cd module. # @summary Class manages the module logic for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::config ( class confdroid_prometheus::main::config (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
include prometheus_cd::main::service include confdroid_prometheus::main::service
exec { 'systemd-daemon-reload':
command => '/bin/systemctl daemon-reload',
path => ['/bin', '/usr/bin'],
refreshonly => true,
}
} }

View File

@@ -1,11 +1,11 @@
# prometheus_cd::main::dirs.pp # confdroid_prometheus::main::dirs.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages directories for the prometheus_cd module. # @summary Class manages directories for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::dirs ( class confdroid_prometheus::main::dirs (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
require prometheus_cd::main::install require confdroid_prometheus::main::install
if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) { if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) {
# prometheus directory # prometheus directory
file { $ps_main_dir: file { $ps_main_dir:
@@ -29,5 +29,35 @@ class prometheus_cd::main::dirs (
seltype => systemd_unit_file_t, seltype => systemd_unit_file_t,
seluser => unconfined_u, seluser => unconfined_u,
} }
if $ps_enable_pruning == true {
file { $ps_pruning_dir:
ensure => directory,
owner => 'prometheus',
group => 'prometheus',
mode => '0755',
selrange => s0,
selrole => object_r,
seltype => usr_,
seluser => unconfined_u,
}
}
if $ps_enable_pruning == false {
file { $ps_pruning_dir:
ensure => absent,
}
}
# binary install directory
if $install_from_binary == true {
file { $ps_install_dir:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
selrange => s0,
selrole => object_r,
seltype => usr_,
seluser => unconfined_u,
}
}
} }
} }

View File

@@ -1,12 +1,12 @@
# prometheus_cd::main::files.pp # confdroid_prometheus::main::files.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages configuration files for the prometheus_cd module. # @summary Class manages configuration files for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::files ( class confdroid_prometheus::main::files (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) { if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) {
require prometheus_cd::main::dirs require confdroid_prometheus::main::dirs
file { $ps_main_file: file { $ps_main_file:
ensure => file, ensure => file,
owner => 'root', owner => 'root',
@@ -16,7 +16,7 @@ class prometheus_cd::main::files (
selrole => object_r, selrole => object_r,
seltype => etc_t, seltype => etc_t,
seluser => system_u, seluser => system_u,
content => template('prometheus_cd/prometheus.yml.erb'), content => template('confdroid_prometheus/prometheus.yml.erb'),
notify => Service[$ps_prom_service], notify => Service[$ps_prom_service],
} }
file { $ps_system_service_file: file { $ps_system_service_file:
@@ -28,7 +28,7 @@ class prometheus_cd::main::files (
selrole => object_r, selrole => object_r,
seltype => systemd_unit_file_t, seltype => systemd_unit_file_t,
seluser => unconfined_u, seluser => unconfined_u,
content => template('prometheus_cd/override.conf.erb'), content => template('confdroid_prometheus/override.conf.erb'),
notify => Service[$ps_prom_service], notify => Service[$ps_prom_service],
} }
file { $ps_web_config_file: file { $ps_web_config_file:
@@ -40,8 +40,77 @@ class prometheus_cd::main::files (
selrole => object_r, selrole => object_r,
seltype => etc_t, seltype => etc_t,
seluser => system_u, seluser => system_u,
content => template('prometheus_cd/web.yml.erb'), content => template('confdroid_prometheus/web.yml.erb'),
notify => Service[$ps_prom_service], notify => Service[$ps_prom_service],
} }
if $ps_enable_pruning == true {
file { $ps_pruning_file:
ensure => file,
owner => 'prometheus',
group => 'prometheus',
mode => '0750',
selrange => s0,
selrole => object_r,
seltype => usr_,
seluser => unconfined_u,
content => template('confdroid_prometheus/prune_blocks.erb'),
# notify Service ToDo,
}
file { $ps_env_file:
ensure => file,
owner => 'prometheus',
group => 'prometheus',
mode => '0440',
selrange => s0,
selrole => object_r,
seltype => usr_,
seluser => unconfined_u,
content => template('confdroid_prometheus/prune.env.erb'),
}
file { $ps_pruning_svc_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
selrange => s0,
selrole => object_r,
seltype => systemd_unit_file_t,
seluser => unconfined_u,
content => template('confdroid_prometheus/prometheus-prune-service.erb'),
notify => Exec['systemd-daemon-reload'],
}
file { $ps_pruning_timer_file:
ensure => file,
owner => 'root',
group => 'root',
mode => '0644',
selrange => s0,
selrole => object_r,
seltype => systemd_unit_file_t,
seluser => unconfined_u,
content => template('confdroid_prometheus/prometheus-prune-timer.erb'),
notify => Exec['systemd-daemon-reload'],
}
file { $ps_prune_log_file:
ensure => file,
owner => 'prometheus',
group => 'prometheus',
mode => '0644',
}
}
if $ps_enable_pruning == false {
file { $ps_pruning_file:
ensure => absent,
notify => Exec['systemd-daemon-reload'],
}
file { $ps_env_file:
ensure => absent,
}
file { $ps_pruning_svc_file:
ensure => absent,
notify => Exec['systemd-daemon-reload'],
}
}
} }
} }

View File

@@ -1,16 +1,22 @@
# prometheus_cd::main::install.pp # confdroid_prometheus::main::install.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class install binaries for the prometheus_cd module. # @summary Class install binaries for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::install ( class confdroid_prometheus::main::install (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
require prometheus_cd::main::yumrepo require confdroid_prometheus::main::yumrepo
if $manage_prometheus == true { if $manage_prometheus == true {
if $install_from_binary == false {
package { $reqpackage_prom: package { $reqpackage_prom:
ensure => $pkg_ensure, ensure => $pkg_ensure,
} }
} }
if $install_from_binary == true {
# place function here to install from binary releases, e.g. using the archive module
}
}
if $manage_node_exporter == true { if $manage_node_exporter == true {
package { $reqpackage_ne: package { $reqpackage_ne:
ensure => $pkg_ensure, ensure => $pkg_ensure,

View File

@@ -1,13 +1,13 @@
# prometheus_cd::main::service.pp # confdroid_prometheus::main::service.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages the services for the prometheus_cd module. # @summary Class manages the services for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::service ( class confdroid_prometheus::main::service (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) { if ($ps_prom_host == $fqdn) and ($manage_prometheus == true) {
require prometheus_cd::main::files require confdroid_prometheus::main::files
require prometheus_cd::firewall::iptables require confdroid_prometheus::firewall::iptables
service { $ps_prom_service: service { $ps_prom_service:
ensure => running, ensure => running,
hasstatus => true, hasstatus => true,
@@ -23,4 +23,27 @@ class prometheus_cd::main::service (
enable => true, enable => true,
} }
} }
if $ps_enable_pruning == true {
service { $ps_prune_service:
hasstatus => true,
hasrestart => true,
}
service { $ps_prune_timer:
ensure => running,
hasstatus => true,
hasrestart => true,
enable => true,
subscribe => File[$ps_pruning_svc_file],
}
}
if $ps_enable_pruning == false {
service { $ps_prune_service:
ensure => stopped,
enable => false,
}
service { $ps_prune_timer:
ensure => stopped,
enable => false,
}
}
} }

View File

@@ -1,10 +1,10 @@
# prometheus_cd::main::yumrepo.pp # confdroid_prometheus::main::yumrepo.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class manages yumrepo for the prometheus_cd module. # @summary Class manages yumrepo for the confdroid_prometheus module.
############################################################################## ##############################################################################
class prometheus_cd::main::yumrepo ( class confdroid_prometheus::main::yumrepo (
) inherits prometheus_cd::params { ) inherits confdroid_prometheus::params {
yumrepo { 'prometheus': yumrepo { 'prometheus':
ensure => 'present', ensure => 'present',
name => 'prometheus', name => 'prometheus',

View File

@@ -1,7 +1,7 @@
# prometheus_cd::params.pp # confdroid_prometheus::params.pp
# Module name: prometheus_cd # Module name: confdroid_prometheus
# Author: Arne Teuke (arne_teuke@confdroid.com) # Author: 12ww1160 (12ww1160@confdroid.com)
# @summary Class holds all parameters for the prometheus_cd module. # @summary Class holds all parameters for the confdroid_prometheus module.
# @param [String] reqpackage_prom the prometheus package # @param [String] reqpackage_prom the prometheus package
# @param [String] reqpackage_ne the node_exporter package # @param [String] reqpackage_ne the node_exporter package
# @param [String] pkg_ensure which version of the package to install # @param [String] pkg_ensure which version of the package to install
@@ -16,13 +16,41 @@
# @param [String] ps_web_pass the password for web authentication # @param [String] ps_web_pass the password for web authentication
# @param [String] ps_retention_time tsdb retention time # @param [String] ps_retention_time tsdb retention time
# @param [String] ps_retention_size tsdb retention size # @param [String] ps_retention_size tsdb retention size
# @param [String] ps_wal_seg_size WAL segment size
# @param [String] ps_min_block_dur tsdb minimum block duration
# @param [String] ps_max_block_dur tsdb maximum block duration
# @param [String] ps_max_mem hard memory ceiling
# @param [String] ps_high_mem soft limit to make kernel reclaim earlier
# @param [String] ps_swap_mem allow swap, but limit it
# @param [String] ps_oom_score OOM killer choosing prometheus
# @param [String] ps_max_procs reduce parallel WAL replay workers
# @param [Boolean] ps_write_external whether to allow remote postgres
# @param [String] ps_auth_ext_user user for writing to extern instance
# @param [String] ps_auth_ext_pass password for writing to extern instance
# @param [String] ps_external_url the full url for the remote write point
# @param [Boolean] ps_enable_pruning whether to allow pruning local blocks
# @param [String] ps_pruning_dir the directory for the pruning script
# @param [String] ps_pruning_file the url and filename for the pruning script
# @param [String] ps_env_file the url and filename for the env file
# @param [String] ps_pg_host the host running the database for cold metrics
# @param [String] ps_pg_port the port for the database for cold metrics
# @param [String] ps_pg_db the database for cold metrics
# @param [String] ps_pg_user the read-only user for the db for cold metrics
# @param [String] ps_pg_pass the password for the db for cold metrics
# @param [Boolean] ps_dry_run (true = just log, false = actually delete blocks)
# @param [String] ps_min_age_hours Minimum block age in hours before pruning
# @param [String] ps_grace_hours Grace period in hours to be extra safe
# @param [String] ps_sql_template the SQL template to use for checks.
# @param [Boolean] install_from_binary whether to install from binary releases
# instead of packages
############################################################################## ##############################################################################
class prometheus_cd::params ( class confdroid_prometheus::params (
# installation # installation
String $reqpackage_prom = 'prometheus2', String $reqpackage_prom = 'prometheus2',
String $reqpackage_ne = 'node_exporter', String $reqpackage_ne = 'node_exporter',
String $pkg_ensure = 'present', String $pkg_ensure = 'present',
Boolean $install_from_binary = false,
# config logic # config logic
Boolean $manage_prometheus = false, Boolean $manage_prometheus = false,
@@ -34,14 +62,47 @@ class prometheus_cd::params (
String $ps_fw_prefix = '50', String $ps_fw_prefix = '50',
String $ps_main_port = '9090', String $ps_main_port = '9090',
# auth # auth prometheus
String $ps_auth_user = 'changeme', String $ps_auth_user = 'changeme',
String $ps_auth_pass = 'changeme', String $ps_auth_pass = 'changeme',
String $ps_web_pass = 'changeme', String $ps_web_pass = 'changeme',
# auth remote
String $ps_auth_ext_user = 'changeme',
String $ps_auth_ext_pass = 'changeme',
# storage # storage
String $ps_retention_time = '15d', String $ps_retention_time = '15d',
String $ps_retention_size = '20GB', String $ps_retention_size = '20GB',
String $ps_wal_seg_size = '50MB',
String $ps_min_block_dur = '2h',
String $ps_max_block_dur = '2h',
# service
String $ps_max_mem = '6G',
String $ps_high_mem = '5G',
String $ps_swap_mem = '4G',
String $ps_oom_score = '500',
String $ps_max_procs = '1',
# remote write external
Boolean $ps_write_external = false,
String $ps_external_url = 'http://changeme.local',
# pruning script
Boolean $ps_enable_pruning = false,
String $ps_pruning_dir = '/opt/prometheus-prune',
String $ps_pruning_file = "${ps_pruning_dir}/prune_prometheus_pg.sh",
String $ps_env_file = "${ps_pruning_dir}/prune.env",
String $ps_pg_host = 'localhost',
String $ps_pg_port = '5432',
String $ps_pg_db = 'prometheus',
String $ps_pg_user = 'readaccess',
String $ps_pg_pass = 'Changeme',
Boolean $ps_dry_run = true,
String $ps_min_age_hours = '4',
String $ps_grace_hours = '1',
String $ps_sql_template = 'Changeme',
) { ) {
# defaults # defaults
@@ -53,16 +114,23 @@ class prometheus_cd::params (
# dirs # dirs
$ps_main_dir = '/etc/prometheus' $ps_main_dir = '/etc/prometheus'
$ps_system_file_dir = '/etc/systemd/system/prometheus.service.d' $ps_system_file_dir = '/etc/systemd/system/prometheus.service.d'
$ps_system_dir = '/etc/systemd/system/'
$ps_install_dir = '/opt/prometheus'
# files # files
$ps_main_file = "${ps_main_dir}/prometheus.yml" $ps_main_file = "${ps_main_dir}/prometheus.yml"
$ps_web_config_file = "${ps_main_dir}/web.yml" $ps_web_config_file = "${ps_main_dir}/web.yml"
$ps_system_service_file = "${ps_system_file_dir}/override.conf" $ps_system_service_file = "${ps_system_file_dir}/override.conf"
$ps_pruning_svc_file = "${ps_system_dir}/prometheus-prune.service"
$ps_pruning_timer_file = "${ps_system_dir}/prometheus-prune.timer"
$ps_prune_log_file = '/var/log/prometheus-prune.log'
# services # services
$ps_prom_service = 'prometheus' $ps_prom_service = 'prometheus'
$ps_ne_service = 'node_exporter' $ps_ne_service = 'node_exporter'
$ps_prune_service = 'prometheus-prune.service'
$ps_prune_timer = 'prometheus-prune.timer'
# includes must be last # includes must be last
include prometheus_cd::main::config include confdroid_prometheus::main::config
} }

View File

@@ -2,6 +2,7 @@
##### File created by Puppet - manual changes will be overwritten ##### ##### File created by Puppet - manual changes will be overwritten #####
############################################################################### ###############################################################################
[Service] [Service]
ExecStart= ExecStart=
ExecStart=/usr/bin/prometheus \ ExecStart=/usr/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \ --config.file=/etc/prometheus/prometheus.yml \
@@ -9,6 +10,9 @@ ExecStart=/usr/bin/prometheus \
--storage.tsdb.path=/var/lib/prometheus \ --storage.tsdb.path=/var/lib/prometheus \
--storage.tsdb.retention.time=<%= @ps_retention_time %> \ --storage.tsdb.retention.time=<%= @ps_retention_time %> \
--storage.tsdb.retention.size=<%= @ps_retention_size %> \ --storage.tsdb.retention.size=<%= @ps_retention_size %> \
--storage.tsdb.wal-segment-size=<%= @ps_wal_seg_size %> \
--web.enable-remote-write-receiver \ --web.enable-remote-write-receiver \
--web.enable-lifecycle \ --web.enable-lifecycle \
--storage.tsdb.wal-compression --storage.tsdb.wal-compression \
--storage.tsdb.min-block-duration=<%= @ps_min_block_dur %> \
--storage.tsdb.max-block-duration=<%= @ps_max_block_dur %>

View File

@@ -0,0 +1,13 @@
[Unit]
Description=Prometheus TSDB prune service
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
User=prometheus
Group=prometheus
EnvironmentFile=<%= @ps_env_file %>
ExecStart=<%= @ps_pruning_file %>
Nice=10
IOWeight=80

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Run Prometheus TSDB prune script every 6 hours
[Timer]
OnBootSec=10min
OnUnitActiveSec=6h
Persistent=true
[Install]
WantedBy=timers.target

View File

@@ -32,7 +32,16 @@ scrape_configs:
username: <%= @ps_auth_user %> username: <%= @ps_auth_user %>
password: <%= @ps_auth_pass %> password: <%= @ps_auth_pass %>
remote_write: remote_write:
- url: "http://localhost:9090/api/v1/write" <% if @ps_write_external == true -%>
- url: "<%= @ps_external_url %>/write"
basic_auth: basic_auth:
username: <%= @ps_auth_user %> username: <%= @ps_auth_ext_user %>
password: <%= @ps_auth_pass %> password: <%= @ps_auth_ext_pass %>
<% end -%>
remote_read:
<% if @ps_write_external == true -%>
- url: "<%= @ps_external_url %>/read"
basic_auth:
username: <%= @ps_auth_ext_user %>
password: <%= @ps_auth_ext_pass %>
<% end -%>

21
templates/prune.env.erb Normal file
View File

@@ -0,0 +1,21 @@
# /opt/prometheus-prune/prune.env
# PostgreSQL connection
PGHOST=<%= @ps_pg_host %>
PGPORT=<%= @ps_pg_port %>
PGDATABASE=<%= @ps_pg_db %>
PGUSER=<%= @ps_pg_user %>
PGPASSWORD=<%= @ps_pg_pass %>
# Dry-run mode (true = just log, false = actually delete)
DRY_RUN=<%= @ps_dry_run %>
# Minimum block age in hours before pruning
MIN_AGE_HOURS=<%= @ps_min_age_hours %>
# Grace period in hours to be extra safe
GRACE_HOURS=<%= @ps_grace_hours %>
# SQL template to check if block exists in PostgreSQL
# @param [String] ps_sql_template the SQL template to use for checks.
<%= @ps_sql_template %>

View File

@@ -0,0 +1,48 @@
#!/bin/bash
set -euo pipefail
# Load environment
source <%= @ps_env_file %>
LOG_FILE="<%= @ps_prune_log_file %>"
echo "$(date '+%Y-%m-%d %H:%M:%S') Starting prune run" >> "$LOG_FILE"
# -----------------------
# Iterate TSDB blocks
# -----------------------
for block in "$TSDB_DIR"/*/; do
[[ -d "$block" ]] || continue
meta="$block/meta.json"
[[ -f "$meta" ]] || continue
min_time=$(jq -r '.minTime' "$meta")
max_time=$(jq -r '.maxTime' "$meta")
# Skip last MIN_AGE_HOURS
block_age_hours=$(( ($(date +%s) - min_time/1000) / 3600 ))
if (( block_age_hours < MIN_AGE_HOURS + GRACE_HOURS )); then
log "Keeping block $block (age ${block_age_hours}h)"
continue
fi
# Check existence in PostgreSQL
check_sql="${CHECK_SQL_TEMPLATE//\{min\}/$min_time}"
check_sql="${check_sql//\{max\}/$max_time}"
exists=$(psql -h "$PGHOST" -p "$PGPORT" -U "$PGUSER" -d "$PGDATABASE" -t -c "$check_sql" | xargs || echo "0")
if [[ "$exists" != "1" ]]; then
log "Block $block not confirmed in PostgreSQL, skipping deletion"
continue
fi
# Delete block
if [[ "$DRY_RUN" == "true" ]]; then
log "[DRY-RUN] Would delete block $block"
else
log "Deleting block $block"
rm -rf "$block"
fi
done
echo "$(date '+%Y-%m-%d %H:%M:%S') Prune run finished" >> "$LOG_FILE"