gitorious-munin-plugins 0.9.17 → 0.9.19
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gitorious-munin-plugin +1 -0
- data/lib/gitorious-munin-plugins/config.rb +43 -0
- data/lib/gitorious-munin-plugins/database.rb +13 -16
- data/lib/gitorious-munin-plugins/plugins/git_proxy.rb +38 -0
- data/lib/gitorious-munin-plugins/plugins/gitorious_clones.rb +20 -0
- data/lib/gitorious-munin-plugins/plugins/gitorious_disk_usage.rb +42 -0
- data/lib/gitorious-munin-plugins/usage_plugin.rb +7 -0
- data/lib/gitorious-munin-plugins/version.rb +1 -1
- metadata +8 -4
data/bin/gitorious-munin-plugin
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require "gitorious-munin-plugins"
|
3
3
|
require "gitorious-munin-plugins/version"
|
4
4
|
require "gitorious-munin-plugins/database"
|
5
|
+
require "gitorious-munin-plugins/config"
|
5
6
|
require "gitorious-munin-plugins/cli"
|
6
7
|
require "gitorious-munin-plugins/plugin"
|
7
8
|
require "gitorious-munin-plugins/usage_plugin"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module GitoriousMuninPlugins
|
2
|
+
class Config
|
3
|
+
GITORIOUS_CONF_PATH = "/etc/gitorious.conf"
|
4
|
+
|
5
|
+
def gitorious_config
|
6
|
+
yaml_file = fetch("GITORIOUS_HOME")
|
7
|
+
gitorious_yml = Pathname(fetch("GITORIOUS_HOME")) + "config/gitorious.yml"
|
8
|
+
YAML::load_file(gitorious_yml)[fetch("RAILS_ENV")]
|
9
|
+
end
|
10
|
+
|
11
|
+
def rails_env
|
12
|
+
@rails_env ||= fetch("RAILS_ENV", "production")
|
13
|
+
end
|
14
|
+
|
15
|
+
def gitorious_home
|
16
|
+
path = fetch("GITORIOUS_HOME")
|
17
|
+
Pathname(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def database_yaml
|
21
|
+
database_yaml = gitorious_home + "config/database.yml"
|
22
|
+
raise NotFound, "No database.yml found in #{database_yml}" unless database_yaml.exist?
|
23
|
+
database_yaml
|
24
|
+
end
|
25
|
+
|
26
|
+
# Fetch line matching #{key}= in /etc/gitorious.conf
|
27
|
+
def fetch(key, default_value=nil)
|
28
|
+
|
29
|
+
begin
|
30
|
+
config_file = File.read(GITORIOUS_CONF_PATH)
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
abort "Gitorious configuration file #{GITORIOUS_CONF_PATH} was not found, exiting"
|
33
|
+
end
|
34
|
+
|
35
|
+
result = config_file.scan(/^#{key}=(.*)$/).flatten.first
|
36
|
+
if result
|
37
|
+
result
|
38
|
+
elsif default_value
|
39
|
+
default_value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,35 +1,32 @@
|
|
1
1
|
module GitoriousMuninPlugins
|
2
2
|
class Database
|
3
3
|
def initialize
|
4
|
+
@config = Config.new
|
4
5
|
end
|
5
6
|
|
6
|
-
def
|
7
|
-
@
|
7
|
+
def database_configuration
|
8
|
+
@database_configuration ||= load_database_configuration
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rescue Errno::ENOENT
|
20
|
-
raise NotFound, "Gitorious configuration file /etc/gitorious.conf was not found, exiting"
|
21
|
-
end
|
11
|
+
def load_database_configuration
|
12
|
+
YAML::load_file(@config.database_yaml)[@config.rails_env]
|
13
|
+
end
|
14
|
+
|
15
|
+
def database_connection
|
16
|
+
@database_connection ||= Mysql.new(database_configuration["host"],
|
17
|
+
database_configuration["username"],
|
18
|
+
database_configuration["password"],
|
19
|
+
database_configuration["database"])
|
22
20
|
end
|
23
21
|
|
24
22
|
def select(sql)
|
23
|
+
conn = database_connection
|
25
24
|
begin
|
26
|
-
conn = Mysql.new(configuration["host"], configuration["username"], configuration["password"], configuration["database"])
|
27
25
|
conn.query(sql)
|
28
26
|
ensure
|
29
27
|
conn.close
|
30
28
|
end
|
31
29
|
end
|
32
30
|
|
33
|
-
class NotFound < StandardError; end
|
34
31
|
end
|
35
32
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
config = GitoriousMuninPlugins::Config.new
|
2
|
+
home = config.gitorious_home
|
3
|
+
ProxyPid = home + "../run/git-proxy-1.pid"
|
4
|
+
|
5
|
+
def ps_output
|
6
|
+
if ProxyPid.exist?
|
7
|
+
cmd = "ps ww `cat #{ProxyPid}` | egrep -v '(ps|PID)'"
|
8
|
+
res = `#{cmd}`.strip
|
9
|
+
if res =~ /\-\ (\d+)\/(\d+)\/(\d+)\ cur\/max\/tot\ conns$/
|
10
|
+
curr, max, total = $1, $2, $3
|
11
|
+
puts "curr.value #{curr}"
|
12
|
+
puts "max.value #{max}"
|
13
|
+
puts "total.value #{total}"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
$stderr.puts "#{ProxyPid} not found"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
case ARGV.shift
|
22
|
+
when "autoconf"
|
23
|
+
puts "no"
|
24
|
+
when "config"
|
25
|
+
puts "graph_title git-proxy activity"
|
26
|
+
puts 'graph_args -l 0'
|
27
|
+
puts 'graph_vlabel active connections'
|
28
|
+
puts 'graph_category Gitorious'
|
29
|
+
puts "curr.label Active connections"
|
30
|
+
puts "curr.draw LINE2"
|
31
|
+
puts "curr.type GAUGE"
|
32
|
+
# puts "max.label Max connections so far"
|
33
|
+
# puts "max.draw no"
|
34
|
+
# puts "total.label Total conncetions"
|
35
|
+
# puts "total.draw no"
|
36
|
+
else
|
37
|
+
ps_output
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# SSH keys
|
2
|
+
database = GitoriousMuninPlugins::Database.new
|
3
|
+
cmd = ARGV.shift
|
4
|
+
|
5
|
+
case cmd
|
6
|
+
when "autoconf"
|
7
|
+
puts "no"
|
8
|
+
when "config"
|
9
|
+
puts "graph_title git:// Clones (within last 24 hrs)"
|
10
|
+
puts 'graph_args -l 0'
|
11
|
+
puts 'graph_vlabel Cloners'
|
12
|
+
puts 'graph_category Gitorious'
|
13
|
+
puts "new.label Clones"
|
14
|
+
puts "new.draw LINE2"
|
15
|
+
puts "new.type GAUGE"
|
16
|
+
else
|
17
|
+
database.select("select count(*) as count from cloners where date >= date_sub(now(), interval 24 hour)").each_hash do |row|
|
18
|
+
puts "new.value #{row['count'].to_i}"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
config = GitoriousMuninPlugins::Config.new
|
2
|
+
GitoriousConfig = config.gitorious_config
|
3
|
+
Directories = {
|
4
|
+
"cache_dir" => GitoriousConfig["archive_cache_dir"],
|
5
|
+
"working_dir" => GitoriousConfig["archive_work_dir"],
|
6
|
+
"repo_root" => GitoriousConfig["repository_base_path"]
|
7
|
+
}
|
8
|
+
def disk_usage(key)
|
9
|
+
dir = Directories[key]
|
10
|
+
command = "du -sb #{dir} 2>/dev/null"
|
11
|
+
result = `#{command}`.split(/\s+/).first
|
12
|
+
end
|
13
|
+
|
14
|
+
cmd = ARGV.shift
|
15
|
+
case cmd
|
16
|
+
when "autoconf"
|
17
|
+
puts "no"
|
18
|
+
when "config"
|
19
|
+
puts "graph_title Disk usage"
|
20
|
+
puts "graph_args -l 0"
|
21
|
+
puts "graph_vlabel Disk usage"
|
22
|
+
puts "graph_category Gitorious"
|
23
|
+
|
24
|
+
# Cache dir
|
25
|
+
puts "cache.label Repo cache"
|
26
|
+
puts "cache.draw LINE2"
|
27
|
+
puts "cache.type GAUGE"
|
28
|
+
|
29
|
+
# Work dir
|
30
|
+
puts "work.label Repo work"
|
31
|
+
puts "work.draw LINE2"
|
32
|
+
puts "work.type GAUGE"
|
33
|
+
|
34
|
+
# Root dir
|
35
|
+
puts "root.label Repo storage"
|
36
|
+
puts "root.draw LINE2"
|
37
|
+
puts "root.type GAUGE"
|
38
|
+
else
|
39
|
+
puts "cache.value #{disk_usage('cache_dir')}"
|
40
|
+
puts "work.value #{disk_usage('working_dir')}"
|
41
|
+
puts "root.value #{disk_usage('repo_root')}"
|
42
|
+
end
|
@@ -17,6 +17,7 @@ EOS
|
|
17
17
|
opt :status, "List install status of plugins"
|
18
18
|
opt :install, "Install PACKAGE1 PACKAGE2. Specify 'all' to install all plugins"
|
19
19
|
opt :uninstall, "Uninstall PACKAGE1 PACKAGE2. Specify 'all' to uninstall all plugins "
|
20
|
+
opt :try, "Try running PACKAGE"
|
20
21
|
end
|
21
22
|
|
22
23
|
if global_options[:status_given]
|
@@ -25,6 +26,8 @@ EOS
|
|
25
26
|
install_plugins(ARGV)
|
26
27
|
elsif global_options[:uninstall_given]
|
27
28
|
uninstall_plugins(ARGV)
|
29
|
+
elsif global_options[:try_given]
|
30
|
+
try_running(ARGV)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -50,6 +53,10 @@ EOS
|
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
56
|
+
def try_running(name)
|
57
|
+
load Plugin.root.realpath + "#{name}.rb"
|
58
|
+
end
|
59
|
+
|
53
60
|
def extract_plugins_from_spec(spec)
|
54
61
|
if spec.first == "all"
|
55
62
|
@known_plugins.map(&:name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitorious-munin-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 19
|
10
|
+
version: 0.9.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marius Mathiesen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-11-
|
18
|
+
date: 2012-11-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -77,8 +77,12 @@ files:
|
|
77
77
|
- gitorious-munin-plugins.gemspec
|
78
78
|
- lib/gitorious-munin-plugins.rb
|
79
79
|
- lib/gitorious-munin-plugins/cli.rb
|
80
|
+
- lib/gitorious-munin-plugins/config.rb
|
80
81
|
- lib/gitorious-munin-plugins/database.rb
|
81
82
|
- lib/gitorious-munin-plugins/plugin.rb
|
83
|
+
- lib/gitorious-munin-plugins/plugins/git_proxy.rb
|
84
|
+
- lib/gitorious-munin-plugins/plugins/gitorious_clones.rb
|
85
|
+
- lib/gitorious-munin-plugins/plugins/gitorious_disk_usage.rb
|
82
86
|
- lib/gitorious-munin-plugins/plugins/gitorious_ssh_keys.rb
|
83
87
|
- lib/gitorious-munin-plugins/plugins/gitorious_users.rb
|
84
88
|
- lib/gitorious-munin-plugins/usage_plugin.rb
|