├── .gitignore ├── README.md ├── TODO ├── example-graph.png ├── graphite_event.yaml ├── lib └── puppet │ └── reports │ └── graphite_event.rb └── manifests └── init.pp /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | puppet-graphite_event 2 | ===================== 3 | 4 | Description 5 | ----------- 6 | 7 | A puppet report processor for sending events to a 8 | [graphite](http://graphite.wikidot.com/) server. 9 | 10 | This report processor will send the number of changes made during a puppet 11 | run into a graphite server. The data can then be overlaid onto other metrics 12 | to help correlate events. Use the `drawAsInfinite()` function in graphite 13 | to draw the events as vertical lines. 14 | 15 | ![example-graph-image](https://github.com/joemiller/puppet-graphite_event/raw/master/example-graph.png) 16 | 17 | For example, in the diagram above the load average from a group of servers 18 | is plotted. Blue vertical lines mark a point in time when puppet modified 19 | resources on a host in the group. We can see that immediately following a 20 | puppet change the load spiked on one of the servers. This can be 21 | very valuable information. 22 | 23 | Additional information on how and why to use graphite to track events 24 | can be found in Etsy's [Measure Anything, Measure Everything](http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/) 25 | paper. 26 | 27 | Similar software 28 | ---------------- 29 | 30 | This module is only meant to send change events to graphite. If you would 31 | like to send all metric data to graphite, please see 32 | [puppet-graphite](https://github.com/nareshov/puppet-graphite) by Naresh V. 33 | 34 | 35 | Requirements 36 | ------------ 37 | 38 | * `Puppet`. (Only tested on 2.7 but likely works on 2.6 and possibly 0.25) 39 | * A [graphite](http://graphite.wikidot.com/) server^ 40 | 41 | Installation & Usage 42 | -------------------- 43 | 44 | 1. Install puppet-graphite_event as a module in your puppet master's module 45 | path (eg: `/etc/puppet/modules/puppet-graphite_event`) 46 | 47 | 2. Copy the included graphite_event.yaml to your puppet master's config 48 | dir (eg: `/etc/puppet/`). Then update the `graphite_server`, `graphie_port`, 49 | and `path_prefix` variables. 50 | 51 | Metrics sent to graphite will use the path: `.fqdn_with_underscores`. 52 | 53 | 3. Enable pluginsync and reports on your master and clients in `puppet.conf` 54 | 55 | [master] 56 | report = true 57 | reports = graphite_event # can specify multiple: `store, graphite_event` 58 | pluginsync = true 59 | 60 | [agent] 61 | report = true 62 | pluginsync = true 63 | 64 | 4. Restart your puppet master. 65 | 66 | Masterless puppet 67 | ----------------- 68 | 69 | I suspect this could also be used in a masterless puppet setup as well, just make 70 | sure to deploy the report and config file to each client. If you have success with this 71 | please let me know by leaving a comment in the github issues section. 72 | 73 | Author 74 | ------ 75 | 76 | joe miller. http://joemiller.me (11/5/2011) 77 | 78 | Derived from [puppet-graphite](https://github.com/nareshov/puppet-graphite) by Naresh V. 79 | 80 | Derived from [puppet-ganglia](https://github.com/jamtur01/puppet-ganglia) by James Turnbull 81 | 82 | Original License 83 | ---------------- 84 | 85 | Author:: James Turnbull () 86 | Copyright:: Copyright (c) 2011 James Turnbull 87 | License:: Apache License, Version 2.0 88 | 89 | Licensed under the Apache License, Version 2.0 (the "License"); 90 | you may not use this file except in compliance with the License. 91 | You may obtain a copy of the License at 92 | 93 | http://www.apache.org/licenses/LICENSE-2.0 94 | 95 | Unless required by applicable law or agreed to in writing, software 96 | distributed under the License is distributed on an "AS IS" BASIS, 97 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 98 | See the License for the specific language governing permissions and 99 | limitations under the License. 100 | 101 | License of this derived work 102 | ---------------------------- 103 | 104 | Same as above plus: 105 | Author:: Joe Miller () 106 | Copyright:: Copyright (c) 2011 Joe Miller 107 | License:: Apache License, Version 2.0 108 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | x rename 2 | x copy in example yaml config 3 | - update readme 4 | - include jpg in readme? 5 | - push to github 6 | - blog 7 | -------------------------------------------------------------------------------- /example-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemiller/puppet-graphite_event/d0447ea9aba105ec6f134d01c21a047bbb98c3f0/example-graph.png -------------------------------------------------------------------------------- /graphite_event.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | :graphite_server: 'graphite.example.com' 3 | :graphite_port: 2003 4 | :path_prefix: events.puppet 5 | -------------------------------------------------------------------------------- /lib/puppet/reports/graphite_event.rb: -------------------------------------------------------------------------------- 1 | require 'puppet' 2 | require 'yaml' 3 | require 'socket' 4 | require 'time' 5 | 6 | Puppet::Reports.register_report(:graphite_event) do 7 | 8 | configfile = File.join([File.dirname(Puppet.settings[:config]), "graphite_event.yaml"]) 9 | raise(Puppet::ParseError, "graphite_event report config file #{configfile} not readable") unless File.exist?(configfile) 10 | config = YAML.load_file(configfile) 11 | GRAPHITE_SERVER = config[:graphite_server] 12 | GRAPHITE_PORT = config[:graphite_port] 13 | PATH_PREFIX = config[:path_prefix] 14 | 15 | desc <<-DESC 16 | Sends the number of changes to graphite. Can be used to help correlate 17 | puppet changes to other data in graphite. 18 | DESC 19 | 20 | def send_metric payload 21 | socket = TCPSocket.new(GRAPHITE_SERVER, GRAPHITE_PORT) 22 | socket.puts payload 23 | socket.close 24 | end 25 | 26 | # NOTE: We only send an update to graphite if the number of changes is > 0. 27 | # we do this so that this data can be graphed with the drawAsInfinite() 28 | # function. This allows you to overlay puppet change events on other 29 | # graphs. See here for more info on graphing 'events': 30 | # http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/ 31 | def process 32 | return if self.metrics.nil? # failed reports may have no metrics? be safe. 33 | changes = self.metrics['changes']['total'] 34 | 35 | if changes > 0 36 | epochtime = Time.now.utc.to_i 37 | host_as_underscores = self.host.gsub(/\./, '_') 38 | name = "#{PATH_PREFIX}.#{host_as_underscores}" 39 | 40 | send_metric "#{name} #{changes} #{epochtime}" 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemiller/puppet-graphite_event/d0447ea9aba105ec6f134d01c21a047bbb98c3f0/manifests/init.pp --------------------------------------------------------------------------------