diff --git a/lc-gdn-chef/cookbooks/prometheus/.foodcritic b/lc-gdn-chef/cookbooks/prometheus/.foodcritic new file mode 100644 index 0000000000000000000000000000000000000000..847f0cb63723a093a615d16c6b51321d19432fed --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.foodcritic @@ -0,0 +1 @@ +~FC033 diff --git a/lc-gdn-chef/cookbooks/prometheus/.gitignore b/lc-gdn-chef/cookbooks/prometheus/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..024f1e115ac44d722f0e8dccf8d54fcc1288e89b --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.gitignore @@ -0,0 +1,21 @@ +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ +pkg/ + +# Berkshelf +.vagrant +/cookbooks +Berksfile.lock + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +.kitchen/ +.kitchen.local.yml +.idea diff --git a/lc-gdn-chef/cookbooks/prometheus/.hound.yml b/lc-gdn-chef/cookbooks/prometheus/.hound.yml new file mode 100644 index 0000000000000000000000000000000000000000..eddba4fa0b5467b41ca465f291e90f723ec93b05 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.hound.yml @@ -0,0 +1,8 @@ +ruby: + config_file: .rubocop.yml + +java_script: + enabled: false + +scss: + enabled: false diff --git a/lc-gdn-chef/cookbooks/prometheus/.kitchen.dokken.yml b/lc-gdn-chef/cookbooks/prometheus/.kitchen.dokken.yml new file mode 100644 index 0000000000000000000000000000000000000000..561d4bafee1b07b0d615df499649aa04395f6ca8 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.kitchen.dokken.yml @@ -0,0 +1,93 @@ +driver: + name: dokken + privileged: true # because Docker and SystemD/Upstart + chef_version: 12.21.31 + #chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> + +transport: + name: dokken + +provisioner: + name: dokken + data_path: test/shared + +verifier: + sudo: false + +platforms: + - name: ubuntu-14.04 + - name: ubuntu-16.04 + driver: + image: dokken/ubuntu-16.04 + pid_one_command: /bin/systemd + intermediate_instructions: + - RUN /usr/bin/apt-get update + - RUN /usr/bin/apt install sudo + # - name: debian-7.11 + # driver: + # cache_directory: false + - name: debian-8.7 + driver: + image: dokken/debian-8 + pid_one_command: /bin/systemd + - name: centos-6.9 + run_list: + - recipe[yum::default] + - name: centos-7.3 + run_list: + - recipe[yum::default] + +suites: + - name: default + run_list: + - recipe[prometheus::default] + - recipe[prometheus::alertmanager] + attributes: + prometheus: + install_method: 'binary' + alertmanager: + install_method: 'binary' + + - name: init-binary + run_list: + - recipe[prometheus::default] + attributes: + prometheus: + init_style: 'init' + install_method: 'binary' + flags: + storage.remote.timeout: 45s + + - name: default-source + run_list: + - recipe[prometheus::default] + attributes: + go: + gobin: '/usr/local/go/bin' + gopath: '/usr/local/go' + + - name: init + run_list: + - recipe[prometheus::default] + provisioner: + name: chef_zero + require_chef_omnibus: 11.12.4 + attributes: + prometheus: + init_style: 'init' + +# - name: bluepill +# run_list: +# - recipe[prometheus::default] +# attributes: +# prometheus: +# init_style: 'bluepill' + +# - name: bluepill-binary +# run_list: +# - recipe[prometheus::default] +# attributes: +# prometheus: +# init_style: 'bluepill' +# install_method: 'binary' + diff --git a/lc-gdn-chef/cookbooks/prometheus/.kitchen.yml b/lc-gdn-chef/cookbooks/prometheus/.kitchen.yml new file mode 100644 index 0000000000000000000000000000000000000000..e642e733c4b46560aa246b6095bca01eece82c66 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.kitchen.yml @@ -0,0 +1,75 @@ +driver: + name: vagrant + +provisioner: + name: chef_zero + data_path: test/shared + +platforms: + - name: ubuntu-14.04 + - name: ubuntu-16.04 + - name: debian-7.11 + driver: + cache_directory: false + - name: debian-8.7 + - name: centos-6.9 + run_list: + - recipe[yum::default] + - name: centos-7.3 + run_list: + - recipe[yum::default] + +suites: + - name: default + run_list: + - recipe[prometheus::default] + - recipe[prometheus::alertmanager] + attributes: + prometheus: + install_method: 'binary' + alertmanager: + install_method: 'binary' + + - name: init-binary + run_list: + - recipe[prometheus::default] + attributes: + prometheus: + init_style: 'init' + install_method: 'binary' + flags: + storage.remote.timeout: 45s + + - name: default-source + run_list: + - recipe[prometheus::default] + attributes: + go: + gobin: '/usr/local/go/bin' + gopath: '/usr/local/go' + + - name: init + run_list: + - recipe[prometheus::default] + provisioner: + name: chef_zero + require_chef_omnibus: 11.12.4 + attributes: + prometheus: + init_style: 'init' + +# - name: bluepill +# run_list: +# - recipe[prometheus::default] +# attributes: +# prometheus: +# init_style: 'bluepill' + +# - name: bluepill-binary +# run_list: +# - recipe[prometheus::default] +# attributes: +# prometheus: +# init_style: 'bluepill' +# install_method: 'binary' + diff --git a/lc-gdn-chef/cookbooks/prometheus/.rubocop.yml b/lc-gdn-chef/cookbooks/prometheus/.rubocop.yml new file mode 100644 index 0000000000000000000000000000000000000000..92b417ea8ca072229f16fe39e42b493242ed4933 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.rubocop.yml @@ -0,0 +1,37 @@ +AllCops: + Exclude: + - vendor/**/* + - .kitchen/**/* + - Vagrantfile + +ClassLength: + Enabled: false +Documentation: + Enabled: false +Encoding: + Enabled: false +LineLength: + Enabled: false +MethodLength: + Enabled: false +NumericLiterals: + Enabled: false +Style/StringLiterals: + Enabled: true + EnforcedStyle: single_quotes +Metrics/LineLength: + Enabled: false +Style/ExtraSpacing: + Enabled: false +Style/SpaceBeforeFirstArg: + Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false +Lint/AmbiguousBlockAssociation: + Enabled: false +Style/PercentLiteralDelimiters: + Enabled: false +Style/SymbolArray: + Enabled: false +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: no_comma diff --git a/lc-gdn-chef/cookbooks/prometheus/.travis.yml b/lc-gdn-chef/cookbooks/prometheus/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..4fcc2becc6a640cf92851751d462e6048e63454e --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/.travis.yml @@ -0,0 +1,24 @@ +dist: trusty +sudo: required +addons: + apt: + sources: + - chef-current-trusty + packages: + - chefdk + +# Don't `bundle install` +install: echo "skip bundle install" + +services: docker + +# Ensure we make ChefDK's Ruby the default +before_script: + - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER ) + - eval "$(chef shell-init bash)" + - chef --version + +script: + - cookstyle + - foodcritic . + - KITCHEN_LOCAL_YAML=.kitchen.dokken.yml chef exec kitchen verify diff --git a/lc-gdn-chef/cookbooks/prometheus/Berksfile b/lc-gdn-chef/cookbooks/prometheus/Berksfile new file mode 100644 index 0000000000000000000000000000000000000000..34fea2166bafb6b6a62488907c532a9d4692d35e --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/Berksfile @@ -0,0 +1,3 @@ +source 'https://supermarket.chef.io' + +metadata diff --git a/lc-gdn-chef/cookbooks/prometheus/CHANGELOG.md b/lc-gdn-chef/cookbooks/prometheus/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..d113da7721171e9719204aa80a3a8492fa24cab8 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/CHANGELOG.md @@ -0,0 +1,75 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +## [Unreleased][unreleased] + +### 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 + +[unreleased]: 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 diff --git a/lc-gdn-chef/cookbooks/prometheus/CONTRIBUTING.md b/lc-gdn-chef/cookbooks/prometheus/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..c12baec6366c4720eb683a65565d2386d0e3d4bd --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/CONTRIBUTING.md @@ -0,0 +1,51 @@ +Contributing to the prometheus Cookbook +========================================= +The prometheus cookbook uses [Github][] to triage, manage, and track issues and changes to the cookbook. + +Everybody is welcome to submit patches, but we ask you keep the following guidelines in mind: + +- [Coding Standards](#coding-standards) +- [Testing](#testing) + +Coding Standards +---------------- +The submitted code should be compatible with the standard Ruby coding guidelines. Here are some additional resources: + +- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) +- [GitHub Styleguide](https://github.com/styleguide/ruby) + +This cookbook is equipped with Rubocop, which will fail the build for violating these standards. + +Testing +------- +Whether your pull request is a bug fix or introduces new classes or methods to the project, we kindly ask that you +include tests for your changes. Even if it's just a small improvement, a test is necessary to ensure the bug is never +re-introduced. + +We understand that not all users are familiar with the testing ecosystem. This cookbook is fully-tested +using [Foodcritic](https://github.com/acrmp/foodcritic), +[Rubocop](https://github.com/bbatsov/rubocop), and [Test Kitchen](https://github.com/test-kitchen/test-kitchen) with +[Serverspec](https://github.com/serverspec/serverspec) bussers. + +Process +------- + +1. Clone the git repository from GitHub: + + $ git clone git@github.com:rayrod2030/chef-prometheus.git + +2. Make sure you have a sane [ChefDK][] development environment: + + $ chef version + +3. Make any changes +4. Write tests to support those changes. +5. Run the tests: + + $ kitchen verify + +6. Assuming the tests pass, commit your changes + +[ChefDK]: https://downloads.chef.io/chef-dk/ + +[github]: https://github.com/rayrod2030/chef-prometheus/issues diff --git a/lc-gdn-chef/cookbooks/prometheus/Gemfile b/lc-gdn-chef/cookbooks/prometheus/Gemfile new file mode 100644 index 0000000000000000000000000000000000000000..b59a528583e8634b00317b35d3c8e145d6770172 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/Gemfile @@ -0,0 +1,36 @@ +source 'https://rubygems.org' + +group :unit do + gem 'berkshelf', '~> 6.3.1' + gem 'chefspec', '~> 7.1.1' +end + +group :lint do + gem 'foodcritic', '~> 12.2.1' + gem 'rubocop', '~> 0.49.1' + gem 'cookstyle', '~> 2.1.0' +end + +group :kitchen_common do + gem 'test-kitchen', '~> 1.19.2' +end + +group :kitchen_docker do + gem 'kitchen-docker', '~> 2.6.0' +end + +group :kitchen_vagrant do + gem 'kitchen-vagrant', '~> 1.2.1' +end + +group :kitchen_cloud do + gem 'kitchen-ec2' +end + +group :integration do + gem 'serverspec' +end + +group :development do + gem 'rake' +end diff --git a/lc-gdn-chef/cookbooks/prometheus/ISSUES.md b/lc-gdn-chef/cookbooks/prometheus/ISSUES.md new file mode 100644 index 0000000000000000000000000000000000000000..36f81fc2ed302121f8c30ae547f1176f35eeb5f9 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/ISSUES.md @@ -0,0 +1,42 @@ +prometheus Cookbook Issues +============================ +This file documents the steps necessary to report any issue with the prometheus cookbook. Following these guidelines +will help ensure your issue is resolved in a timely manner. + +Reporting +--------- +When you report an issue, please include the following information: + +- A high-level overview of what you are trying to accomplish +- An [SSCCE](http://sscce.org/) +- The command you ran +- What you expected to happen +- What actually happened +- The exception backtrace(s), if any +- What operating system and version +- Everything output by running `env` +- What version of the cookbook are you using? +- What version of Ruby you are using (run `ruby -v`) +- What version of Rubygems you are using (run `gem -v`) +- What version of Chef you are using (run `knife -v`) + +Here's a snippet you can copy-paste into the issue and fill out: + +```text +(What is the issue? What are you trying to do? What happened?) + +- Command: `...` +- OS: +- Cookbook Version: +- Ruby Version: +- Rubygems Version: +- Chef Version: +- env: + ```text + # Paste your env here + ``` +- Backtrace: + ```text + # Paste backtrace here + ``` +``` diff --git a/lc-gdn-chef/cookbooks/prometheus/LICENSE b/lc-gdn-chef/cookbooks/prometheus/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..11069edd79019f7dafbe3138841cf289209270dd --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/LICENSE @@ -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. diff --git a/lc-gdn-chef/cookbooks/prometheus/README.md b/lc-gdn-chef/cookbooks/prometheus/README.md new file mode 100644 index 0000000000000000000000000000000000000000..63946999d89251453b36ea01bdf02f4987a7cb8f --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/README.md @@ -0,0 +1,176 @@ +prometheus Cookbook +===================== +[![Cookbook](http://img.shields.io/cookbook/v/prometheus.svg)](https://github.com/rayrod2030/chef-prometheus) +[![Build Status](https://travis-ci.org/elijah/chef-prometheus.svg?branch=master)](https://travis-ci.org/rayrod2030/chef-prometheus?branch=master) +[![Gitter chat](https://img.shields.io/badge/Gitter-rayrod2030%2Fchef--prometheus-brightgreen.svg)](https://gitter.im/rayrod2030/chef-prometheus) + +This cookbook installs the [Prometheus][] monitoring system and time-series database. + +Requirements +------------ + +- Chef 12 or higher +- Ruby 2.2 or higher + +Platform +-------- +Tested on + +* Ubuntu 14.04 +* Ubuntu 12.04 +* Debian 7.7 +* Centos 6.6 +* Centos 7.0 + +Attributes +---------- +In order to keep the README managable and in sync with the attributes, this cookbook documents attributes inline. The +usage instructions and default values for attributes can be found in the individual attribute files. + +Recipes +------- + +### default + +The `default` recipe installs creates all the default [Prometheus][] directories, config files and and users. Default +also calls the configured `install_method` +recipe and finally calls the prometheus `service` recipe. + +### source + +The `source` recipe builds Prometheus from a Github source tag. + +### binary + +The `binary` recipe retrieves and installs a pre-compiled Prometheus build from a user-defined location. + +### service + +The `service` recipe configures Prometheus to run under a process supervisor. Default supervisors are chosen based on +distribution. Currently supported supervisors are init, runit, systemd, upstart and bluepill. + +Resource/Provider +----------------- + +### prometheus_job + +This resource adds a job definition to the Prometheus config file. Here is an example of using this resource to define +the default Prometheus job: + +```ruby +prometheus_job 'prometheus' do + scrape_interval '15s' + target "http://localhost#{node['prometheus']['flags']['web.listen-address']}#{node['prometheus']['flags']['web.telemetry-path']}" +end +``` + +Note: This cookbook uses the accumulator pattern so you can define multiple prometheus_job’s and they will all be added +to the Prometheus config. + +Externally managing `prometheus.conf` +------------------------------------- + +If you prefer to manage your `prometheus.conf` file externally using your own inventory or service discovery mechanism +you can set +`default['prometheus']['allow_external_config']` to `true`. + +Dependencies +------------ + +The following cookbooks are dependencies: + +* [build-essential][] +* [apt][] +* [yum][] +* [runit][] +* [bluepill][] +* [accumulator][] +* [ark][] + +## Usage + +### prometheus::default + +Include `prometheus` in your node's `run_list` to execute the standard deployment of prometheus: + +```json +{ + "run_list": [ + "recipe[prometheus::default]" + ] +} +``` + +### prometheus::use_lwrp + +Used to load promethus cookbook from wrapper cookbook. + +`prometheus::use_lwrp` doesn't do anything other than allow you to include the Prometheus cookbook into your wrapper or +app cookbooks. Doing this allows you to override prometheus attributes and use the prometheus LWRP (`prometheus_job`) in +your wrapper cookbooks. + +```ruby +# Load the promethues cookbook into your wrapper so you have access to the LWRP and attributes + +include_recipe "prometheus::use_lwrp" + +# Add a rule filename under `rule_files` in prometheus.yml.erb +node.set['prometheus']['rule_filenames'] = ["#{node['prometheus']['dir']}/alert.rules"] + +# Example of using search to populate prometheus.yaml jobs using the prometheus_job LWRP +# Finds all the instances that are in the current environment and are taged with "node_exporter" +# Assumes that the service instances were tagged in their own recipes. +client_servers = search(:node, "environment:#{node.chef_environment} AND tags:node_exporter") + +# Assumes service_name is an attribute of each node +client_servers.each do |server| + prometheus_job server.service_name do + scrape_interval ‘15s’ + target “#{server.fqdn}#{node[‘prometheus’][‘flags’][‘web.listen-address’]}" + metrics_path "#{node[‘prometheus’][‘flags’][‘web.telemetry-path’]}” + end +end + +# Now run the default recipe that does all the work configuring and deploying prometheus +include_recipe "prometheus::default" +``` + +Development +----------- +Please see the [Contributing](CONTRIBUTING.md) and [Issue Reporting](ISSUES.md) Guidelines. + +License & Authors +------ + +- Author: Ray Rodriguez +- Author: kristian järvenpää + +```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. +``` + +[build-essential]: https://github.com/opscode-cookbooks/build-essential + +[apt]: https://github.com/opscode-cookbooks/apt + +[runit]: https://github.com/hw-cookbooks/runit + +[Prometheus]: https://github.com/prometheus/prometheus + +[bluepill]: https://github.com/opscode-cookbooks/bluepill + +[ark]: https://github.com/burtlo/ark + +[yum]: https://github.com/chef-cookbooks/yum + +[accumulator]: https://github.com/kisoku/chef-accumulator diff --git a/lc-gdn-chef/cookbooks/prometheus/Rakefile b/lc-gdn-chef/cookbooks/prometheus/Rakefile new file mode 100644 index 0000000000000000000000000000000000000000..c89ac58b334182eabbdf5d529194f080dd89ec4c --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/Rakefile @@ -0,0 +1,45 @@ +require 'bundler/setup' +require 'cookstyle' +require 'rubocop/rake_task' +require 'foodcritic' +require 'kitchen' +require 'rspec/core/rake_task' + +# Unit Tests. rspec/chefspec +RSpec::Core::RakeTask.new(:unit) + +# Style tests. Rubocop and Foodcritic +namespace :style do + desc 'Run Ruby style checks' + RuboCop::RakeTask.new(:ruby) + + desc 'Run Chef style checks' + FoodCritic::Rake::LintTask.new(:chef) do |t| + t.options = { + fail_tags: ['any'] + } + end +end + +desc 'Run all style checks' +task style: ['style:chef', 'style:ruby'] + +# Integration tests. Kitchen.ci +namespace :integration do + desc 'Run Test Kitchen with Vagrant' + task :vagrant do + Kitchen.logger = Kitchen.default_file_logger + Kitchen::Config.new.instances.each do |instance| + instance.test(:always) + end + end +end + +# We cannot run Test Kitchen on Travis CI yet... +namespace :travis do + desc 'Run tests on Travis' + task ci: %w(style unit) +end + +# The default rake task should just run it all +task default: ['travis:ci', 'integration'] diff --git a/lc-gdn-chef/cookbooks/prometheus/Thorfile b/lc-gdn-chef/cookbooks/prometheus/Thorfile new file mode 100644 index 0000000000000000000000000000000000000000..19aaaf2fdb2e82f9bd3a5b4d41911f677084e221 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/Thorfile @@ -0,0 +1,12 @@ +# encoding: utf-8 + +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 diff --git a/lc-gdn-chef/cookbooks/prometheus/Vagrantfile b/lc-gdn-chef/cookbooks/prometheus/Vagrantfile new file mode 100644 index 0000000000000000000000000000000000000000..d2c6b39da8b802623c55540e8051fa21747fb625 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/Vagrantfile @@ -0,0 +1,90 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! +VAGRANTFILE_API_VERSION = '2'.freeze + +Vagrant.require_version '>= 1.5.0' + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + # All Vagrant configuration is done here. The most common configuration + # options are documented and commented below. For a complete reference, + # please see the online documentation at vagrantup.com. + + config.vm.hostname = 'prometheus-berkshelf' + + # Set the version of chef to install using the vagrant-omnibus plugin + # NOTE: You will need to install the vagrant-omnibus plugin: + # + # $ vagrant plugin install vagrant-omnibus + # + if Vagrant.has_plugin?('vagrant-omnibus') + config.omnibus.chef_version = 'latest' + end + + # Every Vagrant virtual environment requires a box to build off of. + # If this value is a shorthand to a box in Vagrant Cloud then + # config.vm.box_url doesn't need to be specified. + config.vm.box = 'bento/ubuntu-14.04' + + # Assign this VM to a host-only network IP, allowing you to access it + # via the IP. Host-only networks can talk to the host machine as well as + # any other machines on the same network, but cannot be accessed (through this + # network interface) by any external networks. + config.vm.network :private_network, type: 'dhcp' + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider :virtualbox do |vb| + # # Don't boot with headless mode + # vb.gui = true + # + # # Use VBoxManage to customize the VM. For example to change memory: + # vb.customize ["modifyvm", :id, "--memory", "1024"] + # end + # + # View the documentation for the provider you're using for more + # information on available options. + + # The path to the Berksfile to use with Vagrant Berkshelf + # config.berkshelf.berksfile_path = "./Berksfile" + + # Enabling the Berkshelf plugin. To enable this globally, add this configuration + # option to your ~/.vagrant.d/Vagrantfile file + config.berkshelf.enabled = true + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to exclusively install and copy to Vagrant's shelf. + # config.berkshelf.only = [] + + # An array of symbols representing groups of cookbook described in the Vagrantfile + # to skip installing and copying to Vagrant's shelf. + # config.berkshelf.except = [] + + config.vm.provision :chef_solo do |chef| + chef.json = { + mysql: { + server_root_password: 'rootpass', + server_debian_password: 'debpass', + server_repl_password: 'replpass' + } + } + + chef.run_list = [ + 'recipe[prometheus::default]', + 'recipe[prometheus::alertmanager]' + ] + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/attributes/default.rb b/lc-gdn-chef/cookbooks/prometheus/attributes/default.rb new file mode 100644 index 0000000000000000000000000000000000000000..508620febfa5467e1b75aeddc3349e0c60332414 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/attributes/default.rb @@ -0,0 +1,274 @@ +# +# Cookbook Name:: prometheus +# Attributes:: default +# + +# Directory where the prometheus binary will be installed +default['prometheus']['dir'] = '/opt/prometheus' + +# Location of Prometheus binary +default['prometheus']['binary'] = "#{node['prometheus']['dir']}/prometheus" + +# Location of Prometheus pid file +default['prometheus']['pid'] = '/var/run/prometheus.pid' + +# Install method. Currently supports source, binary and shell_binary. +default['prometheus']['install_method'] = 'binary' + +# Init style. +# rubocop:disable Style/ConditionalAssignment +case node['platform_family'] +when 'debian' + if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 15.04 + default['prometheus']['init_style'] = 'upstart' + elsif node['platform'] == 'debian' && node['platform_version'].to_f < 8.0 + default['prometheus']['init_style'] = 'runit' + else + default['prometheus']['init_style'] = 'systemd' + end +when 'rhel', 'fedora' + if node['platform_version'].to_i >= 7 + default['prometheus']['init_style'] = 'systemd' + else + default['prometheus']['init_style'] = 'init' + end +else + default['prometheus']['init_style'] = 'init' +end +# rubocop:enable Style/ConditionalAssignment + +# Location for Prometheus logs +default['prometheus']['log_dir'] = '/var/log/prometheus' + +# Prometheus version to build +default['prometheus']['version'] = '2.2.1' + +# Prometheus source repository. +default['prometheus']['source']['git_repository'] = 'https://github.com/prometheus/prometheus.git' + +# Prometheus source repository git reference. Defaults to version tag. Can +# also be set to a branch or master. +default['prometheus']['source']['git_revision'] = "v#{node['prometheus']['version']}" + +# System user to use +default['prometheus']['user'] = 'prometheus' + +# System group to use +default['prometheus']['group'] = 'prometheus' + +# Set if you want ot use the root user +default['prometheus']['use_existing_user'] = false + +# Location for Prometheus pre-compiled binary. +# Default for testing purposes +default['prometheus']['binary_url'] = "https://github.com/prometheus/prometheus/releases/download/v#{node['prometheus']['version']}/prometheus-#{node['prometheus']['version']}.linux-amd64.tar.gz" + +# Checksum for pre-compiled binary +# Default for testing purposes +default['prometheus']['checksum'] = 'caddbbbe3ef8545c6cefb32f9a11207ae18dcc788e8d0fb19659d88c58d14b37' + +# If file extension of your binary can not be determined by the URL +# then define it here. Example 'tar.bz2' +default['prometheus']['file_extension'] = '' + +# Should we allow external config changes? +default['prometheus']['allow_external_config'] = false + +# Prometheus job configuration chef template name. +default['prometheus']['job_config_template_name'] = 'prometheus.yml.erb' + +# Prometheus custom configuration cookbook. Use this if you'd like to bypass the +# default prometheus cookbook job configuration template and implement your own +# templates and recipes to configure Prometheus jobs. +default['prometheus']['job_config_cookbook_name'] = 'prometheus' + +# FLAGS Section: Any attributes defined under the flags hash will be used to +# generate the command line flags for the Prometheus executable. + +# Prometheus configuration file name. + +default['prometheus']['v2_cli_flags'] = [ + 'web.enable-lifecycle' +] + +default['prometheus']['flags']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml" +default['prometheus']['v2_cli_opts']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml" + +# Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal, panic]. +default['prometheus']['flags']['log.level'] = 'info' +default['prometheus']['v2_cli_opts']['log.level'] = 'info' + +# Alert manager HTTP API timeout. +timeout_flag = Gem::Version.new(node['prometheus']['version']) <= Gem::Version.new('0.16.2') ? 'http-deadline' : 'timeout' +default['prometheus']['flags']["alertmanager.#{timeout_flag}"] = '10s' +default['prometheus']['v2_cli_opts']["alertmanager.#{timeout_flag}"] = '10s' + +# The capacity of the queue for pending alert manager notifications. +default['prometheus']['flags']['alertmanager.notification-queue-capacity'] = 100 +default['prometheus']['v2_cli_opts']['alertmanager.notification-queue-capacity'] = 100 + +# The URL of the alert manager to send notifications to. +default['prometheus']['flags']['alertmanager.url'] = 'http://127.0.0.1/alert-manager/' + +# Maximum number of queries executed concurrently. +default['prometheus']['flags']['query.max-concurrency'] = 20 +default['prometheus']['v2_cli_opts']['query.max-concurrency'] = 20 + +# Staleness delta allowance during expression evaluations. +default['prometheus']['flags']['query.staleness-delta'] = '5m' +default['prometheus']['v2_cli_opts']['query.lookback-delta'] = '5m' + +# Maximum time a query may take before being aborted. +default['prometheus']['flags']['query.timeout'] = '2m' +default['prometheus']['v2_cli_opts']['query.timeout'] = '2m' + +# If approx. that many time series are in a state that would require a recovery +# operation after a crash, a checkpoint is triggered, even if the checkpoint interval +# hasn't passed yet. A recovery operation requires a disk seek. The default limit +# intends to keep the recovery time below 1min even on spinning disks. With SSD, +# recovery is much faster, so you might want to increase this value in that case +# to avoid overly frequent checkpoints. +default['prometheus']['flags']['storage.local.checkpoint-dirty-series-limit'] = 5000 + +# The period at which the in-memory index of time series is checkpointed. +default['prometheus']['flags']['storage.local.checkpoint-interval'] = '5m' + +# If set, the local storage layer will perform crash recovery even if the last +# shutdown appears to be clean. +default['prometheus']['flags']['storage.local.dirty'] = false + +# The size in bytes for the fingerprint to metric index cache. +default['prometheus']['flags']['storage.local.index-cache-size.fingerprint-to-metric'] = 10485760 + +# The size in bytes for the metric time range index cache. +default['prometheus']['flags']['storage.local.index-cache-size.fingerprint-to-timerange'] = 5242880 + +# The size in bytes for the label name to label values index cache. +default['prometheus']['flags']['storage.local.index-cache-size.label-name-to-label-values'] = 10485760 + +# The size in bytes for the label pair to fingerprints index cache. +default['prometheus']['flags']['storage.local.index-cache-size.label-pair-to-fingerprints'] = 20971520 + +# How many chunks to keep in memory. While the size of a chunk is 1kiB, the total +# memory usage will be significantly higher than this value * 1kiB. Furthermore, +# for various reasons, more chunks might have to be kept in memory temporarily. +default['prometheus']['flags']['storage.local.memory-chunks'] = 1048576 + +# Base path for metrics storage. +default['prometheus']['flags']['storage.local.path'] = '/var/lib/prometheus' +default['prometheus']['v2_cli_opts']['storage.tsdb.path'] = '/var/lib/prometheus' + +# If set, a crash recovery will perform checks on each series file. This might take a very long time. +default['prometheus']['flags']['storage.local.pedantic-checks'] = false + +# How long to retain samples in the local storage. +default['prometheus']['flags']['storage.local.retention'] = '360h0m0s' +default['prometheus']['v2_cli_opts']['storage.tsdb.retention'] = '15d' + +# When to sync series files after modification. Possible values: +# 'never', 'always', 'adaptive'. Sync'ing slows down storage performance +# but reduces the risk of data loss in case of an OS crash. With the +# 'adaptive' strategy, series files are sync'd for as long as the storage +# is not too much behind on chunk persistence. +default['prometheus']['flags']['storage.local.series-sync-strategy'] = 'adaptive' + +# The URL of the remote InfluxDB server to send samples to. None, if empty. +default['prometheus']['flags']['storage.remote.influxdb-url'] = '' + +# The name of the database to use for storing samples in InfluxDB. +default['prometheus']['flags']['storage.remote.influxdb.database'] = 'prometheus' + +# The InfluxDB retention policy to use. +default['prometheus']['flags']['storage.remote.influxdb.retention-policy'] = 'default' + +# The URL of the OpenTSDB instance to send samples to. None, if empty. +default['prometheus']['flags']['storage.remote.opentsdb-url'] = '' + +# The timeout to use when sending samples to the remote storage. +default['prometheus']['flags']['storage.remote.timeout'] = '30s' + +# prometheus v2.x flags +default['prometheus']['flags']['storage.remote.timeout'] = '30s' + +# Path to the console library directory. +default['prometheus']['flags']['web.console.libraries'] = 'console_libraries' + +# Path to the console template directory, available at /console. +default['prometheus']['flags']['web.console.templates'] = 'consoles' + +# Enable remote service shutdown. +default['prometheus']['flags']['web.enable-remote-shutdown'] = false + +# The URL under which Prometheus is externally reachable (for +# example, if Prometheus is served via a reverse proxy). Used for +# generating relative and absolute links back to Prometheus itself. If +# omitted, relevant URL components will be derived automatically. +default['prometheus']['flags']['web.external-url'] = '' + +# Address to listen on for the web interface, API, and telemetry. +default['prometheus']['flags']['web.listen-address'] = ':9090' + +# Path under which to expose metrics. +default['prometheus']['flags']['web.telemetry-path'] = '/metrics' + +# Read assets/templates from file instead of binary. +# web.use-local-assets flag got removed in 0.17 +# https://github.com/prometheus/prometheus/commit/a542cc86096e1bad694e04d307301a807583dfc6 +if Gem::Version.new(node['prometheus']['version']) <= Gem::Version.new('0.16.2') + default['prometheus']['flags']['web.use-local-assets'] = false +end + +# Path to static asset directory, available at /user. +default['prometheus']['flags']['web.user-assets'] = '' + +# Alertmanager attributes + +# Install method. Currently supports source and binary. +default['prometheus']['alertmanager']['install_method'] = 'binary' + +# Location of Alertmanager binary +default['prometheus']['alertmanager']['binary'] = "#{node['prometheus']['dir']}/alertmanager" + +# Alertmanager version to build +default['prometheus']['alertmanager']['version'] = '0.14.0' + +# Alertmanager source repository. +default['prometheus']['alertmanager']['git_repository'] = 'https://github.com/prometheus/alertmanager.git' + +# Alertmanager source repository git reference. Defaults to version tag. Can +# also be set to a branch or master. +default['prometheus']['alertmanager']['git_revision'] = "v#{node['prometheus']['alertmanager']['version']}" + +# Location for Alertmanager pre-compiled binary. +# Default for testing purposes +default['prometheus']['alertmanager']['binary_url'] = "https://github.com/prometheus/alertmanager/releases/download/v#{node['prometheus']['alertmanager']['version']}/alertmanager-#{node['prometheus']['alertmanager']['version']}.linux-amd64.tar.gz" + +# Checksum for pre-compiled binary +# Default for testing purposes +default['prometheus']['alertmanager']['checksum'] = 'caddbbbe3ef8545c6cefb32f9a11207ae18dcc788e8d0fb19659d88c58d14b37' + +# If file extension of your binary can not be determined by the URL +# then define it here. Example 'tar.bz2' +default['prometheus']['alertmanager']['file_extension'] = '' + +# Alertmanager configuration file name. +default['prometheus']['alertmanager']['config.file'] = "#{node['prometheus']['dir']}/alertmanager.yml" + +# Alertmanager configuration storage directory +default['prometheus']['alertmanager']['storage.path'] = "#{node['prometheus']['dir']}/data" + +# Alertmanager configuration chef template name. +default['prometheus']['alertmanager']['config_cookbook_name'] = 'prometheus' + +# Alertmanager custom configuration cookbook. Use this if you'd like to bypass the +# default prometheus cookbook Alertmanager configuration template and implement your own +# templates and recipes to configure Alertmanager. +default['prometheus']['alertmanager']['config_template_name'] = 'alertmanager.yml.erb' + +# Array of alert rules filenames to be inserted in prometheus.yml.erb under "rule_files" +default['prometheus']['rule_filenames'] = nil + +default['prometheus']['alertmanager']['notification'] = {} + +default['prometheus']['global']['scrape_interval'] = '60s' +default['prometheus']['global']['evaluation_interval'] = '60s' diff --git a/lc-gdn-chef/cookbooks/prometheus/chefignore b/lc-gdn-chef/cookbooks/prometheus/chefignore new file mode 100644 index 0000000000000000000000000000000000000000..138a808b67633b24ad88bf2d33fafca5f30e8e16 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/chefignore @@ -0,0 +1,94 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING +CHANGELOG* + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/lc-gdn-chef/cookbooks/prometheus/libraries/prometheus_helper.rb b/lc-gdn-chef/cookbooks/prometheus/libraries/prometheus_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..bffb1059cd10e4e7826d29f36cc6c2155ae41ed0 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/libraries/prometheus_helper.rb @@ -0,0 +1,19 @@ + +def generate_flags + config = '' + if Gem::Version.new(node['prometheus']['version']) < Gem::Version.new('2.0.0-alpha.0') + # Generate cli opts for prometheus 1.x + node['prometheus']['flags'].each do |flag_key, flag_value| + config += "-#{flag_key}=#{flag_value} " if flag_value != '' + end + else + # Generate cli opts for prometheus 2.x & hopefully beyond if there are no changes + node['prometheus']['v2_cli_opts'].each do |opt_key, opt_value| + config += "--#{opt_key}=#{opt_value} " if opt_value != '' + end + node['prometheus']['v2_cli_flags'].each do |opt_flag| + config += "--#{opt_flag} " if opt_flag != '' + end + end + config +end diff --git a/lc-gdn-chef/cookbooks/prometheus/metadata.rb b/lc-gdn-chef/cookbooks/prometheus/metadata.rb new file mode 100644 index 0000000000000000000000000000000000000000..9c4a7d18a6528952fdf50403dc01ed9763c1bcb4 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/metadata.rb @@ -0,0 +1,25 @@ +name 'prometheus' +maintainer 'Elijah Wright' +maintainer_email 'elijah.wright@gmail.com' +license 'Apache-2.0' +description 'Installs/Configures Prometheus' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.6.5' +source_url 'https://github.com/elijah/chef-prometheus' +issues_url 'https://github.com/elijah/chef-prometheus/issues' +chef_version '>= 12.15.25', '< 14' if respond_to?(:chef_version) + +%w(ubuntu debian centos redhat fedora).each do |os| + supports os +end + +depends 'apt' +depends 'yum' +depends 'build-essential' +depends 'runit', '>= 1.5' +depends 'ark' +depends 'golang' +depends 'compat_resource' + +# this should really be a suggests +depends 'bluepill', '~> 2.3' diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager.rb new file mode 100644 index 0000000000000000000000000000000000000000..11fae346b8762eafc1cb795d4752b17756058325 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager.rb @@ -0,0 +1,141 @@ +# +# Cookbook Name:: prometheus +# Recipe:: alertmanager +# +# Author: Paul Magrath +# +# 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. +# + +include_recipe 'build-essential::default' + +user node['prometheus']['user'] do + system true + shell '/bin/false' + home node['prometheus']['dir'] + not_if { node['prometheus']['use_existing_user'] == true || node['prometheus']['user'] == 'root' } +end + +directory node['prometheus']['dir'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +directory node['prometheus']['log_dir'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +directory node['prometheus']['alertmanager']['storage.path'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +# -- Write our Config -- # + +template node['prometheus']['alertmanager']['config.file'] do + cookbook node['prometheus']['alertmanager']['config_cookbook_name'] + source node['prometheus']['alertmanager']['config_template_name'] + mode '0644' + owner node['prometheus']['user'] + group node['prometheus']['group'] + variables( + notification_config: node['prometheus']['alertmanager']['notification'] + ) + notifies :restart, 'service[alertmanager]' +end + +# -- Do the install -- # + +include_recipe "prometheus::alertmanager_#{node['prometheus']['alertmanager']['install_method']}" + +case node['prometheus']['init_style'] +when 'runit' + include_recipe 'runit::default' + + runit_service 'alertmanager' do + default_logger true + end +when 'bluepill' + include_recipe 'bluepill::default' + + template "#{node['bluepill']['conf_dir']}/alertmanager.pill" do + source 'alertmanager.pill.erb' + mode '0644' + end + + bluepill_service 'alertmanager' do + action [:enable, :load] + end +when 'systemd' + # rubocop:disable Style/HashSyntax + dist_dir, conf_dir, env_file = value_for_platform_family( + ['fedora'] => %w(fedora sysconfig alertmanager), + ['rhel'] => %w(redhat sysconfig alertmanager), + ['debian'] => %w(debian default alertmanager) + ) + + template '/etc/systemd/system/alertmanager.service' do + source 'systemd/alertmanager.service.erb' + mode '0644' + variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}") + notifies :restart, 'service[alertmanager]', :delayed + end + + template "/etc/#{conf_dir}/#{env_file}" do + source "#{dist_dir}/#{conf_dir}/alertmanager.erb" + mode '0644' + notifies :restart, 'service[alertmanager]', :delayed + end + + service 'alertmanager' do + supports :status => true, :restart => true + action [:enable, :start] + end + # rubocop:enable Style/HashSyntax +when 'upstart' + template '/etc/init/alertmanager.conf' do + source 'upstart/alertmanager.service.erb' + mode '0644' + notifies :restart, 'service[alertmanager]', :delayed + end + + service 'alertmanager' do + provider Chef::Provider::Service::Upstart + action [:enable, :start] + end +else + template '/etc/init.d/alertmanager' do + source 'alertmanager.erb' + owner 'root' + group node['root_group'] + mode '0755' + notifies :restart, 'service[alertmanager]', :delayed + end +end + +# rubocop:disable Style/HashSyntax +service 'alertmanager' do + supports :status => true, :restart => true, :reload => true +end +# rubocop:enable Style/HashSyntax + +service 'alertmanager' do + action [:enable, :start] +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_binary.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_binary.rb new file mode 100644 index 0000000000000000000000000000000000000000..26cc2b665e221a3b36f3de03da02e857aa0757eb --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_binary.rb @@ -0,0 +1,39 @@ +# +# Cookbook Name:: prometheus +# Recipe:: alertmanager_binary +# +# Author: Javier Zunzunegui +# +# 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. +# + +include_recipe 'ark::default' + +%w(curl tar bzip2).each do |pkg| + package pkg +end + +dir_name = ::File.basename(node['prometheus']['dir']) +dir_path = ::File.dirname(node['prometheus']['dir']) + +ark dir_name do + url node['prometheus']['alertmanager']['binary_url'] + checksum node['prometheus']['alertmanager']['checksum'] + version node['prometheus']['alertmanager']['version'] + prefix_root Chef::Config['file_cache_path'] + path dir_path + owner node['prometheus']['user'] + group node['prometheus']['group'] + extension node['prometheus']['alertmanager']['file_extension'] unless node['prometheus']['alertmanager']['file_extension'].empty? + action :put +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_source.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_source.rb new file mode 100644 index 0000000000000000000000000000000000000000..8d9e4545d2f6a03eca90a0ca30ef259ca15bd904 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/alertmanager_source.rb @@ -0,0 +1,36 @@ +# +# Cookbook Name:: prometheus +# Recipe:: alertmanager_source +# +# Author: Javier Zunzunegui +# +# 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. +# + +# These packages are needed go build +%w(curl git-core mercurial gzip sed).each do |pkg| + package pkg +end + +git "#{Chef::Config[:file_cache_path]}/alertmanager-#{node['prometheus']['alertmanager']['version']}" do + repository node['prometheus']['alertmanager']['git_repository'] + revision node['prometheus']['alertmanager']['git_revision'] + action :checkout +end + +bash 'compile_alertmanager_source' do + cwd "#{Chef::Config[:file_cache_path]}/alertmanager-#{node['prometheus']['alertmanager']['version']}" + code "make && mv alertmanager #{node['prometheus']['dir']}" + + notifies :restart, 'service[alertmanager]' +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/binary.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/binary.rb new file mode 100644 index 0000000000000000000000000000000000000000..1ee606a843e240205f0758572aae7c5e3974c1f0 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/binary.rb @@ -0,0 +1,39 @@ +# +# Cookbook Name:: prometheus +# Recipe:: binary +# +# Author: Kristian Jarvenpaa +# +# 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. +# + +include_recipe 'ark::default' + +%w(curl tar bzip2).each do |pkg| + package pkg +end + +dir_name = ::File.basename(node['prometheus']['dir']) +dir_path = ::File.dirname(node['prometheus']['dir']) + +ark dir_name do + url node['prometheus']['binary_url'] + checksum node['prometheus']['checksum'] + version node['prometheus']['version'] + prefix_root Chef::Config['file_cache_path'] + path dir_path + owner node['prometheus']['user'] + group node['prometheus']['group'] + extension node['prometheus']['file_extension'] unless node['prometheus']['file_extension'].empty? + action :put +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/default.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/default.rb new file mode 100644 index 0000000000000000000000000000000000000000..5ef9dd2b23b6a7d0a2c4d3d73d358e024c021265 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/default.rb @@ -0,0 +1,75 @@ +# +# Cookbook Name:: prometheus +# Recipe:: default +# +# Author: Ray Rodriguez +# +# 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. +# +user node['prometheus']['user'] do + system true + shell '/bin/false' + home node['prometheus']['dir'] + not_if { node['prometheus']['use_existing_user'] == true || node['prometheus']['user'] == 'root' } +end + +directory node['prometheus']['dir'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +directory node['prometheus']['log_dir'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +directory node['prometheus']['flags']['storage.local.path'] do + owner node['prometheus']['user'] + group node['prometheus']['group'] + mode '0755' + recursive true +end + +apt_update 'please' +# Ensure that any unpacking of prometheus doesn't blow away our own configuration +include_recipe "prometheus::#{node['prometheus']['install_method']}" + +# -- Write our Config -- # + +template node['prometheus']['flags']['config.file'] do + action :nothing + cookbook node['prometheus']['job_config_cookbook_name'] + source node['prometheus']['job_config_template_name'] + mode '0644' + owner node['prometheus']['user'] + group node['prometheus']['group'] + variables( + rule_filenames: node['prometheus']['rule_filenames'] + ) + notifies :reload, 'service[prometheus]' +end + +# monitor our server instance +prometheus_job 'prometheus' do + scrape_interval '15s' + target "localhost#{node['prometheus']['flags']['web.listen-address']}" + metrics_path node['prometheus']['flags']['web.telemetry-path'] +end + +# -- Do the install -- # + +include_recipe 'prometheus::service' diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/service.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/service.rb new file mode 100644 index 0000000000000000000000000000000000000000..7ff84e89ea0cdc3ee6705d56de36e590d7d66558 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/service.rb @@ -0,0 +1,87 @@ +# +# Cookbook Name:: prometheus +# Recipe:: service +# +# 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. +# + +case node['prometheus']['init_style'] +when 'runit' + include_recipe 'runit::default' + + runit_service 'prometheus' do + default_logger true + end +when 'bluepill' + include_recipe 'bluepill::default' + + template "#{node['bluepill']['conf_dir']}/prometheus.pill" do + source 'prometheus.pill.erb' + mode '0644' + end + + bluepill_service 'prometheus' do + action [:enable, :load] + end +when 'systemd' + # rubocop:disable Style/HashSyntax + dist_dir, conf_dir, env_file = value_for_platform_family( + ['fedora'] => %w(fedora sysconfig prometheus), + ['rhel'] => %w(redhat sysconfig prometheus), + ['debian'] => %w(debian default prometheus) + ) + + template '/etc/systemd/system/prometheus.service' do + source 'systemd/prometheus.service.erb' + mode '0644' + variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}") + notifies :restart, 'service[prometheus]', :delayed + end + + template "/etc/#{conf_dir}/#{env_file}" do + source "#{dist_dir}/#{conf_dir}/prometheus.erb" + mode '0644' + notifies :restart, 'service[prometheus]', :delayed + end + + service 'prometheus' do + supports :status => true, :restart => true + action [:enable, :start] + end + # rubocop:enable Style/HashSyntax +when 'upstart' + template '/etc/init/prometheus.conf' do + source 'upstart/prometheus.service.erb' + mode '0644' + notifies :restart, 'service[prometheus]', :delayed + end + + service 'prometheus' do + provider Chef::Provider::Service::Upstart + action [:enable, :start] + end +else + template '/etc/init.d/prometheus' do + source 'prometheus.erb' + owner 'root' + group node['root_group'] + mode '0755' + notifies :restart, 'service[prometheus]', :delayed + end +end + +# rubocop:disable Style/HashSyntax +service 'prometheus' do + supports :status => true, :restart => true, :reload => true +end +# rubocop:enable Style/HashSyntax diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/shell_binary.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/shell_binary.rb new file mode 100644 index 0000000000000000000000000000000000000000..cceaa9a22a80caebf62591a250f9d2987d62885f --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/shell_binary.rb @@ -0,0 +1,40 @@ +# +# Cookbook Name:: prometheus +# Recipe:: shell_binary +# +# Author: Rohit Gupta - @rohit01 +# +# This recipie is similar to binary.rb without 'ark' dependency +# + +%w(curl tar bzip2).each do |pkg| + package pkg +end + +bash 'download_prometheus' do + code <<-EOH + pfilename="#{Chef::Config[:file_cache_path]}/prometheus-#{node['prometheus']['version']}.tar.gz" + curl -L -o "${pfilename}" "#{node['prometheus']['binary_url']}" + chksum="$(shasum -b -a 256 ${pfilename} | awk '{print $1}')" + if [ "${chksum}" != "#{node['prometheus']['checksum']}" ]; then + echo "ERROR: Downloaded file checksum mismatch. Aborting!" + exit 1 + fi + EOH + user 'root' + group 'root' + creates "#{Chef::Config[:file_cache_path]}/prometheus-#{node['prometheus']['version']}.tar.gz" + action :run + notifies :run, 'bash[install_prometheus]', :immediately +end + +bash 'install_prometheus' do + code <<-EOH + mkdir -p "#{node['prometheus']['dir']}" + tar -xzf "#{Chef::Config[:file_cache_path]}/prometheus-#{node['prometheus']['version']}.tar.gz" -C "#{node['prometheus']['dir']}" --strip-components=1 + EOH + user 'root' + group 'root' + action :nothing + notifies :restart, 'service[prometheus]' +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/source.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/source.rb new file mode 100644 index 0000000000000000000000000000000000000000..c6f8a021f1c3a00c96adc5d855f8113fea481d3a --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/source.rb @@ -0,0 +1,45 @@ +# +# Cookbook Name:: prometheus +# Recipe:: default +# +# Author: Ray Rodriguez +# +# 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. +# + +include_recipe 'build-essential::default' +include_recipe 'golang::default' + +# These packages are needed go build +%w(curl git-core mercurial gzip sed).each do |pkg| + package pkg +end + +git "#{Chef::Config[:file_cache_path]}/prometheus-#{node['prometheus']['version']}" do + repository node['prometheus']['source']['git_repository'] + revision node['prometheus']['source']['git_revision'] + action :checkout +end + +bash 'compile_prometheus_source' do + cwd "#{Chef::Config[:file_cache_path]}/prometheus-#{node['prometheus']['version']}" + environment 'PATH' => "/usr/local/go/bin:#{ENV['PATH']}", 'GOPATH' => "/opt/go:#{node['go']['gopath']}:/opt/go/src/github.com/prometheus/promu/vendor" + code <<-EOH + make build && + mv prometheus #{node['prometheus']['dir']} && + cp -R console_libraries #{node['prometheus']['dir']} && + cp -R consoles #{node['prometheus']['dir']} + EOH + + notifies :restart, 'service[prometheus]' +end diff --git a/lc-gdn-chef/cookbooks/prometheus/recipes/use_lwrp.rb b/lc-gdn-chef/cookbooks/prometheus/recipes/use_lwrp.rb new file mode 100644 index 0000000000000000000000000000000000000000..101d5337288c1e33158264e21d71380ca5094e22 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/recipes/use_lwrp.rb @@ -0,0 +1,30 @@ +# +# Cookbook Name:: prometheus +# Recipe:: use_lwrp +# +# Author: Robert Berger +# +# 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. +# + +# This recipe does nothing, allows you to `include_recipe "prometheus::use_lwrp"` +# so you can override attributes and use the LWRP[s] in a wrapper cookbook. +# Then `include_recipe "prometheus::default"` to actually install and configure prometheus. + +# New workflow: +# - Create wrapper cookbook that +# - `include_recipe "prometheus::use_lwrp" +# - Collects any jobs / targets, +# - Use prometheus_job to create the jobs +# - Override any needed attributes +# - `include_recipe "prometheus::default` diff --git a/lc-gdn-chef/cookbooks/prometheus/resources/job.rb b/lc-gdn-chef/cookbooks/prometheus/resources/job.rb new file mode 100644 index 0000000000000000000000000000000000000000..d9d47aa3f24ff714ef2eb75b479e4511a2a00392 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/resources/job.rb @@ -0,0 +1,33 @@ +property :scrape_interval, String +property :scrape_timeout, String +property :labels, Hash +property :target, [Array, String] +property :metrics_path, String, default: '/metrics' +property :config_file, String, default: lazy { node['prometheus']['flags']['config.file'] } + +default_action :create + +action :create do + with_run_context :root do + edit_resource(:template, config_file) do |new_resource| + variables[:jobs] ||= {} + variables[:jobs][new_resource.name] ||= {} + variables[:jobs][new_resource.name]['scrape_interval'] = new_resource.scrape_interval + variables[:jobs][new_resource.name]['scrape_timeout'] = new_resource.scrape_timeout + variables[:jobs][new_resource.name]['target'] = new_resource.target + variables[:jobs][new_resource.name]['metrics_path'] = new_resource.metrics_path + variables[:jobs][new_resource.name]['labels'] = new_resource.labels + + action :nothing + delayed_action :create + + not_if { node['prometheus']['allow_external_config'] } + end + end +end + +action :delete do + template config_file do + action :delete + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/spec/spec_helper.rb b/lc-gdn-chef/cookbooks/prometheus/spec/spec_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..b640ebaa930a92161ed4a15d5fddf28bcd2c71b4 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'chefspec' +require 'chefspec/berkshelf' +require_relative 'support/matchers' + +RSpec.configure do |config| + # No WARN messages during testing + config.log_level = :error +end + +ChefSpec::Coverage.start! diff --git a/lc-gdn-chef/cookbooks/prometheus/spec/support/matchers.rb b/lc-gdn-chef/cookbooks/prometheus/spec/support/matchers.rb new file mode 100644 index 0000000000000000000000000000000000000000..22df5a768de710fb08bd9553714d018536fc38c4 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/spec/support/matchers.rb @@ -0,0 +1,4 @@ + +def put_ark(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:ark, :put, resource_name) +end diff --git a/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/alertmanager_spec.rb b/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/alertmanager_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..9063c0e3f7275c5750fc61214f8ac82e9bcde8cc --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/alertmanager_spec.rb @@ -0,0 +1,303 @@ +# +# Filename:: alertmanager_spec.rb +# Description:: Verifies alertmanager recipe(s). +# +# Author: Elijah Caine +# + +require 'spec_helper' + +# Caution: This is a carbon-copy of default_spec.rb with some variable replacements. + +describe 'prometheus::alertmanager' do + let(:chef_run) do + ChefSpec::SoloRunner.new( + platform: 'ubuntu', + version: '16.04', + file_cache_path: '/tmp/chef/cache' + ).converge(described_recipe) + end + + before do + stub_command('/usr/local/go/bin/go version | grep "go1.5 "').and_return(0) + end + + it 'creates a user with correct attributes' do + expect(chef_run).to create_user('prometheus').with( + system: true, + shell: '/bin/false', + home: '/opt/prometheus' + ) + end + + it 'creates a directory at /opt/prometheus' do + expect(chef_run).to create_directory('/opt/prometheus').with( + owner: 'prometheus', + group: 'prometheus', + mode: '0755', + recursive: true + ) + end + + it 'creates a directory at /var/log/prometheus' do + expect(chef_run).to create_directory('/var/log/prometheus').with( + owner: 'prometheus', + group: 'prometheus', + mode: '0755', + recursive: true + ) + end + + it 'renders a prometheus job configuration file and notifies prometheus to restart' do + resource = chef_run.template('/opt/prometheus/alertmanager.yml') + expect(resource).to notify('service[alertmanager]').to(:restart) + end + + # Test for source.rb + + context 'source' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['alertmanager']['version'] = '0.14.0' + node.set['prometheus']['alertmanager']['install_method'] = 'source' + end.converge(described_recipe) + end + + it 'includes build-essential' do + expect(chef_run).to include_recipe('build-essential::default') + end + + %w(curl git-core mercurial gzip sed).each do |pkg| + it 'installs #{pkg}' do + expect(chef_run).to install_package(pkg) + end + end + + it 'checks out alertmanager from github' do + expect(chef_run).to checkout_git("#{Chef::Config[:file_cache_path]}/alertmanager-0.14.0").with( + repository: 'https://github.com/prometheus/alertmanager.git', + revision: 'v0.14.0' + ) + end + + it 'compiles alertmanager source' do + expect(chef_run).to run_bash('compile_alertmanager_source') + end + + it 'notifies alertmanager to restart' do + resource = chef_run.bash('compile_alertmanager_source') + expect(resource).to notify('service[alertmanager]').to(:restart) + end + + context 'runit' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'runit' + end.converge(described_recipe) + end + + it 'includes runit::default recipe' do + expect(chef_run).to include_recipe('runit::default') + end + + it 'enables runit_service' do + expect(chef_run).to enable_runit_service('alertmanager') + end + end + + context 'bluepill' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'bluepill' + end.converge(described_recipe) + end + + it 'includes bluepill::default recipe' do + expect(chef_run).to include_recipe('bluepill::default') + end + + it 'renders a bluepill configuration file' do + expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/alertmanager.pill") + end + end + + context 'init' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'init' + end.converge(described_recipe) + end + + it 'renders an init.d configuration file' do + expect(chef_run).to render_file('/etc/init.d/alertmanager') + end + end + + context 'systemd' do + unit_file = '/etc/systemd/system/alertmanager.service' + + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'systemd' + node.set['prometheus']['user'] = 'prom_user' + node.set['prometheus']['group'] = 'prom_group' + node.set['prometheus']['alertmanager']['binary'] = '/tmp/alertmanager' + node.set['prometheus']['alertmanager']['storage.path'] = '/tmp/alertmanager_data' + node.set['prometheus']['alertmanager']['config.file'] = '/tmp/alertmanager.conf' + node.set['prometheus']['flags']['alertmanager.url'] = 'http://0.0.0.0:8080' + end.converge(described_recipe) + end + + it 'renders a systemd service file' do + expect(chef_run).to render_file(unit_file) + end + + it 'renders systemd unit with custom variables' do + expect(chef_run).to render_file(unit_file).with_content { |content| + expect(content).to include('ExecStart=/tmp/alertmanager') + expect(content).to include('-storage.path=/tmp/alertmanager_data \\') + expect(content).to include('-config.file=/tmp/alertmanager.conf \\') + expect(content).to include('-web.external-url=http://0.0.0.0:8080') + expect(content).to include('User=prom_user') + expect(content).to include('Group=prom_group') + } + end + end + + context 'upstart' do + job_file = '/etc/init/alertmanager.conf' + + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + node.set['prometheus']['user'] = 'prom_user' + node.set['prometheus']['group'] = 'prom_group' + node.set['prometheus']['alertmanager']['binary'] = '/tmp/alertmanager' + node.set['prometheus']['alertmanager']['storage.path'] = '/tmp/alertmanager_data' + node.set['prometheus']['alertmanager']['config.file'] = '/tmp/alertmanager.conf' + node.set['prometheus']['flags']['alertmanager.url'] = 'http://0.0.0.0:8080' + node.set['prometheus']['log_dir'] = '/tmp' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file(job_file) + end + + it 'renders an upstart job configuration with custom variables' do + expect(chef_run).to render_file(job_file).with_content { |content| + expect(content).to include('setuid prom_user') + expect(content).to include('setgid prom_group') + expect(content).to include('exec >> "/tmp/alertmanager.log"') + expect(content).to include('exec /tmp/alertmanager') + expect(content).to include('-storage.path=/tmp/alertmanager_data') + expect(content).to include('-config.file=/tmp/alertmanager.conf') + expect(content).to include('-web.external-url=http://0.0.0.0:8080') + } + end + end + end + + # Test for binary.rb + + context 'binary' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['alertmanager']['version'] = '0.14.0' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'runs ark with correct attributes' do + expect(chef_run).to put_ark('prometheus').with( + url: 'https://github.com/prometheus/alertmanager/releases/download/v0.14.0/alertmanager-0.14.0.linux-amd64.tar.gz', + checksum: 'caddbbbe3ef8545c6cefb32f9a11207ae18dcc788e8d0fb19659d88c58d14b37', + version: '0.14.0', + prefix_root: Chef::Config['file_cache_path'], + path: '/opt', + owner: 'prometheus', + group: 'prometheus' + ) + end + + it 'runs ark with given file_extension' do + chef_run.node.set['prometheus']['alertmanager']['file_extension'] = 'tar.gz' + chef_run.converge(described_recipe) + expect(chef_run).to put_ark('prometheus').with( + extension: 'tar.gz' + ) + end + + context 'runit' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'runit' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'includes runit::default recipe' do + expect(chef_run).to include_recipe('runit::default') + end + + it 'enables runit_service' do + expect(chef_run).to enable_runit_service('alertmanager') + end + end + + context 'bluepill' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'bluepill' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'includes bluepill::default recipe' do + expect(chef_run).to include_recipe('bluepill::default') + end + + it 'renders a bluepill configuration file' do + expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/alertmanager.pill") + end + end + + context 'init' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'init' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders an init.d configuration file' do + expect(chef_run).to render_file('/etc/init.d/alertmanager') + end + end + + context 'systemd' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'systemd' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders a systemd service file' do + expect(chef_run).to render_file('/etc/systemd/system/alertmanager.service') + end + end + context 'upstart' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + node.set['prometheus']['alertmanager']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file('/etc/init/alertmanager.conf') + end + end + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/default_spec.rb b/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..aa83a3272711d07d9f7f9dabfe3bcac2d33bb98c --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/spec/unit/recipes/default_spec.rb @@ -0,0 +1,261 @@ +require 'spec_helper' + +describe 'prometheus::default' do + let(:chef_run) do + ChefSpec::SoloRunner.new( + platform: 'ubuntu', + version: '16.04', + file_cache_path: '/tmp/chef/cache', + step_into: ['prometheus_job'] + ).converge(described_recipe) + end + + before do + stub_command('/usr/local/go/bin/go version | grep "go1.5 "').and_return(0) + end + + it 'creates a user with correct attributes' do + expect(chef_run).to create_user('prometheus').with( + system: true, + shell: '/bin/false', + home: '/opt/prometheus' + ) + end + + it 'creates a directory at /opt/prometheus' do + expect(chef_run).to create_directory('/opt/prometheus').with( + owner: 'prometheus', + group: 'prometheus', + mode: '0755', + recursive: true + ) + end + + it 'creates a directory at /var/log/prometheus' do + expect(chef_run).to create_directory('/var/log/prometheus').with( + owner: 'prometheus', + group: 'prometheus', + mode: '0755', + recursive: true + ) + end + + it 'renders a prometheus job configuration file and notifies prometheus to reload' do + resource = chef_run.template('/opt/prometheus/prometheus.yml') + expect(resource).to notify('service[prometheus]').to(:reload) + end + + it 'uses an attribute to select the prometheus.yml template' do + chef_run.node.override['prometheus']['job_config_cookbook_name'] = 'other_cookbook' + chef_run.converge(described_recipe) + expect(chef_run).to create_template('/opt/prometheus/prometheus.yml').with_cookbook('other_cookbook') + end + + # Test for source.rb + + context 'source' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['version'] = '2.2.1' + node.set['prometheus']['install_method'] = 'source' + end.converge(described_recipe) + end + + it 'includes build-essential' do + expect(chef_run).to include_recipe('build-essential::default') + end + + %w(curl git-core mercurial gzip sed).each do |pkg| + it 'installs #{pkg}' do + expect(chef_run).to install_package(pkg) + end + end + + it 'checks out prometheus from github' do + expect(chef_run).to checkout_git("#{Chef::Config[:file_cache_path]}/prometheus-2.2.1").with( + repository: 'https://github.com/prometheus/prometheus.git', + revision: 'v2.2.1' + ) + end + + it 'compiles prometheus source' do + expect(chef_run).to run_bash('compile_prometheus_source') + end + + it 'notifies prometheus to reload' do + resource = chef_run.bash('compile_prometheus_source') + expect(resource).to notify('service[prometheus]').to(:restart) + end + + context 'runit' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'runit' + end.converge(described_recipe) + end + + it 'includes runit::default recipe' do + expect(chef_run).to include_recipe('runit::default') + end + + it 'enables runit_service' do + expect(chef_run).to enable_runit_service('prometheus') + end + end + + context 'bluepill' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'bluepill' + end.converge(described_recipe) + end + + it 'includes bluepill::default recipe' do + expect(chef_run).to include_recipe('bluepill::default') + end + + it 'renders a bluepill configuration file' do + expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/prometheus.pill") + end + end + + context 'init' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'init' + end.converge(described_recipe) + end + + it 'renders an init.d configuration file' do + expect(chef_run).to render_file('/etc/init.d/prometheus') + end + end + + context 'systemd' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'systemd' + end.converge(described_recipe) + end + + it 'renders a systemd service file' do + expect(chef_run).to render_file('/etc/systemd/system/prometheus.service') + end + end + + context 'upstart' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file('/etc/init/prometheus.conf') + end + end + end + + # Test for binary.rb + + context 'binary' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['version'] = '2.2.1' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'runs ark with correct attributes' do + expect(chef_run).to put_ark('prometheus').with( + url: 'https://github.com/prometheus/prometheus/releases/download/v2.2.1/prometheus-2.2.1.linux-amd64.tar.gz', + checksum: 'caddbbbe3ef8545c6cefb32f9a11207ae18dcc788e8d0fb19659d88c58d14b37', + version: '2.2.1', + prefix_root: Chef::Config['file_cache_path'], + path: '/opt', + owner: 'prometheus', + group: 'prometheus' + ) + end + + it 'runs ark with given file_extension' do + chef_run.node.set['prometheus']['file_extension'] = 'tar.gz' + chef_run.converge(described_recipe) + expect(chef_run).to put_ark('prometheus').with( + extension: 'tar.gz' + ) + end + + context 'runit' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'runit' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'includes runit::default recipe' do + expect(chef_run).to include_recipe('runit::default') + end + + it 'enables runit_service' do + expect(chef_run).to enable_runit_service('prometheus') + end + end + + context 'bluepill' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'bluepill' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'includes bluepill::default recipe' do + expect(chef_run).to include_recipe('bluepill::default') + end + + it 'renders a bluepill configuration file' do + expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/prometheus.pill") + end + end + + context 'init' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'init' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders an init.d configuration file' do + expect(chef_run).to render_file('/etc/init.d/prometheus') + end + end + + context 'systemd' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'systemd' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders a systemd service file' do + expect(chef_run).to render_file('/etc/systemd/system/prometheus.service') + end + end + context 'upstart' do + let(:chef_run) do + ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/var/chef/cache') do |node| + node.set['prometheus']['init_style'] = 'upstart' + node.set['prometheus']['install_method'] = 'binary' + end.converge(described_recipe) + end + + it 'renders an upstart job configuration file' do + expect(chef_run).to render_file('/etc/init/prometheus.conf') + end + end + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/centos/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/centos/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..9e670e57aeec73dff636cabe9e8aac77d983fabe --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/centos/prometheus.erb @@ -0,0 +1,155 @@ +#!/bin/sh +# Init script for prometheus +# Maintained by +# Generated by pleaserun. +# Implemented based on LSB Core 3.1: +# * Sections: 20.2, 20.3 +# +### BEGIN INIT INFO +# Provides: prometheus +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: +# Description: no description given +### END INIT INFO + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +export PATH + +name=$(basename $0) +program="<%= node['prometheus']['binary'] %>" +args="<%= generate_flags %>" +pidfile=<%= node['prometheus']['pid'] %> +user=<%= node['prometheus']['source']['user'] %> +group=<%= node['prometheus']['source']['group'] %> +chroot="/" +chdir="/" + +[ -r /etc/default/$name ] && . /etc/default/$name +[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name + +trace() { + logger -t "/etc/init.d/prometheus" "$@" +} + +emit() { + trace "$@" + echo "$@" +} + +start() { + + + # Setup any environmental stuff beforehand + + + # Run the program! + + chroot --userspec "$user":"$group" "$chroot" sh -c " + + cd \"$chdir\" + exec \"$program\" $args + " >> <%= "#{node['prometheus']['log_dir']}/prometheus.log" %> 2>&1 & + + # Generate the pidfile from here. If we instead made the forked process + # generate it there will be a race condition between the pidfile writing + # and a process possibly asking for status. + echo $! > $pidfile + + emit "$name started" + return 0 +} + +stop() { + # Try a few times to kill TERM the program + if status ; then + pid=$(cat "$pidfile") + trace "Killing $name (pid $pid) with SIGTERM" + kill -TERM $pid + # Wait for it to exit. + for i in 1 2 3 4 5 ; do + trace "Waiting $name (pid $pid) to die..." + status || break + sleep 1 + done + if status ; then + emit "$name stop failed; still running." + else + emit "$name stopped." + fi + fi +} + +status() { + if [ -f "$pidfile" ] ; then + pid=$(cat "$pidfile") + if ps -p $pid > /dev/null 2> /dev/null ; then + # process by this pid is running. + # It may not be our pid, but that's what you get with just pidfiles. + # TODO(sissel): Check if this process seems to be the same as the one we + # expect. It'd be nice to use flock here, but flock uses fork, not exec, + # so it makes it quite awkward to use in this case. + return 0 + else + return 2 # program is dead but pid file exists + fi + else + return 3 # program is not running + fi +} + +force_stop() { + if status ; then + stop + status && kill -KILL $(cat "$pidfile") + fi +} + + +case "$1" in + force-start|start|stop|force-stop|restart) + trace "Attempting '$1' on prometheus" + ;; +esac + +case "$1" in + force-start) + PRESTART=no + exec "$0" start + ;; + start) + status + code=$? + if [ $code -eq 0 ]; then + emit "$name is already running" + exit $code + else + start + exit $? + fi + ;; + stop) stop ;; + force-stop) force_stop ;; + status) + status + code=$? + if [ $code -eq 0 ] ; then + emit "$name is running" + else + emit "$name is not running" + fi + exit $code + ;; + restart) + + stop && start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|force-start|force-stop|status|restart}" >&2 + exit 3 + ;; +esac + +exit $? diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/debian/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/debian/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..9e670e57aeec73dff636cabe9e8aac77d983fabe --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/debian/prometheus.erb @@ -0,0 +1,155 @@ +#!/bin/sh +# Init script for prometheus +# Maintained by +# Generated by pleaserun. +# Implemented based on LSB Core 3.1: +# * Sections: 20.2, 20.3 +# +### BEGIN INIT INFO +# Provides: prometheus +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: +# Description: no description given +### END INIT INFO + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +export PATH + +name=$(basename $0) +program="<%= node['prometheus']['binary'] %>" +args="<%= generate_flags %>" +pidfile=<%= node['prometheus']['pid'] %> +user=<%= node['prometheus']['source']['user'] %> +group=<%= node['prometheus']['source']['group'] %> +chroot="/" +chdir="/" + +[ -r /etc/default/$name ] && . /etc/default/$name +[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name + +trace() { + logger -t "/etc/init.d/prometheus" "$@" +} + +emit() { + trace "$@" + echo "$@" +} + +start() { + + + # Setup any environmental stuff beforehand + + + # Run the program! + + chroot --userspec "$user":"$group" "$chroot" sh -c " + + cd \"$chdir\" + exec \"$program\" $args + " >> <%= "#{node['prometheus']['log_dir']}/prometheus.log" %> 2>&1 & + + # Generate the pidfile from here. If we instead made the forked process + # generate it there will be a race condition between the pidfile writing + # and a process possibly asking for status. + echo $! > $pidfile + + emit "$name started" + return 0 +} + +stop() { + # Try a few times to kill TERM the program + if status ; then + pid=$(cat "$pidfile") + trace "Killing $name (pid $pid) with SIGTERM" + kill -TERM $pid + # Wait for it to exit. + for i in 1 2 3 4 5 ; do + trace "Waiting $name (pid $pid) to die..." + status || break + sleep 1 + done + if status ; then + emit "$name stop failed; still running." + else + emit "$name stopped." + fi + fi +} + +status() { + if [ -f "$pidfile" ] ; then + pid=$(cat "$pidfile") + if ps -p $pid > /dev/null 2> /dev/null ; then + # process by this pid is running. + # It may not be our pid, but that's what you get with just pidfiles. + # TODO(sissel): Check if this process seems to be the same as the one we + # expect. It'd be nice to use flock here, but flock uses fork, not exec, + # so it makes it quite awkward to use in this case. + return 0 + else + return 2 # program is dead but pid file exists + fi + else + return 3 # program is not running + fi +} + +force_stop() { + if status ; then + stop + status && kill -KILL $(cat "$pidfile") + fi +} + + +case "$1" in + force-start|start|stop|force-stop|restart) + trace "Attempting '$1' on prometheus" + ;; +esac + +case "$1" in + force-start) + PRESTART=no + exec "$0" start + ;; + start) + status + code=$? + if [ $code -eq 0 ]; then + emit "$name is already running" + exit $code + else + start + exit $? + fi + ;; + stop) stop ;; + force-stop) force_stop ;; + status) + status + code=$? + if [ $code -eq 0 ] ; then + emit "$name is running" + else + emit "$name is not running" + fi + exit $code + ;; + restart) + + stop && start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|force-start|force-stop|status|restart}" >&2 + exit 3 + ;; +esac + +exit $? diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.init.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.init.erb new file mode 100644 index 0000000000000000000000000000000000000000..1bf205d3675b596b8c58154a83a6b49cf8f94743 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.init.erb @@ -0,0 +1,2 @@ +# We should fill this in with a generic init file for alertmanager. +# diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.pill.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.pill.erb new file mode 100644 index 0000000000000000000000000000000000000000..1fbde1f0a47746822dc46e99138bd9643696b69f --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.pill.erb @@ -0,0 +1,14 @@ + +Bluepill.application('alertmanager') do |app| + app.process('alertmanager') do |process| + process.pid_file = "<%= node['prometheus']['pid'] %>" + process.working_dir = "<%= node['prometheus']['dir'] %>" + process.start_command = "<%= node['prometheus']['alertmanager']['binary'] %> -log.level=debug \ + -storage.path="<%= node['prometheus']['dir'] %>/data" \ + -config.file="<%= node['prometheus']['alertmanager']['config.file'] %>" \ + -web.external-url="<%= node['prometheus']['flags']['alertmanager.url'] %>" + process.environment = {'GOMAXPROCS' => <%= node['cpu']['total'] %>} + process.stdout = process.stderr = "<%= node['prometheus']['log_dir'] %>/alertmanager.log" + process.daemonize = true + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.yml.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.yml.erb new file mode 100644 index 0000000000000000000000000000000000000000..949efac1323051c96e931aee24ebdfbb89e3291c --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/alertmanager.yml.erb @@ -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: + +- name: 'team-Y-mails' + email_configs: + - to: 'team-Y+alerts@example.org' + +- name: 'team-Y-pager' + pagerduty_configs: + - service_key: + +- name: 'team-DB-pager' + pagerduty_configs: + - service_key: + diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/alertmanager.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/alertmanager.erb new file mode 100644 index 0000000000000000000000000000000000000000..27eca88db52dd6156738759edd02f8178ce6146a --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/alertmanager.erb @@ -0,0 +1,3 @@ +# Configuration file for the alertmanager service + +GOMAXPROCS=<%= node['cpu']['total'] %> diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..523b1543e5f2b7a9c1735f25d633a3a1af03e503 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/debian/default/prometheus.erb @@ -0,0 +1,3 @@ +# Configuration file for the prometheus service + +GOMAXPROCS=<%= node['cpu']['total'] %> diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.pill.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.pill.erb new file mode 100644 index 0000000000000000000000000000000000000000..ad5d72d003145af54155d9a0c69665cf1b49184c --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.pill.erb @@ -0,0 +1,11 @@ + +Bluepill.application('prometheus') do |app| + app.process('prometheus') do |process| + process.pid_file = "<%= node['prometheus']['pid'] %>" + process.working_dir = "<%= node['prometheus']['dir'] %>" + process.start_command = "<%= node['prometheus']['binary'] %> <%= generate_flags %>" + process.environment = {'GOMAXPROCS' => <%= node['cpu']['total'] %>} + process.stdout = process.stderr = "<%= node['prometheus']['log_dir'] %>/prometheus.log" + process.daemonize = true + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.yml.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.yml.erb new file mode 100644 index 0000000000000000000000000000000000000000..b42804b02c37758c039724860d226ea2d1b6e187 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/prometheus.yml.erb @@ -0,0 +1,34 @@ +# Global default settings. +global: + <%node['prometheus']['global'].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 %> + diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/alertmanager.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/alertmanager.erb new file mode 100644 index 0000000000000000000000000000000000000000..27eca88db52dd6156738759edd02f8178ce6146a --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/alertmanager.erb @@ -0,0 +1,3 @@ +# Configuration file for the alertmanager service + +GOMAXPROCS=<%= node['cpu']['total'] %> diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..523b1543e5f2b7a9c1735f25d633a3a1af03e503 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/redhat/sysconfig/prometheus.erb @@ -0,0 +1,3 @@ +# Configuration file for the prometheus service + +GOMAXPROCS=<%= node['cpu']['total'] %> diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/sv-prometheus-run.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/sv-prometheus-run.erb new file mode 100644 index 0000000000000000000000000000000000000000..93f22fc1eac109362ce419ca13ed86f7ccef2b39 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/sv-prometheus-run.erb @@ -0,0 +1,5 @@ +#!/bin/sh + +exec 2>&1 +export GOMAXPROCS=<%= node['cpu']['total'] %> +exec <%= node['prometheus']['binary'] %> <%= generate_flags %> diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/alertmanager.service.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/alertmanager.service.erb new file mode 100644 index 0000000000000000000000000000000000000000..8fa25fe257af8bd4306bc5031036165c0a1d7fde --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/alertmanager.service.erb @@ -0,0 +1,16 @@ +[Unit] +Description=Prometheus Alertmanager +After=network.target + +[Service] +ExecStart=<%= node['prometheus']['alertmanager']['binary'] %> \ + --log.level=debug \ + --storage.path=<%= node['prometheus']['alertmanager']['storage.path'] %> \ + --config.file=<%= node['prometheus']['alertmanager']['config.file'] %> \ + --web.external-url=<%= node['prometheus']['flags']['alertmanager.url'] %> +User=<%= node['prometheus']['user'] %> +Group=<%= node['prometheus']['group'] %> +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/prometheus.service.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/prometheus.service.erb new file mode 100644 index 0000000000000000000000000000000000000000..43e7b9f46a45cf38f222492e3bf6fc27bb2267ef --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/systemd/prometheus.service.erb @@ -0,0 +1,15 @@ +[Unit] +Description=Prometheus +After=network.target auditd.service + +[Service] +Type=simple +EnvironmentFile=<%= @sysconfig_file %> +User=<%= node['prometheus']['user'] %> +Group=<%= node['prometheus']['group'] %> +ExecStart=<%= node['prometheus']['binary'] %> <%= generate_flags %> +ExecReload=/bin/kill -HUP $MAINPID +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/alertmanager.service.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/alertmanager.service.erb new file mode 100644 index 0000000000000000000000000000000000000000..d64776706c0788bfeaa92785a56b91cdebbdb6fd --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/alertmanager.service.erb @@ -0,0 +1,14 @@ +description "Prometheus Alertmanager" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +env GOMAXPROCS=<%= node['cpu']['total'] %> +setuid <%= node['prometheus']['user'] %> +setgid <%= node['prometheus']['group'] %> + +script + exec >> "<%= node['prometheus']['log_dir'] %>/alertmanager.log" + exec 2>&1 + exec <%= node['prometheus']['alertmanager']['binary'] %> -config.file=<%= node['prometheus']['alertmanager']['config.file'] %> -storage.path=<%= node['prometheus']['alertmanager']['storage.path'] %> -web.external-url=<%= node['prometheus']['flags']['alertmanager.url'] %> +end script diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/prometheus.service.erb b/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/prometheus.service.erb new file mode 100644 index 0000000000000000000000000000000000000000..f8ee88f8184ef1ff77434e557f51a7c4e0ce1a42 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/default/upstart/prometheus.service.erb @@ -0,0 +1,15 @@ +description "Prometheus" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +env GOMAXPROCS=<%= node['cpu']['total'] %> +setuid <%= node['prometheus']['user'] %> +setgid <%= node['prometheus']['user'] %> + +script + chdir <%= node['prometheus']['dir'] %> + exec >> "<%= node['prometheus']['log_dir'] %>/prometheus.log" + exec 2>&1 + exec <%= node['prometheus']['binary'] %> <%= generate_flags %> +end script diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/redhat/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/redhat/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..9e670e57aeec73dff636cabe9e8aac77d983fabe --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/redhat/prometheus.erb @@ -0,0 +1,155 @@ +#!/bin/sh +# Init script for prometheus +# Maintained by +# Generated by pleaserun. +# Implemented based on LSB Core 3.1: +# * Sections: 20.2, 20.3 +# +### BEGIN INIT INFO +# Provides: prometheus +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: +# Description: no description given +### END INIT INFO + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +export PATH + +name=$(basename $0) +program="<%= node['prometheus']['binary'] %>" +args="<%= generate_flags %>" +pidfile=<%= node['prometheus']['pid'] %> +user=<%= node['prometheus']['source']['user'] %> +group=<%= node['prometheus']['source']['group'] %> +chroot="/" +chdir="/" + +[ -r /etc/default/$name ] && . /etc/default/$name +[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name + +trace() { + logger -t "/etc/init.d/prometheus" "$@" +} + +emit() { + trace "$@" + echo "$@" +} + +start() { + + + # Setup any environmental stuff beforehand + + + # Run the program! + + chroot --userspec "$user":"$group" "$chroot" sh -c " + + cd \"$chdir\" + exec \"$program\" $args + " >> <%= "#{node['prometheus']['log_dir']}/prometheus.log" %> 2>&1 & + + # Generate the pidfile from here. If we instead made the forked process + # generate it there will be a race condition between the pidfile writing + # and a process possibly asking for status. + echo $! > $pidfile + + emit "$name started" + return 0 +} + +stop() { + # Try a few times to kill TERM the program + if status ; then + pid=$(cat "$pidfile") + trace "Killing $name (pid $pid) with SIGTERM" + kill -TERM $pid + # Wait for it to exit. + for i in 1 2 3 4 5 ; do + trace "Waiting $name (pid $pid) to die..." + status || break + sleep 1 + done + if status ; then + emit "$name stop failed; still running." + else + emit "$name stopped." + fi + fi +} + +status() { + if [ -f "$pidfile" ] ; then + pid=$(cat "$pidfile") + if ps -p $pid > /dev/null 2> /dev/null ; then + # process by this pid is running. + # It may not be our pid, but that's what you get with just pidfiles. + # TODO(sissel): Check if this process seems to be the same as the one we + # expect. It'd be nice to use flock here, but flock uses fork, not exec, + # so it makes it quite awkward to use in this case. + return 0 + else + return 2 # program is dead but pid file exists + fi + else + return 3 # program is not running + fi +} + +force_stop() { + if status ; then + stop + status && kill -KILL $(cat "$pidfile") + fi +} + + +case "$1" in + force-start|start|stop|force-stop|restart) + trace "Attempting '$1' on prometheus" + ;; +esac + +case "$1" in + force-start) + PRESTART=no + exec "$0" start + ;; + start) + status + code=$? + if [ $code -eq 0 ]; then + emit "$name is already running" + exit $code + else + start + exit $? + fi + ;; + stop) stop ;; + force-stop) force_stop ;; + status) + status + code=$? + if [ $code -eq 0 ] ; then + emit "$name is running" + else + emit "$name is not running" + fi + exit $code + ;; + restart) + + stop && start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|force-start|force-stop|status|restart}" >&2 + exit 3 + ;; +esac + +exit $? diff --git a/lc-gdn-chef/cookbooks/prometheus/templates/ubuntu/prometheus.erb b/lc-gdn-chef/cookbooks/prometheus/templates/ubuntu/prometheus.erb new file mode 100644 index 0000000000000000000000000000000000000000..9e670e57aeec73dff636cabe9e8aac77d983fabe --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/templates/ubuntu/prometheus.erb @@ -0,0 +1,155 @@ +#!/bin/sh +# Init script for prometheus +# Maintained by +# Generated by pleaserun. +# Implemented based on LSB Core 3.1: +# * Sections: 20.2, 20.3 +# +### BEGIN INIT INFO +# Provides: prometheus +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: +# Description: no description given +### END INIT INFO + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +export PATH + +name=$(basename $0) +program="<%= node['prometheus']['binary'] %>" +args="<%= generate_flags %>" +pidfile=<%= node['prometheus']['pid'] %> +user=<%= node['prometheus']['source']['user'] %> +group=<%= node['prometheus']['source']['group'] %> +chroot="/" +chdir="/" + +[ -r /etc/default/$name ] && . /etc/default/$name +[ -r /etc/sysconfig/$name ] && . /etc/sysconfig/$name + +trace() { + logger -t "/etc/init.d/prometheus" "$@" +} + +emit() { + trace "$@" + echo "$@" +} + +start() { + + + # Setup any environmental stuff beforehand + + + # Run the program! + + chroot --userspec "$user":"$group" "$chroot" sh -c " + + cd \"$chdir\" + exec \"$program\" $args + " >> <%= "#{node['prometheus']['log_dir']}/prometheus.log" %> 2>&1 & + + # Generate the pidfile from here. If we instead made the forked process + # generate it there will be a race condition between the pidfile writing + # and a process possibly asking for status. + echo $! > $pidfile + + emit "$name started" + return 0 +} + +stop() { + # Try a few times to kill TERM the program + if status ; then + pid=$(cat "$pidfile") + trace "Killing $name (pid $pid) with SIGTERM" + kill -TERM $pid + # Wait for it to exit. + for i in 1 2 3 4 5 ; do + trace "Waiting $name (pid $pid) to die..." + status || break + sleep 1 + done + if status ; then + emit "$name stop failed; still running." + else + emit "$name stopped." + fi + fi +} + +status() { + if [ -f "$pidfile" ] ; then + pid=$(cat "$pidfile") + if ps -p $pid > /dev/null 2> /dev/null ; then + # process by this pid is running. + # It may not be our pid, but that's what you get with just pidfiles. + # TODO(sissel): Check if this process seems to be the same as the one we + # expect. It'd be nice to use flock here, but flock uses fork, not exec, + # so it makes it quite awkward to use in this case. + return 0 + else + return 2 # program is dead but pid file exists + fi + else + return 3 # program is not running + fi +} + +force_stop() { + if status ; then + stop + status && kill -KILL $(cat "$pidfile") + fi +} + + +case "$1" in + force-start|start|stop|force-stop|restart) + trace "Attempting '$1' on prometheus" + ;; +esac + +case "$1" in + force-start) + PRESTART=no + exec "$0" start + ;; + start) + status + code=$? + if [ $code -eq 0 ]; then + emit "$name is already running" + exit $code + else + start + exit $? + fi + ;; + stop) stop ;; + force-stop) force_stop ;; + status) + status + code=$? + if [ $code -eq 0 ] ; then + emit "$name is running" + else + emit "$name is not running" + fi + exit $code + ;; + restart) + + stop && start + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|force-start|force-stop|status|restart}" >&2 + exit 3 + ;; +esac + +exit $? diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/alertmanager/serverspec/default_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/alertmanager/serverspec/default_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..ceb8a0fba8135e3d38fa6681178f4425d0f4bb95 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/alertmanager/serverspec/default_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'alertmanager service' do + describe service('alertmanager') do + it { should be_running } + end + + describe port(9093) do + it { should be_listening.with('tcp') } + end +end + +describe 'alertmanger should be exposing metrics' do + describe command("curl 'http://localhost:9093/#/alerts/'") do + its(:stdout) { should include('Alertmanager') } + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill-binary/serverspec/binary_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill-binary/serverspec/binary_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..95956e9762929a1fc5c52b09b5381169c4ac6d72 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill-binary/serverspec/binary_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe command('/opt/chef/embedded/bin/bluepill status prometheus') do + its(:stdout) { should match(/up/) } + end + + describe port(9090) do + it { should be_listening } + end + + describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill/serverspec/source_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill/serverspec/source_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..6cdbf3a7eead0875a135151a36a6713d22aec9c8 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/bluepill/serverspec/source_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe command('/opt/chef/embedded/bin/bluepill status prometheus') do + its(:stdout) { should match(/up/) } + end + + describe port(9090) do + it { should be_listening } + end +end + +describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/default-binary/serverspec/binary_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/default-binary/serverspec/binary_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..a31c61417162984e84da6950d3837fecf9986344 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/default-binary/serverspec/binary_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe service('prometheus') do + it { should be_running } + end + + describe port(9090) do + it { should be_listening } + end + + describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/default/serverspec/source_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/default/serverspec/source_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..4ba8302c69856f8c6a137fc16e040de6df91ce44 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/default/serverspec/source_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe service('prometheus') do + it { should be_running } + end + + describe port(9090) do + it { should be_listening } + end +end + +describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/init-binary/serverspec/binary_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/init-binary/serverspec/binary_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..e0ff2c03edd04d00238691b3001095e0968799fe --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/init-binary/serverspec/binary_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe command('/etc/init.d/prometheus status') do + its(:stdout) { should match(/prometheus is running/) } + end + + describe port(9090) do + it { should be_listening } + end + + describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/integration/init/serverspec/source_spec.rb b/lc-gdn-chef/cookbooks/prometheus/test/integration/init/serverspec/source_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..05c422acebb5b2473e825fb18a1b75222721b809 --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/integration/init/serverspec/source_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../../kitchen/data/spec_helper' + +describe 'prometheus service' do + describe command('/etc/init.d/prometheus status') do + its(:stdout) { should match(/prometheus is running/) } + end + + describe port(9090) do + it { should be_listening } + end +end + +describe 'prometheus should be exposing metrics' do + describe command("curl 'http://localhost:9090/metrics'") do + its(:stdout) { should match(/prometheus_notifications_queue_capacity 100/) } + end +end diff --git a/lc-gdn-chef/cookbooks/prometheus/test/shared/spec_helper.rb b/lc-gdn-chef/cookbooks/prometheus/test/shared/spec_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..071e57fc4c88f98fbce503cbdc7aa8914ef2479f --- /dev/null +++ b/lc-gdn-chef/cookbooks/prometheus/test/shared/spec_helper.rb @@ -0,0 +1,12 @@ +require 'serverspec' + +# Required by serverspec +set :backend, :exec + +Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require_relative(file) } + +RSpec.configure do |config| + config.before(:all) do + config.path = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' + end +end