Skip to content

Commit fb907d3

Browse files
jaymzhfacebook-github-bot
authored andcommitted
fb_collectd: Fix various problems (facebook#261)
Summary: * Most configs are not possible with existing code as it quotes strings that collectd won't accept quoted * Add support for Load configurations * Fix 'global' vs 'globals' in docs * Add more docs Signed-off-by: Phil Dibowitz <phil@ipom.com> Pull Request resolved: facebook#261 Test Plan: Imported from GitHub, without a `Test Plan:` line. This cookbook is an open-source example, not in use internally. Differential Revision: D69599764 fbshipit-source-id: 6fe4531662f906404377867beca18af3c470471f
1 parent f7c21f8 commit fb907d3

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

cookbooks/fb_collectd/README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,75 @@ Attributes
1515

1616
Usage
1717
-----
18-
### Daemon
18+
### Daemon configuration
19+
1920
To install collectd include `fb_collectd::default`. Global settings can be
2021
customized using the `node['fb_collectd']['globals']` attribute and individual
2122
plugins can be enabled and configured using `node['fb_collectd']['plugins']`.
2223
Example:
2324

2425
```ruby
25-
node.default['fb_collectd']['global']['FQDNLookup'] = true
26+
node.default['fb_collectd']['globals']['FQDNLookup'] = true
2627
node.default['fb_collectd']['plugins']['cpu'] = nil
2728
node.default['fb_collectd']['plugins']['syslog'] = {
2829
'LogLevel' => 'info',
2930
}
3031
```
3132

33+
This will render like:
34+
35+
```text
36+
FQDNLookup true
37+
LoadPlugin cpu
38+
LoadPlugin syslog
39+
<Plugin syslog>
40+
LogLevel info
41+
</Plugin>
42+
```
43+
44+
All plugins will also be loaded with a simple `LoadPlugin $PLUGIN` - if you
45+
need the loading to have a configuration as well, use the `_load_config` key:
46+
47+
```ruby
48+
node.default['fb_collectd']['plugins']['python'] => {
49+
'_load_config' => {
50+
'Globals' => true,
51+
},
52+
...
53+
}
54+
```
55+
56+
which will render like so:
57+
58+
```text
59+
<LoadPlugin python>
60+
Globals true
61+
</LoadPlugin>
62+
<Plugin python>
63+
...
64+
</Plugin>
65+
```
66+
67+
Note that since collectd expects _most_ of its string config values to be unquoted,
68+
we do not quote string values by default (otherwise things like `LogLevel` above
69+
would error). If a value needs to be quoted, you can quote it in it's config:
70+
71+
```ruby
72+
node.default['fb_collectd']['plugins']['apache'] => {
73+
'Instance "localhost"' => {
74+
'URL' => '"http://localhost/server-status?auto"',
75+
},
76+
}
77+
```
78+
79+
### Sysconfig
80+
3281
On Debian systems, environment settings can be configured in
3382
`node['fb_collectd']['sysconfig']`; note that this attribute is ignored on
3483
CentOS.
3584

3685
### Frontend
86+
3787
The collectd-web fronted can be installed with the `fb_collectd::fronted`
3888
recipe. Use the `node['fb_collectd']['collection']` to customize its settings.
3989
Note that this recipe will not install or configure a web server, so unless you

cookbooks/fb_collectd/libraries/default.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ def self._gen_collectd_conf_entry(k, v, i = 0)
4848
return "#{indent}#{k} true"
4949
elsif v.is_a?(FalseClass)
5050
return "#{indent}#{k} false"
51-
elsif v.is_a?(Numeric)
52-
return "#{indent}#{k} #{v}"
5351
else
54-
return "#{indent}#{k} \"#{v}\""
52+
return "#{indent}#{k} #{v}"
5553
end
5654
end
5755
end

cookbooks/fb_collectd/templates/default/collectd.conf.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
<% end -%>
88

99
<% config['plugins'].each do |plugin, config| -%>
10+
<% if config && config['_load_config'] %>
11+
<LoadPlugin <%= plugin %>>
12+
<% config['_load_config'].each do |key, val| %>
13+
<%= FB::Collectd._gen_collectd_conf_entry(key, val, 1) %>
14+
<% end %>
15+
</LoadPlugin>
16+
<% else %>
1017
LoadPlugin <%= plugin %>
18+
<% end %>
1119
<% if config -%>
1220
<Plugin <%= plugin %>>
1321
<% config.each do |key, val| -%>
22+
<% next if key == '_load_config' %>
1423
<%= FB::Collectd._gen_collectd_conf_entry(key, val, 2) %>
1524
<% end -%>
1625
</Plugin>

0 commit comments

Comments
 (0)