summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvarac <varacanero@zeromail.org>2010-07-15 23:41:29 +0200
committervarac <varacanero@zeromail.org>2010-07-15 23:41:29 +0200
commit3214469254a1d20a3ea8637d2cca3b07c2b03e78 (patch)
tree442383f4be41675051e9c1f509e6d029a69ed8e3
parent9b7eb96eb112a989be41949dcedd974b2390f13d (diff)
parent9820bf2428a6fe3dbd0f361e5679991d263b73af (diff)
merge with shared-modules/passenger
-rw-r--r--README33
-rw-r--r--files/mod_passenger.conf0
-rwxr-xr-xfiles/munin/passenger_memory_stats123
-rwxr-xr-xfiles/munin/passenger_stats45
-rw-r--r--manifests/base.pp13
-rw-r--r--manifests/debian.pp19
-rw-r--r--manifests/init.pp25
-rw-r--r--manifests/munin.pp20
8 files changed, 268 insertions, 10 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..7014d6f
--- /dev/null
+++ b/README
@@ -0,0 +1,33 @@
+Passenger (mod_rails) puppet module
+-----------------------------------
+
+This puppet module handles a passenger setup, it installs the
+packages, and configures some munin graphs.
+
+Dependencies
+------------
+
+This module expects you to have:
+ . munin module
+ . apache module
+
+Getting started
+---------------
+
+Simply do 'include passenger' and it will be installed.
+
+Configuration
+-------------
+
+If you need to install a specific version of passenger or
+librack-ruby, you can specify the version to be installed by providing
+a variable, for example:
+
+$passenger_ensure_version = "2.2.3-2~bpo50+1"
+$librack-ruby_ensure_version = "1.0.0-2~bpo50+1"
+
+If you need to set different munin plugin configuration values, you
+can also do so as follows:
+
+$passenger_memory_munin_config = "user root\nenv.passenger_memory_stats /opt/bin/passenger-memory-stats"
+$passenger_stats_munin_config = "user root\nenv.PASSENGER_TMPDIR /var/tmp\n"
diff --git a/files/mod_passenger.conf b/files/mod_passenger.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/files/mod_passenger.conf
diff --git a/files/munin/passenger_memory_stats b/files/munin/passenger_memory_stats
new file mode 100755
index 0000000..eb9b284
--- /dev/null
+++ b/files/munin/passenger_memory_stats
@@ -0,0 +1,123 @@
+#!/usr/bin/env ruby
+pod=<<-POD
+
+=head1 NAME
+passenger_memory_stats - Munin plugin to monitor the memory usage of passenger application servers.
+Monitors the memory consumed by passenger instances.
+
+=head1 APPLICABLE SYSTEMS
+All systems that have passenger installed.
+
+=head1 CONFIGURATION
+The plugin needs to execute passenger-memory-stats.
+This configuration section shows the defaults of the plugin:
+
+ [passenger_*]
+ user root
+ command /usr/local/bin/ruby %c
+
+Options
+ env.passenger_memory_stats '/path/to/passenger-memory-stats' # Path to passenger memory status.
+ env.graph_category 'App' # Graph Category. Defaults to Passenger.
+
+ln -s /usr/share/munin/plugins/passenger_memory_stats /etc/munin/plugins/passenger_memory_stats
+
+=head1 INTERPRETATION
+The plugin shows the memory consumed by passenger instances.
+
+=head1 MAGIC MARKERS
+ #%# family=auto
+ #%# capabilities=autoconf
+
+=head1 VERSION
+1.5
+
+=head1 BUGS
+None known
+
+=head1 AUTHOR
+Ilya Lityuga
+Bart ten Brinke - railsdoctors.com
+
+=head1 LICENSE
+MIT
+
+POD
+
+# Globals
+GRAPH_CATEGORY = ENV['graph_category'] || 'Passenger'
+PASSENGER_MEMORY_STATS = ENV['passenger_memory_stats'] || '/usr/local/bin/passenger-memory-stats'
+
+# Check if this plugin can run
+def autoconf
+ begin
+ require 'rubygems'
+ gem "passenger", ">=2.0"
+ rescue Exception => e
+ puts "no (Gem not found: #{e})"
+ exit 1
+ end
+
+ status = `#{PASSENGER_MEMORY_STATS}`
+ unless $?.success?
+ puts "no (error when executing #{PASSENGER_MEMORY_STATS})"
+ exit 1
+ end
+
+ puts "yes"
+ exit 0
+end
+
+# Describe the graph config
+def config
+ status = `#{PASSENGER_MEMORY_STATS}`
+ memory_info = open('/proc/meminfo', 'r') do |lines|
+ lines.inject({}) do |h, line|
+ matched = line.match(/^([\w_\(\)]+):\s+(\d+)/)
+ h[matched[1].to_sym] = matched[2].to_i * 1024
+ h
+ end
+ end
+ upper_limit = memory_info[:MemTotal]
+ puts <<-CONFIG
+graph_category #{GRAPH_CATEGORY}
+graph_title Passenger memory stats
+graph_vlabel Bytes
+graph_args --base 1000 -l 0 --upper-limit #{upper_limit}
+graph_info The memory used by passenger instances on this application server
+
+memory.label memory
+CONFIG
+ exit 0
+end
+
+
+# Collect the data
+# <tt>debug</tt> Show debug information
+def run(debug = false)
+ stats = `#{PASSENGER_MEMORY_STATS}`
+
+ unless $?.success?
+ $stderr.puts "failed executing passenger-memory-stats"
+ exit 1
+ end
+
+ puts stats if debug
+
+ #### Total private dirty RSS: 81.81 MB
+ stats =~ /RSS:\s*([\d\.]+)\s*MB\Z/m
+ memory = ($1.to_f * 1024 * 1024).to_i
+ puts "memory.value #{memory}"
+end
+
+
+# Main
+if ARGV[0] == "config"
+ config
+elsif ARGV[0] == "autoconf"
+ autoconf
+elsif ARGV[0] == "debug"
+ run(true)
+else
+ run
+end
diff --git a/files/munin/passenger_stats b/files/munin/passenger_stats
new file mode 100755
index 0000000..a117903
--- /dev/null
+++ b/files/munin/passenger_stats
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+
+def output_config
+ puts <<-END
+graph_category Passenger
+graph_title passenger status
+graph_vlabel count
+
+sessions.label sessions
+max.label max processes
+running.label running processes
+active.label active processes
+inactive.label inactive processes
+END
+ exit 0
+end
+
+def output_values
+ status = `/usr/sbin/passenger-status`
+ unless $?.success?
+ $stderr.puts "failed executing passenger-status"
+ exit 1
+ end
+ status =~ /max\s+=\s+(\d+)/
+ puts "max.value #{$1}"
+
+ status =~ /count\s+=\s+(\d+)/
+ puts "running.value #{$1}"
+
+ status =~ /active\s+=\s+(\d+)/
+ puts "active.value #{$1}"
+
+ status =~ /inactive\s+=\s+(\d+)/
+ puts "inactive.value #{$1}"
+
+ total_sessions = 0
+ status.scan(/Sessions: (\d+)/).flatten.each { |count| total_sessions += count.to_i }
+ puts "sessions.value #{total_sessions}"
+end
+
+if ARGV[0] == "config"
+ output_config
+else
+ output_values
+end
diff --git a/manifests/base.pp b/manifests/base.pp
new file mode 100644
index 0000000..34ef976
--- /dev/null
+++ b/manifests/base.pp
@@ -0,0 +1,13 @@
+class passenger::base {
+
+ include apache
+
+ apache::config::file { 'mod_passenger':
+ ensure => present,
+ source => [ "puppet://${server}/modules/site-passenger/${fqdn}/mod_passenger.conf",
+ "puppet://${server}/modules/site-passenger/mod_passenger.conf",
+ "puppet://${server}/modules/passenger/mod_passenger.conf",
+ ],
+ }
+
+}
diff --git a/manifests/debian.pp b/manifests/debian.pp
new file mode 100644
index 0000000..f351111
--- /dev/null
+++ b/manifests/debian.pp
@@ -0,0 +1,19 @@
+class passenger::debian inherits passenger::base {
+
+ if !defined(Package["libapache2-mod-passenger"]) {
+ if $passenger_ensure_version == '' { $passenger_ensure_version = 'installed' }
+ apache::debian::module { 'passenger':
+ ensure => $passenger_ensure_version,
+ package_name => 'libapache2-mod-passenger';
+ }
+ }
+
+ if !defined(Package["librack-ruby"]) {
+ if $librack_ensure_version == '' { $librack_ensure_version = 'installed' }
+ package {
+ "librack-ruby":
+ ensure => $librack_ensure_version;
+ }
+ }
+
+}
diff --git a/manifests/init.pp b/manifests/init.pp
index acf3b30..59cdabd 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,16 +1,21 @@
-#
# passenger module
#
-# Copyright 2009, admin(at)immerda.ch
-#
-# This program is free software; you can redistribute
-# it and/or modify it under the terms of the GNU
-# General Public License version 3 as published by
-# the Free Software Foundation.
+# Copyright 2010, Riseup Networks
+# Micah Anderson micah(at)riseup.net
#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
-class passenger{
- package{'passenger':
- ensure => installed,
+class passenger {
+
+ case $operatingsystem {
+ debian: { include passenger::debian }
+ default: { include passenger::base }
}
+
+ if $use_munin {
+ include passenger::munin
+ }
+
}
diff --git a/manifests/munin.pp b/manifests/munin.pp
new file mode 100644
index 0000000..9b6cc68
--- /dev/null
+++ b/manifests/munin.pp
@@ -0,0 +1,20 @@
+class passenger::munin {
+
+ case $passenger_memory_munin_config { '':
+ { $passenger_memory_munin_config = "user root\nenv.passenger_memory_stats /usr/sbin/passenger-memory-stats" }
+ }
+
+ case $passenger_stats_munin_config { '':
+ { $passenger_stats_munin_config = "user root\n" }
+ }
+
+ munin::plugin::deploy {
+ 'passenger_memory_stats':
+ source => "passenger/munin/passenger_memory_stats",
+ config => $passenger_memory_munin_config;
+ 'passenger_stats':
+ source => "passenger/munin/passenger_stats",
+ config => $passenger_stats_munin_config;
+ }
+
+}