diff --git a/README.md b/README.md index 98d1846..de76b79 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,86 @@ -Description -=========== +## Description Installs and configures statsite, statsd implementation. https://github.com/armon/statsite -Requirements -============ +## Requirements + +### Platforms * Ubuntu 10.04 / Ubuntu 12.04 +* Centos 7 + +### Cookbooks + * python * git * runit -Attributes -========== +## Usage -* `node[:statsite][:path]` - Default setting: "/opt/statsite" -* `node[:statsite][:repo]` - Default setting: "git://github.com/armon/statsite.git" +`recipe[statsite]` install, build and start statsite + +## Attributes + +### Installation/System Attributes + +#### Systemd, Upstart, Init (Debian based) init systems + +These attributes are used by Systemd, Upstart, Init (Debian based) init systems. + +* `default[:statsite][:service_type]` - Can be "upstart", "systemd", "init" or + "runit". Default: "runit" * `node[:statsite][:conf]` - Default setting: "/etc/statsite.conf" +* `node[:statsite][:path]` - Default setting: "/opt/statsite" * `node[:statsite][:owner]` - Default setting: "statsite" + +#### Upstart and Init (Debian based) specific + +In addition to attributes listed above, these attributes are also used by Upstart and Init. + * `node[:statsite][:group]` - Default setting: "statsite" + +#### Init (Debian based) specific + +In addition to attributes listed above, this attribute is also used by Init. + +* `default[:statsite][:pid_file]` - Default setting: "/var/run/statsite/statsite.pid" + +### Build Attributes + +* `node[:statsite][:repo]` - Default setting: "git://github.com/armon/statsite.git" +* `node[:statsite][:ref]` - Default setting: "HEAD" + +### Daemon Attributes + * `node[:statsite][:bind_address]` - Default setting: ::1 -* `node[:statsite][:port]` - Default setting: 8125 +* `node[:statsite][:tcp_port]` - Default setting: 8125 +* `node[:statsite][:udp_port]` - Default setting: 8125 * `node[:statsite][:loglevel]` - Default setting: "INFO" * `node[:statsite][:flush_interval]` - Default setting: 10 * `node[:statsite][:timer_eps]` - Default setting: 0.01 * `node[:statsite][:stream_command]` - Optional handler. Default setting: '' -* `default[:statsite][:service_type]` - Can be "runit" or "upstart". Default: "runit" +* `node[:statsite][:binary_stream]` - Optional handler. Default setting: '' +* `node[:statsite][:use_type_prefix]` - Optional handler. Default setting: '' + +## Recipes -Usage -===== +* `recipe[statsite]` Installs/Configures statsite -`recipe[statsite]` install, build and start with either runit or upstart +## Roles + +### Histogram -Histogram -========= Additional histograms can be defined in `node[:statsite][:histogram]` attribute. Role example: - + ``` { ... "default_attributes": { "statsite": { "bind_address": "::", - "port": 18125, + "udp_port": 18125, "stream_command": "python /opt/statsite/sinks/graphite.py graphite.recfut.com 2003 statsite", "service_type": "upstart", "histogram": { @@ -57,6 +93,6 @@ Role example: } } } -... +... } ``` diff --git a/attributes/default.rb b/attributes/default.rb index 2c022cf..d88ae3a 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -5,11 +5,14 @@ default[:statsite][:owner] = "statsite" default[:statsite][:group] = "statsite" default[:statsite][:bind_address] = "::1" -default[:statsite][:port] = 8125 +default[:statsite][:tcp_port] = 8125 +default[:statsite][:udp_port] = 8125 default[:statsite][:loglevel] = "INFO" default[:statsite][:flush_interval] = 10 default[:statsite][:timer_eps] = 0.01 default[:statsite][:stream_command] = "" +default[:statsite][:binary_stream] = "" +default[:statsite][:use_type_prefix] = "" default[:statsite][:service_type] = "runit" default[:statsite][:pid_file] = "/var/run/statsite/statsite.pid" diff --git a/recipes/default.rb b/recipes/default.rb index 72f10b0..19ea9f2 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -81,6 +81,24 @@ action [:enable, :start] end +when 'systemd' + service_resource = 'service[statsite]' + + template "/lib/systemd/system/statsite.service" do + source "systemd.statsite.erb" + mode "0755" + variables( + :conf => node[:statsite][:conf], + :path => node[:statsite][:path], + :user => node[:statsite][:owner] + ) + end + + service "statsite" do + supports :restart => true + action [:enable, :start] + end + when 'init' service_resource = 'service[statsite]' diff --git a/templates/default/statsite.conf.erb b/templates/default/statsite.conf.erb index a2ccf56..7e57ec9 100644 --- a/templates/default/statsite.conf.erb +++ b/templates/default/statsite.conf.erb @@ -4,14 +4,20 @@ bind_address = <%= node[:statsite][:bind_address] %> daemonize = 1 pid_file = <%= node[:statsite][:pid_file] %> <% end -%> -port = <%= node[:statsite][:port] %> -udp_port = <%= node[:statsite][:port] %> +tcp_port = <%= node[:statsite][:tcp_port] %> +udp_port = <%= node[:statsite][:udp_port] %> log_level = <%= node[:statsite][:loglevel] %> flush_interval = <%= node[:statsite][:flush_interval] %> timer_eps = <%= node[:statsite][:timer_eps] %> <% if node[:statsite][:stream_command] -%> stream_cmd = <%= node[:statsite][:stream_command] %> <% end -%> +<% if node[:statsite][:binary_stream] -%> +binary_stream = <%= node[:statsite][:binary_stream] %> +<% end -%> +<% if node[:statsite][:use_type_prefix] -%> +use_type_prefix = <%= node[:statsite][:use_type_prefix] %> +<% end -%> <% if node[:statsite][:histogram] -%> <% node[:statsite][:histogram].each do |section,opts| -%> diff --git a/templates/default/systemd.statsite.erb b/templates/default/systemd.statsite.erb new file mode 100644 index 0000000..da63c90 --- /dev/null +++ b/templates/default/systemd.statsite.erb @@ -0,0 +1,15 @@ +[Unit] +Description=Statsite Collector +Wants=basic.target +After=basic.target network.target + +[Service] +User=<%= @user %> +ExecStart=<%= @path %>/statsite -f <%= @conf %> +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target