Projet

Général

Profil

Révision 580c41ea

ID580c41ea3d3cb4952312c7b46f5321fd4e224c09
Parent 6fe3a2fe
Enfant 0abe4482, a89da38d

Ajouté par Artem Sheremet il y a presque 14 ans

Adding new plugins

  • netstat_bsd_
    for mbufs/etc statistics from BSD's netstat -m
  • tcp_retries
    for TCP retransmission count rate from procfs /proc/net/tcp

Voir les différences:

plugins/network/netstat_bsd_
1
#!/usr/bin/env ruby
2

  
3
# netstat_bsd revision 1 (Feb 2012)
4
#
5
# This plugin shows various statistics from 'netstat -m'
6
#
7
# Required privileges: none
8
#
9
# OS:
10
# 	Supposed: BSD
11
# 	Tested:   FreeBSD 8.2
12
#
13
# Author: Artem Sheremet <dot.doom@gmail.com>
14
#
15

  
16
#%# family=auto
17
#%# capabilities=autoconf suggest
18

  
19
# original filename
20
PLUGIN_NAME = 'netstat_bsd_'
21

  
22
class String
23
	def escape
24
		self.gsub /[^\w]/, '_'
25
	end
26

  
27
	unless method_defined? :start_with?
28
		def start_with?(str)
29
			self[0...str.size] == str
30
		end
31
	end
32
end
33

  
34
def netstat(filter = nil)
35
	Hash[`netstat -m`.split($/).map { |line|
36
		if line =~ /^([\d\/K]+) (.*) \(([\w\/+]+)\)$/
37
			# 7891K/22385K/30276K bytes allocated to network (current/cache/total)
38
			values, desc, names = $1, $2, $3
39
			[desc, names.split('/').zip(values.split '/')] if filter.nil? or desc.escape == filter
40
		elsif line =~ /^(\d+) (.*)$/
41
			# 12327 requests for I/O initiated by sendfile
42
			value, desc = $1, $2
43
			[desc, [[ :value, value ]]] if filter.nil? or desc.escape == filter
44
		end
45
	}.compact]
46
end
47

  
48
stat_name = File.basename($0, '.*').escape
49
stat_name.slice! 0, PLUGIN_NAME.size if stat_name.start_with? PLUGIN_NAME
50

  
51
case ARGV.first
52
when 'autoconf'
53
	puts `uname -s`.include?('FreeBSD') ? 'yes' : 'no'
54
when 'suggest'
55
	puts netstat.keys.map(&:escape).join $/
56
when 'config'
57
	data = netstat(stat_name)
58
	if data.empty?
59
		warn "no data for <#{stat_name}>. Try running with 'suggest'"
60
	else
61
		desc, values = data.first
62
		stack = values.size > 1
63
		first = true
64
		puts <<CONFIG
65
graph_title Netstat: #{desc}
66
graph_category netstat
67
graph_vtitle current
68
graph_order #{values.map { |name, _| name.to_s.escape }.join ' '}
69
CONFIG
70
		puts values.map { |name, _|
71
			esc_name = name.to_s.escape
72
			"#{esc_name}.draw " + if %w(total max).include? name
73
				'LINE'
74
			elsif stack
75
				if first
76
					first = false
77
					'AREA'
78
				else
79
					'STACK'
80
				end
81
			else
82
				'LINE2'
83
			end + "\n#{esc_name}.label #{name}"
84
		}.join $/
85
	end
86
when nil # fetch
87
	data = netstat(stat_name)
88
	unless data.empty?
89
		puts data.first.last.map { |name, value|
90
			value = value.to_i * 1024 if value.end_with? 'K'
91
			"#{name.to_s.escape}.value #{value}"
92
		}.join $/
93
	end
94
else
95
	warn "unrecognized argument <#{ARGV.fist}>"
96
end
plugins/network/tcp_retries
1
#!/bin/sh
2

  
3
# tcp_retries revision 2 (Feb 2012)
4
#
5
# TCP retransmission rate. Useful for network debugging.
6
#
7
# Required privileges: none
8
#
9
# OS: Linux with procfs
10
#
11
# Author: Artem Sheremet <dot.doom@gmail.com>
12
#
13

  
14
#%# family=auto
15
#%# capabilities=autoconf
16

  
17
TCPSTAT=/proc/net/tcp
18

  
19
case $1 in
20
	autoconf)
21
		[ -r $TCPSTAT -o -r ${TCPSTAT}6 ] && echo "yes" || echo "no"
22
		;;
23
    config)
24
		cat <<CONFIG
25
graph_title TCP retransmissions
26
graph_vlabel Rate, retrs/sockets
27
graph_category network
28
graph_info TCP sockets retransmission counters from $TCPSTAT
29
rate.label Retransmission rate
30
rate.draw LINE2
31
rate.min 0
32
CONFIG
33
		;;
34
esac
35

  
36
cat /proc/net/tcp* | awk '
37
{
38
	TOTAL += $7;
39
	COUNT++;
40
}
41

  
42
END {
43
	printf "rate.value %.3f\n", TOTAL/COUNT
44
}
45
'

Formats disponibles : Unified diff