Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Statsd Exporter, Mysqld Exporter, make exporters generic #27

Merged
merged 37 commits into from
Dec 27, 2016

Conversation

lswith
Copy link
Contributor

@lswith lswith commented Nov 17, 2016

Add a statsd exporter to the mix

@oliver006
Copy link

@brutus333 - any chance this will be merged? I'd love to use this module to install the statsd_exporter and this would come in super handy.

@lswith
Copy link
Contributor Author

lswith commented Dec 12, 2016

I actually need to update this quite a bit. I've updated everything to use a daemon resource. It allows for every prometheus exporter to be added easily.

@brutus333
Copy link
Collaborator

In this case, I'll wait a bit for your changes. Did you generalize the exporter support?

@lswith
Copy link
Contributor Author

lswith commented Dec 12, 2016 via email

@brutus333
Copy link
Collaborator

It is looking very good at first glance but I need to test it a bit; even if each exporter needs code duplication, we can get rid of too many templates issue. One idea to go even further would be to have a defined type for exporters and applying individual values for each type of exported but the hard thing is to add custom parameters for exporters (e.g. my.cnf for mysql exporter). Something similar with keyword arguments in Python would help.
Thank you so much for your contribution, please redo the pull request with the newest additions.

@oliver006
Copy link

Thanks guys, this all sounds great, especially being able to add more exporters in a more modular way.
I added the memcached exporter in my repo and will add the redis exporter soon. Once this here is merged I'll open a PR.

@lswith lswith changed the title Add Statsd exporter Add Statsd Exporter, Mysqld Exporter, make exporters generic Dec 13, 2016
default => undef,
}

$extra_statsd_maps = hiera_array('prometheus::statsd_exporter::statsd_maps')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add [] as the default?

@@ -0,0 +1,8 @@
<% @real_statsd_maps.each do |metric| -%>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to real_statsd_maps.sort.each ?
Old Ruby versions have a bug where the order is not deterministic and it triggers the service restart on each run even if the data didn't change.

Copy link
Collaborator

@brutus333 brutus333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment in the README file regarding the breaking change for the alertmanager: since the name of the alertmanager service is changing from alert_manager, the user should be warned.
One solution is to stop and erase the alert_manager service before upgrading.

Copy link
Collaborator

@brutus333 brutus333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add changes to daemon.pp to comply with #30
They are right about the location of systemd files.
Thank you

@lswith
Copy link
Contributor Author

lswith commented Dec 14, 2016

It could be hard to delete the old alertmanager completely, however stopping it should at least happen so that they don't clash.

Copy link
Collaborator

@brutus333 brutus333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you deleted these parameters. They are used in manifests.

@lswith
Copy link
Contributor Author

lswith commented Dec 14, 2016 via email

<% @real_statsd_maps.sort.each do |metric| -%>
<%= metric['map'] %>
name="<%= metric['name'] %>"
<% metric['labels'].each do |key, value| -%>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot to mention to also add a sort here as well.

@brutus333
Copy link
Collaborator

