Add community prometheus cookbook

This commit is contained in:
Greg Karekinian
2026-07-03 16:35:26 +02:00
parent ec73dd5b57
commit 4cd6c41254
29 changed files with 1430 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
ruby:
config_file: .rubocop.yml
java_script:
enabled: false
scss:
enabled: false
@@ -0,0 +1,9 @@
config:
ul-indent: false # MD007
line-length: false # MD013
no-duplicate-heading: false # MD024
reference-links-images: false # MD052
no-multiple-blanks:
maximum: 2
ignores:
- .github/copilot-instructions.md
@@ -0,0 +1,3 @@
{
".": "1.0.0"
}
+104
View File
@@ -0,0 +1,104 @@
# Change Log
All notable changes to this project will be documented in this file.
## [1.0.0](https://github.com/sous-chefs/prometheus/compare/v0.7.6...v1.0.0) (2026-04-29)
### ⚠ BREAKING CHANGES
* migrate prometheus resources ([#36](https://github.com/sous-chefs/prometheus/issues/36))
### Features
* migrate prometheus resources ([#36](https://github.com/sous-chefs/prometheus/issues/36)) ([6698649](https://github.com/sous-chefs/prometheus/commit/66986492fe0f069bc69474e19423b16e21563c16))
### Bug Fixes
* **ci:** Update workflows to use release pipeline ([#29](https://github.com/sous-chefs/prometheus/issues/29)) ([b991214](https://github.com/sous-chefs/prometheus/commit/b991214225164d55694966e535478a38e720a8f0))
## [0.7.6](https://github.com/sous-chefs/prometheus/compare/0.7.5...v0.7.6) (2025-10-16)
### Bug Fixes
* **ci:** Update workflows to use release pipeline ([#29](https://github.com/sous-chefs/prometheus/issues/29)) ([b991214](https://github.com/sous-chefs/prometheus/commit/b991214225164d55694966e535478a38e720a8f0))
## 0.7.2 - *2022-02-08*
* Remove delivery folder
Standardise files with files in sous-chefs/repo-management
## 0.7.1 - *2021-06-01*
* resolved cookstyle error: Thorfile:1:1 convention: `Style/Encoding`
* resolved cookstyle error: test/shared/spec_helper.rb:6:10 convention: `Style/ExpandPathArguments`
## [0.7.1 - *2021-06-01*][0.7.1 - *2021-06-01*]
### Changed
* Updated attributes and templates for Prometheus 0.15 release.
### Added
* Added upstart init for ubuntu platform.
## [0.5.1] - 2015-03-25
Changed
* Updated documentation.
## [0.5.0] - 2015-03-25
Added
* Added systemd init for redhat platform family version 7 or greater.
* Default init style per platform.
* Install Prometheus via pre-compiled binary.
* Added the prometheus_job resource for defining Prometheus scraping jobs.
* Attribute flag to externally manage prometheus.conf file.
Changed
* Removed flags that were deprecated in the prometheus 0.12.0 release.
### Contributors for this release
* [Eric Richardson](https://github.com/ewr) - External jobs config and prometheus job resource.
Thank You!
## [0.4.0] - 2015-03-12
### Fixed
* Fix init template path bug on chef 11.x.
## [0.3.0] - 2015-03-11
Fixed
* Fixed cookbook badge in README
## [0.2.0] - 2015-03-11
Fixed
* License defined in metadata.
## 0.1.0 - 2015-03-11
Changed
* Initial release of prometheus cookbook
[0.7.1 - *2021-06-01*]: https://github.com/rayrod2030/chef-prometheus/compare/0.5.1...HEAD
[0.5.1]: https://github.com/rayrod2030/chef-prometheus/compare/0.5.0...0.5.1
[0.5.0]: https://github.com/rayrod2030/chef-prometheus/compare/0.4.0...0.5.0
[0.4.0]: https://github.com/rayrod2030/chef-prometheus/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/rayrod2030/chef-prometheus/compare/0.2.0...0.3.0
[0.2.0]: https://github.com/rayrod2030/chef-prometheus/compare/0.1.0...0.2.0
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://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.
+36
View File
@@ -0,0 +1,36 @@
# Limitations
This cookbook manages Prometheus and Alertmanager from upstream release archives or source builds.
## Upstream Support
Prometheus publishes precompiled archives for Prometheus and Alertmanager from the official download page and GitHub releases. As of April 28, 2026, the cookbook defaults to:
* Prometheus 3.11.2 `linux-amd64` and `linux-arm64`
* Alertmanager 0.32.0 `linux-amd64` and `linux-arm64`
The upstream projects also publish Docker images and archives for other operating systems. This cookbook only supports Linux systemd hosts.
## Platform Support
Supported platforms are modern systemd Linux distributions declared in `metadata.rb`:
* AlmaLinux 8+
* Amazon Linux 2023+
* CentOS Stream 9+
* Debian 12+
* Fedora
* Oracle Linux 8+
* Red Hat Enterprise Linux 8+
* Rocky Linux 8+
* Ubuntu 20.04+
Legacy init systems are not supported. The cookbook no longer manages runit, upstart, or SysV init services.
## Installation Constraints
The default binary installation path uses official Linux tarballs for `amd64` or `arm64`. Override `architecture`, `binary_url`, `checksum`, and `file_extension` when using another upstream artifact or a private mirror.
Source installs require build tooling, Git, and the upstream Go build chain expected by the selected Prometheus or Alertmanager version. Source builds are retained for compatibility but binary installs are the primary supported path.
Prometheus and Alertmanager are not installed from operating system package repositories by these resources.
+67
View File
@@ -0,0 +1,67 @@
# prometheus Cookbook
This cookbook provides custom resources for installing and configuring [Prometheus][] and Alertmanager.
## Requirements
* Chef Infra Client 16.0 or later
* A systemd Linux platform listed in [LIMITATIONS.md](LIMITATIONS.md)
See [LIMITATIONS.md](LIMITATIONS.md) for upstream platform and installation constraints.
## Resources
* [prometheus_install](documentation/prometheus_install.md)
* [prometheus_config](documentation/prometheus_config.md)
* [prometheus_service](documentation/prometheus_service.md)
* [prometheus_job](documentation/prometheus_job.md)
* [prometheus_alertmanager_install](documentation/prometheus_alertmanager_install.md)
* [prometheus_alertmanager_config](documentation/prometheus_alertmanager_config.md)
* [prometheus_alertmanager_service](documentation/prometheus_alertmanager_service.md)
See [migration.md](migration.md) for migration notes from the legacy recipe and attribute interface.
## Usage
```ruby
prometheus_install 'prometheus'
prometheus_config 'prometheus'
prometheus_job 'prometheus' do
scrape_interval '15s'
target 'localhost:9090'
end
prometheus_service 'prometheus'
```
Alertmanager:
```ruby
prometheus_alertmanager_install 'alertmanager'
prometheus_alertmanager_config 'alertmanager'
prometheus_alertmanager_service 'alertmanager'
```
## License & Authors
* Author: Ray Rodriguez <rayrod2030@gmail.com>
* Author: kristian järvenpää <kristian.jarvenpaa@gmail.com>
* Maintainer: Sous Chefs
```text
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
http://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]: https://github.com/prometheus/prometheus
+10
View File
@@ -0,0 +1,10 @@
require 'bundler'
require 'bundler/setup'
require 'berkshelf/thor'
begin
require 'kitchen/thor_tasks'
Kitchen::ThorTasks.new
rescue LoadError
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
+115
View File
@@ -0,0 +1,115 @@
# Put files/directories that should be ignored in this file when uploading
# to a Chef Infra Server or Supermarket.
# Lines that start with '# ' are comments.
# OS generated files #
######################
.DS_Store
ehthumbs.db
Icon?
nohup.out
Thumbs.db
.envrc
# EDITORS #
###########
.#*
.project
.settings
*_flymake
*_flymake.*
*.bak
*.sw[a-z]
*.tmproj
*~
\#*
REVISION
TAGS*
tmtags
.vscode
.editorconfig
## COMPILED ##
##############
*.class
*.com
*.dll
*.exe
*.o
*.pyc
*.so
*/rdoc/
a.out
mkmf.log
# Testing #
###########
.circleci/*
.codeclimate.yml
.delivery/*
.foodcritic
.kitchen*
.mdlrc
.overcommit.yml
.rspec
.rubocop.yml
.travis.yml
.watchr
.yamllint
azure-pipelines.yml
Dangerfile
examples/*
features/*
Guardfile
kitchen*.yml
mlc_config.json
Procfile
Rakefile
spec/*
test/*
# SCM #
#######
.git
.gitattributes
.gitconfig
.github/*
.gitignore
.gitkeep
.gitmodules
.svn
*/.bzr/*
*/.git
*/.hg/*
*/.svn/*
# Berkshelf #
#############
Berksfile
Berksfile.lock
cookbooks/*
tmp
# Bundler #
###########
vendor/*
Gemfile
Gemfile.lock
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Documentation #
#############
CODE_OF_CONDUCT*
CONTRIBUTING*
documentation/*
TESTING*
UPGRADING*
# Vagrant #
###########
.vagrant
Vagrantfile
+78
View File
@@ -0,0 +1,78 @@
# frozen_string_literal: true
require 'uri'
module PrometheusCookbook
module Helpers
def archive_name(component, version, url)
basename = ::File.basename(URI.parse(url).path)
basename.sub(/(?:\.tar\.gz|\.tgz|\.tar\.bz2|\.tar\.xz|\.zip)\z/, '')
rescue URI::InvalidURIError
"#{component}-#{version}"
end
def install_dir_parent(install_dir)
::File.dirname(install_dir)
end
def install_dir_name(install_dir)
::File.basename(install_dir)
end
def prometheus_flags(resource)
flag_pairs = if Gem::Version.new(resource.version) < Gem::Version.new('2.0.0-alpha.0')
resource.flags.map { |key, value| "-#{key}=#{value}" unless value == '' }
else
resource.cli_options.map { |key, value| "--#{key}=#{value}" unless value == '' } +
resource.cli_flags.map { |flag| "--#{flag}" unless flag == '' }
end
flag_pairs.compact.join(' ')
end
def prometheus_unit_content(resource)
{
Unit: {
Description: 'Prometheus',
After: 'network.target auditd.service',
},
Service: {
Type: 'simple',
Environment: "GOMAXPROCS=#{node['cpu']['total'] || 1}",
User: resource.user,
Group: resource.group,
ExecStart: "#{resource.binary} #{prometheus_flags(resource)}",
ExecReload: '/bin/kill -HUP $MAINPID',
Restart: 'always',
},
Install: {
WantedBy: 'multi-user.target',
},
}
end
def alertmanager_unit_content(resource)
{
Unit: {
Description: 'Prometheus Alertmanager',
After: 'network.target',
},
Service: {
User: resource.user,
Group: resource.group,
ExecStart: [
resource.binary,
"--log.level=#{resource.log_level}",
"--storage.path=#{resource.storage_path}",
"--config.file=#{resource.config_file}",
"--web.external-url=#{resource.external_url}",
].join(' '),
Restart: 'always',
},
Install: {
WantedBy: 'multi-user.target',
},
}
end
end
end
+44
View File
@@ -0,0 +1,44 @@
{
"name": "prometheus",
"description": "Provides custom resources for installing and configuring Prometheus and Alertmanager",
"long_description": "",
"maintainer": "Sous Chefs",
"maintainer_email": "help@sous-chefs.org",
"license": "Apache-2.0",
"platforms": {
"almalinux": ">= 8.0",
"amazon": ">= 2023.0",
"centos_stream": ">= 9.0",
"debian": ">= 12.0",
"fedora": ">= 0.0.0",
"oracle": ">= 8.0",
"redhat": ">= 8.0",
"rocky": ">= 8.0",
"ubuntu": ">= 20.04"
},
"dependencies": {
"ark": ">= 0.0.0"
},
"providing": {
},
"recipes": {
},
"version": "1.0.0",
"source_url": "https://github.com/sous-chefs/prometheus",
"issues_url": "https://github.com/sous-chefs/prometheus/issues",
"privacy": false,
"chef_versions": [
[
">= 16.0"
]
],
"ohai_versions": [
],
"gems": [
],
"eager_load_libraries": true
}
+23
View File
@@ -0,0 +1,23 @@
# frozen_string_literal: true
name 'prometheus'
maintainer 'Sous Chefs'
maintainer_email 'help@sous-chefs.org'
license 'Apache-2.0'
description 'Provides custom resources for installing and configuring Prometheus and Alertmanager'
version '1.0.0'
source_url 'https://github.com/sous-chefs/prometheus'
issues_url 'https://github.com/sous-chefs/prometheus/issues'
chef_version '>= 16.0'
depends 'ark'
supports 'almalinux', '>= 8.0'
supports 'amazon', '>= 2023.0'
supports 'centos_stream', '>= 9.0'
supports 'debian', '>= 12.0'
supports 'fedora'
supports 'oracle', '>= 8.0'
supports 'redhat', '>= 8.0'
supports 'rocky', '>= 8.0'
supports 'ubuntu', '>= 20.04'
+36
View File
@@ -0,0 +1,36 @@
# Migration
This cookbook has been migrated from recipes and attributes to custom resources.
## Removed Entry Points
The `recipes/` and `attributes/` directories were removed. Wrapper cookbooks should call the resources directly and pass property values instead of overriding `node['prometheus']` attributes.
Legacy runit, upstart, and SysV init behavior was removed. Services are managed with Chef's `systemd_unit` resource.
## Resource Mapping
Use these resources in place of the old recipes:
* `prometheus_install` replaces `prometheus::binary`, `prometheus::shell_binary`, and `prometheus::source`.
* `prometheus_config` replaces the Prometheus configuration portion of `prometheus::default`.
* `prometheus_service` replaces `prometheus::service`.
* `prometheus_alertmanager_install` replaces `prometheus::alertmanager_binary` and `prometheus::alertmanager_source`.
* `prometheus_alertmanager_config` replaces the Alertmanager configuration portion of `prometheus::alertmanager`.
* `prometheus_alertmanager_service` replaces the Alertmanager service portion of `prometheus::alertmanager`.
* `prometheus_job` remains available and now uses explicit properties instead of node attributes.
## Example
```ruby
prometheus_install 'prometheus'
prometheus_config 'prometheus'
prometheus_job 'prometheus' do
scrape_interval '15s'
target 'localhost:9090'
end
prometheus_service 'prometheus'
```
@@ -0,0 +1,12 @@
{
"packages": {
".": {
"package-name": "prometheus",
"changelog-path": "CHANGELOG.md",
"release-type": "ruby",
"include-component-in-tag": false,
"version-file": "metadata.rb"
}
},
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}
+18
View File
@@ -0,0 +1,18 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"packageRules": [
{
"groupName": "Actions",
"matchUpdateTypes": ["minor", "patch", "pin"],
"automerge": true,
"addLabels": ["Release: Patch", "Skip: Announcements"]
},
{
"groupName": "Actions",
"matchUpdateTypes": ["major"],
"automerge": false,
"addLabels": ["Release: Patch", "Skip: Announcements"]
}
]
}
@@ -0,0 +1,21 @@
# frozen_string_literal: true
property :version, String, default: '0.32.0'
property :binary, String, default: '/opt/prometheus/alertmanager'
property :architecture, String, equal_to: %w(amd64 arm64), default: lazy {
node['kernel']['machine'] == 'aarch64' ? 'arm64' : 'amd64'
}
property :binary_url, String, default: lazy { "https://github.com/prometheus/alertmanager/releases/download/v#{version}/alertmanager-#{version}.linux-#{architecture}.tar.gz" }
property :checksum, String, default: lazy {
{
'amd64' => 'be72f50f6124ec53d944c0f100f8ec8108d969bade02fcc9f06a3068ff6c726f',
'arm64' => '7812e12699694974f57ecc0b0400913c6c0d90190630d4332a7994a44982b1ed',
}[architecture]
}
property :file_extension, String, default: ''
property :source_repository, String, default: 'https://github.com/prometheus/alertmanager.git'
property :source_revision, String, default: lazy { "v#{version}" }
property :config_file, String, default: '/opt/prometheus/alertmanager.yml'
property :storage_path, String, default: '/opt/prometheus/data'
property :external_url, String, default: 'http://127.0.0.1/alert-manager/'
property :log_level, String, default: 'debug'
@@ -0,0 +1,8 @@
# frozen_string_literal: true
property :install_dir, String, default: '/opt/prometheus'
property :log_dir, String, default: '/var/log/prometheus'
property :user, String, default: 'prometheus'
property :group, String, default: 'prometheus'
property :use_existing_user, [true, false], default: false
property :install_method, String, equal_to: %w(binary shell_binary source), default: 'binary'
@@ -0,0 +1,71 @@
# frozen_string_literal: true
property :version, String, default: '3.11.2'
property :binary, String, default: '/opt/prometheus/prometheus'
property :architecture, String, equal_to: %w(amd64 arm64), default: lazy {
node['kernel']['machine'] == 'aarch64' ? 'arm64' : 'amd64'
}
property :binary_url, String, default: lazy { "https://github.com/prometheus/prometheus/releases/download/v#{version}/prometheus-#{version}.linux-#{architecture}.tar.gz" }
property :checksum, String, default: lazy {
{
'amd64' => 'f643ea1ee90d109329302d27bddb1fb2e52655b1fa84e9e26f9a6f340da144a6',
'arm64' => '4e40f115655a3021744137f49287846bc5a59e02835565748ff66b23e776a73d',
}[architecture]
}
property :file_extension, String, default: ''
property :source_repository, String, default: 'https://github.com/prometheus/prometheus.git'
property :source_revision, String, default: lazy { "v#{version}" }
property :config_file, String, default: '/opt/prometheus/prometheus.yml'
property :storage_path, String, default: '/var/lib/prometheus'
property :flags, Hash, default: lazy {
legacy_flags = {
'config.file' => config_file,
'log.level' => 'info',
'alertmanager.timeout' => '10s',
'alertmanager.notification-queue-capacity' => 100,
'alertmanager.url' => 'http://127.0.0.1/alert-manager/',
'query.max-concurrency' => 20,
'query.staleness-delta' => '5m',
'query.timeout' => '2m',
'storage.local.checkpoint-dirty-series-limit' => 5000,
'storage.local.checkpoint-interval' => '5m',
'storage.local.dirty' => false,
'storage.local.index-cache-size.fingerprint-to-metric' => 10_485_760,
'storage.local.index-cache-size.fingerprint-to-timerange' => 5_242_880,
'storage.local.index-cache-size.label-name-to-label-values' => 10_485_760,
'storage.local.index-cache-size.label-pair-to-fingerprints' => 20_971_520,
'storage.local.memory-chunks' => 1_048_576,
'storage.local.path' => storage_path,
'storage.local.pedantic-checks' => false,
'storage.local.retention' => '360h0m0s',
'storage.local.series-sync-strategy' => 'adaptive',
'storage.remote.influxdb-url' => '',
'storage.remote.influxdb.database' => 'prometheus',
'storage.remote.influxdb.retention-policy' => 'default',
'storage.remote.opentsdb-url' => '',
'storage.remote.timeout' => '30s',
'web.console.libraries' => 'console_libraries',
'web.console.templates' => 'consoles',
'web.enable-remote-shutdown' => false,
'web.external-url' => '',
'web.listen-address' => ':9090',
'web.telemetry-path' => '/metrics',
'web.user-assets' => '',
}
legacy_flags['web.use-local-assets'] = false if Gem::Version.new(version) <= Gem::Version.new('0.16.2')
legacy_flags
}
property :cli_options, Hash, default: lazy {
{
'config.file' => config_file,
'log.level' => 'info',
'query.max-concurrency' => 20,
'query.lookback-delta' => '5m',
'query.timeout' => '2m',
'storage.tsdb.path' => storage_path,
'storage.tsdb.retention.time' => '15d',
'web.listen-address' => ':9090',
'web.telemetry-path' => '/metrics',
}
}
property :cli_flags, Array, default: ['web.enable-lifecycle']
@@ -0,0 +1,30 @@
# frozen_string_literal: true
provides :prometheus_alertmanager_config
unified_mode true
use '_partial/_common'
use '_partial/_alertmanager'
property :template_cookbook, String, default: 'prometheus'
property :template_source, String, default: 'alertmanager.yml.erb'
property :notification_config, Hash, default: {}
default_action :create
action :create do
template new_resource.config_file do
cookbook new_resource.template_cookbook
source new_resource.template_source
mode '0644'
owner new_resource.user
group new_resource.group
variables(notification_config: new_resource.notification_config)
end
end
action :delete do
file new_resource.config_file do
action :delete
end
end
@@ -0,0 +1,89 @@
# frozen_string_literal: true
provides :prometheus_alertmanager_install
unified_mode true
use '_partial/_common'
use '_partial/_alertmanager'
default_action :install
action_class do
include PrometheusCookbook::Helpers
end
action :install do
user new_resource.user do
system true
shell '/bin/false'
home new_resource.install_dir
not_if { new_resource.use_existing_user || new_resource.user == 'root' }
end
directory new_resource.install_dir do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
directory new_resource.log_dir do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
directory new_resource.storage_path do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
case new_resource.install_method
when 'binary'
package %w(tar bzip2)
ark install_dir_name(new_resource.install_dir) do
url new_resource.binary_url
checksum new_resource.checksum
version new_resource.version
prefix_root Chef::Config['file_cache_path']
path install_dir_parent(new_resource.install_dir)
owner new_resource.user
group new_resource.group
extension new_resource.file_extension unless new_resource.file_extension.empty?
action :put
end
when 'shell_binary'
package %w(tar bzip2)
remote_file "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}.tar.gz" do
source new_resource.binary_url
checksum new_resource.checksum
action :create
notifies :run, 'execute[install_alertmanager_archive]', :immediately
end
execute 'install_alertmanager_archive' do
command "tar -xzf #{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}.tar.gz -C #{new_resource.install_dir} --strip-components=1"
action :nothing
end
when 'source'
build_essential 'install compilation tools'
package %w(curl git-core mercurial gzip sed)
git "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}" do
repository new_resource.source_repository
revision new_resource.source_revision
action :checkout
end
bash 'compile_alertmanager_source' do
cwd "#{Chef::Config[:file_cache_path]}/alertmanager-#{new_resource.version}"
code "make && mv alertmanager #{new_resource.install_dir}"
end
end
end
@@ -0,0 +1,56 @@
# frozen_string_literal: true
provides :prometheus_alertmanager_service
unified_mode true
use '_partial/_common'
use '_partial/_alertmanager'
default_action :create
action_class do
include PrometheusCookbook::Helpers
end
action :create do
systemd_unit 'alertmanager.service' do
content alertmanager_unit_content(new_resource)
action [:create, :enable, :start]
end
end
action :enable do
systemd_unit 'alertmanager.service' do
action :enable
end
end
action :start do
systemd_unit 'alertmanager.service' do
action :start
end
end
action :restart do
systemd_unit 'alertmanager.service' do
action :restart
end
end
action :reload do
systemd_unit 'alertmanager.service' do
action :reload
end
end
action :stop do
systemd_unit 'alertmanager.service' do
action [:stop, :disable]
end
end
action :delete do
systemd_unit 'alertmanager.service' do
action [:stop, :disable, :delete]
end
end
+44
View File
@@ -0,0 +1,44 @@
# frozen_string_literal: true
provides :prometheus_config
unified_mode true
use '_partial/_common'
use '_partial/_prometheus'
property :template_cookbook, String, default: 'prometheus'
property :template_source, String, default: 'prometheus.yml.erb'
property :rule_filenames, [Array, nil], default: nil
property :global_config, Hash, default: {
'scrape_interval' => '60s',
'evaluation_interval' => '60s',
}
property :allow_external_config, [true, false], default: false
default_action :create
action :create do
config_resource = new_resource
with_run_context :root do
template config_resource.config_file do
cookbook config_resource.template_cookbook
source config_resource.template_source
mode '0644'
owner config_resource.user
group config_resource.group
variables(
global_config: config_resource.global_config,
jobs: {},
rule_filenames: config_resource.rule_filenames
)
not_if { config_resource.allow_external_config }
end
end
end
action :delete do
file new_resource.config_file do
action :delete
end
end
+98
View File
@@ -0,0 +1,98 @@
# frozen_string_literal: true
provides :prometheus_install
unified_mode true
use '_partial/_common'
use '_partial/_prometheus'
default_action :install
action_class do
include PrometheusCookbook::Helpers
end
action :install do
user new_resource.user do
system true
shell '/bin/false'
home new_resource.install_dir
not_if { new_resource.use_existing_user || new_resource.user == 'root' }
end
directory new_resource.install_dir do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
directory new_resource.log_dir do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
directory new_resource.storage_path do
owner new_resource.user
group new_resource.group
mode '0755'
recursive true
end
case new_resource.install_method
when 'binary'
package %w(tar bzip2)
ark install_dir_name(new_resource.install_dir) do
url new_resource.binary_url
checksum new_resource.checksum
version new_resource.version
prefix_root Chef::Config['file_cache_path']
path install_dir_parent(new_resource.install_dir)
owner new_resource.user
group new_resource.group
extension new_resource.file_extension unless new_resource.file_extension.empty?
action :put
end
when 'shell_binary'
package %w(tar bzip2)
remote_file "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}.tar.gz" do
source new_resource.binary_url
checksum new_resource.checksum
action :create
notifies :run, 'execute[install_prometheus_archive]', :immediately
end
execute 'install_prometheus_archive' do
command "tar -xzf #{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}.tar.gz -C #{new_resource.install_dir} --strip-components=1"
action :nothing
end
when 'source'
build_essential 'install compilation tools'
package %w(curl git-core mercurial gzip sed)
git "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}" do
repository new_resource.source_repository
revision new_resource.source_revision
action :checkout
end
bash 'compile_prometheus_source' do
cwd "#{Chef::Config[:file_cache_path]}/prometheus-#{new_resource.version}"
environment(
'PATH' => "/usr/local/go/bin:#{ENV.fetch('PATH', nil)}",
'GOPATH' => '/opt/go:/opt/go/src/github.com/prometheus/promu/vendor'
)
code <<~EOH
make build
mv prometheus #{new_resource.install_dir}
cp -R console_libraries #{new_resource.install_dir}
cp -R consoles #{new_resource.install_dir}
EOH
end
end
end
+41
View File
@@ -0,0 +1,41 @@
# frozen_string_literal: true
provides :prometheus_job
unified_mode true
property :scrape_interval, String
property :scrape_timeout, String
property :labels, Hash
property :target, [Array, String], required: true
property :metrics_path, String, default: '/metrics'
property :config_file, String, default: '/opt/prometheus/prometheus.yml'
property :allow_external_config, [true, false], default: false
default_action :create
action :create do
job_resource = new_resource
with_run_context :root do
edit_resource(:template, job_resource.config_file) do
variables[:jobs] ||= {}
variables[:jobs][job_resource.name] ||= {}
variables[:jobs][job_resource.name]['scrape_interval'] = job_resource.scrape_interval
variables[:jobs][job_resource.name]['scrape_timeout'] = job_resource.scrape_timeout
variables[:jobs][job_resource.name]['target'] = job_resource.target
variables[:jobs][job_resource.name]['metrics_path'] = job_resource.metrics_path
variables[:jobs][job_resource.name]['labels'] = job_resource.labels
action :nothing
delayed_action :create
not_if { job_resource.allow_external_config }
end
end
end
action :delete do
file new_resource.config_file do
action :delete
end
end
+56
View File
@@ -0,0 +1,56 @@
# frozen_string_literal: true
provides :prometheus_service
unified_mode true
use '_partial/_common'
use '_partial/_prometheus'
default_action :create
action_class do
include PrometheusCookbook::Helpers
end
action :create do
systemd_unit 'prometheus.service' do
content prometheus_unit_content(new_resource)
action [:create, :enable, :start]
end
end
action :enable do
systemd_unit 'prometheus.service' do
action :enable
end
end
action :start do
systemd_unit 'prometheus.service' do
action :start
end
end
action :restart do
systemd_unit 'prometheus.service' do
action :restart
end
end
action :reload do
systemd_unit 'prometheus.service' do
action :reload
end
end
action :stop do
systemd_unit 'prometheus.service' do
action [:stop, :disable]
end
end
action :delete do
systemd_unit 'prometheus.service' do
action [:stop, :disable, :delete]
end
end
@@ -0,0 +1,115 @@
global:
# The smarthost and SMTP sender used for mail notifications.
smtp_smarthost: 'localhost:25'
smtp_from: 'alertmanager@example.org'
# The root route on which each incoming alert enters.
route:
# The root route must not have any matchers as it is the entry point for
# all alerts. It needs to have a receiver configured so alerts that do not
# match any of the sub-routes are sent to someone.
receiver: 'team-X-mails'
# The labels by which incoming alerts are grouped together. For example,
# multiple alerts coming in for cluster=A and alertname=LatencyHigh would
# be batched into a single group.
group_by: ['alertname', 'cluster']
# When a new group of alerts is created by an incoming alert, wait at
# least 'group_wait' to send the initial notification.
# This way ensures that you get multiple alerts for the same group that start
# firing shortly after another are batched together on the first
# notification.
group_wait: 30s
# When the first notification was sent, wait 'group_interval' to send a batch
# of new alerts that started firing for that group.
group_interval: 5m
# If an alert has successfully been sent, wait 'repeat_interval' to
# resend them.
repeat_interval: 3h
# All the above attributes are inherited by all child routes and can
# overwritten on each.
# The child route trees.
routes:
# This routes performs a regular expression match on alert labels to
# catch alerts that are related to a list of services.
- match_re:
service: ^(foo1|foo2|baz)$
receiver: team-X-mails
# The service has a sub-route for critical alerts, any alerts
# that do not match, i.e. severity != critical, fall-back to the
# parent node and are sent to 'team-X-mails'
routes:
- match:
severity: critical
receiver: team-X-pager
- match:
service: files
receiver: team-Y-mails
routes:
- match:
severity: critical
receiver: team-Y-pager
# This route handles all alerts coming from a database service. If there's
# no team to handle it, it defaults to the DB team.
- match:
service: database
receiver: team-DB-pager
# Also group alerts by affected database.
group_by: [alertname, cluster, database]
routes:
- match:
owner: team-X
receiver: team-X-pager
- match:
owner: team-Y
receiver: team-Y-pager
# Inhibition rules allow to mute a set of alerts given that another alert is
# firing.
# We use this to mute any warning-level notifications if the same alert is
# already critical.
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
# Apply inhibition if the alertname is the same.
equal: ['alertname']
receivers:
- name: 'team-X-mails'
email_configs:
- to: 'team-X+alerts@example.org'
- name: 'team-X-pager'
email_configs:
- to: 'team-X+alerts-critical@example.org'
pagerduty_configs:
- service_key: <team-X-key>
- name: 'team-Y-mails'
email_configs:
- to: 'team-Y+alerts@example.org'
- name: 'team-Y-pager'
pagerduty_configs:
- service_key: <team-Y-key>
- name: 'team-DB-pager'
pagerduty_configs:
- service_key: <team-DB-key>
@@ -0,0 +1,33 @@
# Global default settings.
global:
<% @global_config.each do |k,v| %>
<%=k%>: "<%=v%>"
<% end %>
scrape_configs:
<% @jobs.each do |name, job| %>
- job_name: "<%= name %>"
<% if job['scrape_interval'] %>
scrape_interval: "<%= job['scrape_interval'] %>"
<% end %>
<% if job['scrape_timeout'] %>
scrape_timeout: "<%= job['scrape_timeout'] %>"
<% end %>
metrics_path: "<%= job['metrics_path'] %>"
static_configs:
- targets: <%= Array(job['target']) %>
<%if job['labels'] %>
labels:
<% job['labels'].each do |label,label_config| %>
<%=label%>: <%=label_config%>
<%end%>
<%end%>
<% end %>
<% if @rule_filenames %>
rule_files:
<% @rule_filenames.each do |filename| %>
- <%= filename %>
<% end %>
<% end %>