From 3e548c97a89f6ad079a019b4933994341a2a2703 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Fri, 15 Feb 2013 09:18:13 +0100 Subject: [PATCH 1/3] Added instance port number for better understanding --- plugins/thin/thin_memory | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/thin/thin_memory b/plugins/thin/thin_memory index afbb20d9..9eab4e84 100755 --- a/plugins/thin/thin_memory +++ b/plugins/thin/thin_memory @@ -41,10 +41,11 @@ module Munin # run main method def run - pids = get_pids() - pids.sort.each do |pid| + instances = get_pids() + instances.each do |instance| + pid, port = instance.split("|") rss = (pid_rss(pid).to_i)/1024 - puts "thin_#{pid}.value #{rss}" + puts "thin_#{port}.value #{rss}" end end @@ -60,7 +61,7 @@ module Munin # fetch all pids that match thin def get_pids - pids = `pgrep thin`.split + pids = `pgrep -f 'thin' -l | awk -F " " '{ if (substr( $4, 10, 4)>=1) print $1"|"substr( $4, 10, 4)}'`.split(/\r?\n/) end def autoconf From c39b74e17e286c060a835f09ac540d0946439b65 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Fri, 15 Feb 2013 10:00:06 +0100 Subject: [PATCH 2/3] Changed label from pid to instance port --- plugins/thin/thin_threads | 18 ++++++++---------- plugins/thin/thins_peak_memory | 19 +++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/plugins/thin/thin_threads b/plugins/thin/thin_threads index 1f39b906..086692b0 100755 --- a/plugins/thin/thin_threads +++ b/plugins/thin/thin_threads @@ -41,10 +41,11 @@ module Munin class ThinThreads def run - pids = get_pids() - pids.sort.each do |pid| - res = (get_threads(pid).to_i) - puts "thin_#{pid}.value #{res}" + instances = get_pids() + instances.each do |instance| + pid, port = instance.split("|") + rss = (get_threads(pid).to_i)/1024 + puts "thin_#{port}.value #{rss}" end end @@ -61,13 +62,10 @@ module Munin return res end end - - - # Get pis using lsof (list open files) - # look for listening tcp applications - # that match the name thin + + # fetch all pids that match thin def get_pids - pids = `pgrep thin`.split + pids = `pgrep -f 'thin' -l | awk -F " " '{ if (substr( $4, 10, 4)>=1) print $1"|"substr( $4, 10, 4)}'`.split(/\r?\n/) end def autoconf diff --git a/plugins/thin/thins_peak_memory b/plugins/thin/thins_peak_memory index 4d9b7123..93341991 100755 --- a/plugins/thin/thins_peak_memory +++ b/plugins/thin/thins_peak_memory @@ -38,9 +38,9 @@ module Munin class ThinPeakMemory def run - pids = get_pids() - port_list = Hash.new - pids.sort.each do |pid, port| + instances = get_pids() + instances.each do |instance| + pid, port = instance.split("|") hwm = (pid_hwm(pid).to_i)/1024 puts "thin_#{port}.value #{hwm}" end @@ -61,18 +61,9 @@ module Munin end end - # Get pis using lsof (list open files) - # look for listening tcp applications - # that match the name thin + # fetch all pids that match thin def get_pids - pids_ports = [] - pids = `pgrep thin`.split - pids.each do |t| - port = `lsof -p #{t} | grep LISTEN`.split[8] - port = port.split(":")[1] - pids_ports << [t,port] - end - pids_ports + pids = `pgrep -f 'thin' -l | awk -F " " '{ if (substr( $4, 10, 4)>=1) print $1"|"substr( $4, 10, 4)}'`.split(/\r?\n/) end def autoconf From f847a3a4253b96ef19434efb9c83a349d7c9c063 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Fri, 15 Feb 2013 10:55:42 +0100 Subject: [PATCH 3/3] Fixing config / labels --- plugins/thin/thin_memory | 11 ++++++----- plugins/thin/thin_threads | 11 ++++++----- plugins/thin/thins_peak_memory | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/thin/thin_memory b/plugins/thin/thin_memory index 9eab4e84..cf7814df 100755 --- a/plugins/thin/thin_memory +++ b/plugins/thin/thin_memory @@ -81,11 +81,12 @@ when "config" puts "graph_args --base 1024 -l 0" puts "graph_scale yes" puts "graph_info Tracks the size of individual thin processes" - mpm.get_pids.sort.each do |pid| - puts "thin_#{pid}.label thin_#{pid}" - puts "thin_#{pid}.info Process memory" - puts "thin_#{pid}.type GAUGE" - puts "thin_#{pid}.min 0" + mpm.get_pids.sort.each do |instance| + pid, port = instance.split("|") + puts "thin_#{port}.label thin_#{port}" + puts "thin_#{port}.info Process memory" + puts "thin_#{port}.type GAUGE" + puts "thin_#{port}.min 0" end when "autoconf" if mpm.autoconf diff --git a/plugins/thin/thin_threads b/plugins/thin/thin_threads index 086692b0..16cbd567 100755 --- a/plugins/thin/thin_threads +++ b/plugins/thin/thin_threads @@ -85,11 +85,12 @@ when "config" puts "graph_args -l 0" puts "graph_scale yes" puts "graph_info Tracks how many threads per thin processes" - mpm.get_pids.sort.each do |pid| - puts "thin_#{pid}.label thin_#{pid}" - puts "thin_#{pid}.info Threads per Thin process" - puts "thin_#{pid}.type GAUGE" - puts "thin_#{pid}.min 0" + mpm.get_pids.sort.each do |instance| + pid, port = instance.split("|") + puts "thin_#{port}.label thin_#{port}" + puts "thin_#{port}.info Threads per Thin process" + puts "thin_#{port}.type GAUGE" + puts "thin_#{port}.min 0" end when "autoconf" if mpm.autoconf diff --git a/plugins/thin/thins_peak_memory b/plugins/thin/thins_peak_memory index 93341991..049fda29 100755 --- a/plugins/thin/thins_peak_memory +++ b/plugins/thin/thins_peak_memory @@ -83,7 +83,8 @@ when "config" puts "graph_args -l 0" puts "graph_scale yes" puts "graph_info Tracks the peak memory of thin processes, aka High Water Mark." - mpm.get_pids.sort.each do |pid,port| + mpm.get_pids.sort.each do |instance| + pid, port = instance.split("|") puts "thin_#{port}.label thin_#{port}" puts "thin_#{port}.info Peak Memory" puts "thin_#{port}.type GAUGE"