I found two additional issues:

  1. this code from alertmanager class vanished unfortunately in daemon implemnetation:
    if $::prometheus::alert_manager::storage_path { file { $::prometheus::alert_manager::storage_path: ensure => 'directory', owner => $::prometheus::alert_manager::user, group => $::prometheus::alert_manager::group, mode => '0755', }
    Due to this issue, the alert_manager service will not start.
  2. $user and $group parameters are duplicated in the daemon defined type definition.

Please fix; I tested with these changes and it looks fine.

@@ -0,0 +1,61 @@
GEM

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should commit this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add Gemfile.lock to .gitignore

@@ -0,0 +1,12 @@
test.dispatcher.*.*.*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of this configuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the default supplied by the statsd_exporter

@@ -0,0 +1,242 @@
# Class: prometheus::mysqld_exporter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for renaming prometheus::alert_manager to prometheus::alertmanager? This is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of the binary and package is alertmanager not alert_manager. This was to keep consistency and allows for easier use of the daemon.pp.

@@ -0,0 +1,8 @@
<% @real_statsd_maps.sort_by!{ |metric| metric[:name] }.each do |metric| -%>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you can just use sort_by instead of sort_by

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand.

<% metric['labels'].sort.each do |key, value| -%>
<%= key %>="<%= value %>"
<% end -%>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this blank line is redundant given that the previous line ends with -%>

#
# Daemonize the prometheus node exporter
# Daemonize the prometheus <%= @name %>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be "Prometheus <%= @name %> exporter"

# pidfile: /var/run/node_exporter/pidfile
# description: Prometheus Exporter <%= @name %>
# processname: <%= @name %>
# pidfile: /var/run/<%= @name %>/pidfile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to /var/run/<%= @name %>/<%= @name %>.pid for consistency with Upstart?

DAEMON=<%= scope.lookupvar('prometheus::node_exporter::bin_dir') %>/node_exporter
PID_FILE=/var/run/node_exporter/node_exporter.pid
LOG_FILE=/var/log/node_exporter
DAEMON=<%= @bin_dir %>/<%= @name %>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This <%= @bin_dir %>/<%= @name %> logic is repeated in different template files. I think that you should define this value as a Puppet variable instead.


[ -e /etc/sysconfig/node_exporter ] && . /etc/sysconfig/node_exporter
[ -e /etc/sysconfig/<%= @name %> ] && . /etc/sysconfig/<%= @name %>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think /etc/sysconfig is a RedHat thing? This should read from /etc/default for Debian systems.

[Service]
User=<%= @user %>
Group=<%= @group %>
ExecStart=<%= @bin_dir %>/<%= @name %> <%= @options %>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, you should read the options from the defaults file. Like this:

EnvironmentFile=/etc/default/<%= @name %>
ExecStart=<%= @bin_dir %>/<%= @name %> $OPTIONS

Copy link
Collaborator

@brutus333 brutus333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The daemon.systemd template does not work since Shellwords.escape does not return new line separated strings.
Instead, I tested the following form:
+ExecStart=<%= @bin_dir %>/<%= @name %><% for option in Shellwords.split(@options) %>
+<%= option -%>
+<% end %>
+
The last newline is mandatory.

@brutus333 brutus333 merged commit c941249 into voxpupuli:master Dec 27, 2016
roidelapluie pushed a commit that referenced this pull request Jun 21, 2017
puppet-lint: fix arrow_on_right_operand_line
vide pushed a commit to billyperformance/puppet-prometheus that referenced this pull request Jun 22, 2017
…li#27)

* add a statsd_exporter

* update templates

* :update to use a template

* fix bug

* migrate to using generic service configurations

* update node_exporter

* update to just daemon

* move node_exporter to use a generic daemon

* move the statsd_exporter and alert_manager to generic daemon install

* update to make the daemon a resource

* update

* add mysqld_exporter

* update default params

* update to use different users

* update to use newer version of node_exporter
fix mysqld_exporter my.cnf location

* update systemd daemon

* update to use alertmanager instead of alert_manager

* update template filename

* update version so that alertmanager breaking changes are known

* update from review

* update systemd files

* update readme

* the service should be restarted when the configuration is updated

* fix bug in params

* fix sorting of an array of hashes

* add a lockfile for Gems

* update documentation and sort params alphabetically

* add some tests

* add .gitignore file

* remove Gemfile.lock

* remove fixture modules

* fix comments

* shellescape options variable

* update statsd template

* Fixed daemon.systemd template; fixed duplicate definitions of  and  in daemon.pp; fixed duplicate definition of  in alertmanager.pp

* Fixed daemon upstart script

* Changed statsd mapping code for ruby 1.8.7 compatibility
cegeka-jenkins pushed a commit to cegeka/puppet-prometheus that referenced this pull request Aug 28, 2019
…li#27)

* add a statsd_exporter

* update templates

* :update to use a template

* fix bug

* migrate to using generic service configurations

* update node_exporter

* update to just daemon

* move node_exporter to use a generic daemon

* move the statsd_exporter and alert_manager to generic daemon install

* update to make the daemon a resource

* update

* add mysqld_exporter

* update default params

* update to use different users

* update to use newer version of node_exporter
fix mysqld_exporter my.cnf location

* update systemd daemon

* update to use alertmanager instead of alert_manager

* update template filename

* update version so that alertmanager breaking changes are known

* update from review

* update systemd files

* update readme

* the service should be restarted when the configuration is updated

* fix bug in params

* fix sorting of an array of hashes

* add a lockfile for Gems

* update documentation and sort params alphabetically

* add some tests

* add .gitignore file

* remove Gemfile.lock

* remove fixture modules

* fix comments

* shellescape options variable

* update statsd template

* Fixed daemon.systemd template; fixed duplicate definitions of  and  in daemon.pp; fixed duplicate definition of  in alertmanager.pp

* Fixed daemon upstart script

* Changed statsd mapping code for ruby 1.8.7 compatibility
Rovanion pushed a commit to Rovanion/puppet-prometheus that referenced this pull request May 5, 2021
…li#27)

* add a statsd_exporter

* update templates

* :update to use a template

* fix bug

* migrate to using generic service configurations

* update node_exporter

* update to just daemon

* move node_exporter to use a generic daemon

* move the statsd_exporter and alert_manager to generic daemon install

* update to make the daemon a resource

* update

* add mysqld_exporter

* update default params

* update to use different users

* update to use newer version of node_exporter
fix mysqld_exporter my.cnf location

* update systemd daemon

* update to use alertmanager instead of alert_manager

* update template filename

* update version so that alertmanager breaking changes are known

* update from review

* update systemd files

* update readme

* the service should be restarted when the configuration is updated

* fix bug in params

* fix sorting of an array of hashes

* add a lockfile for Gems

* update documentation and sort params alphabetically

* add some tests

* add .gitignore file

* remove Gemfile.lock

* remove fixture modules

* fix comments

* shellescape options variable

* update statsd template

* Fixed daemon.systemd template; fixed duplicate definitions of  and  in daemon.pp; fixed duplicate definition of  in alertmanager.pp

* Fixed daemon upstart script

* Changed statsd mapping code for ruby 1.8.7 compatibility
Rovanion pushed a commit to Rovanion/puppet-prometheus that referenced this pull request May 5, 2021
puppet-lint: fix arrow_on_right_operand_line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants