This repository has been archived by the owner on Mar 11, 2018. It is now read-only.
/
rw_
executable file
·114 lines (102 loc) · 2.53 KB
/
rw_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env ruby
# Source: https://github.com/cmur2/munin-regenwolken
#
# Example usage:
# Do
# ln -s /path/to/rw_ rw_<option>
# where <option> is one of users|files|size|hits
#
# Example config:
# [rw_*]
# env.url http://rw.example.org/
#
require 'csv'
require 'open-uri'
script = File.basename($0)
@option = script.gsub('rw_', '')
@cmd = ARGV[0]
# open stderr
$stderr = IO.new(2, "w")
def uri
ENV['url'] + '?format=csv'
end
raw_data = open(uri).read
# take only first row since we've given only one symbol
csv_data = CSV.parse(raw_data)
def echo_users(val)
case @cmd
when 'config'
puts "graph_title Registered users (#{ENV['url']})"
puts "graph_args --lower-limit 0"
puts "graph_vlabel users"
puts "graph_category regenwolken"
puts "graph_scale no"
puts "graph_info This graph shows the number of registered users."
puts "users.label registered users"
puts "users.info Number of registered users on #{ENV['url']}"
puts "users.type GAUGE"
else
puts "users.value #{val}"
end
end
def echo_files(val)
case @cmd
when 'config'
puts "graph_title Files (#{ENV['url']})"
puts "graph_args --lower-limit 0"
puts "graph_vlabel files"
puts "graph_category regenwolken"
puts "graph_scale no"
puts "graph_info This graph shows the number of hosted files."
puts "files.label files"
puts "files.info Number of hosted files on #{ENV['url']}"
puts "files.type GAUGE"
else
puts "files.value #{val}"
end
end
def echo_size(val)
case @cmd
when 'config'
puts "graph_title Database size (#{ENV['url']})"
puts "graph_args --lower-limit 0"
puts "graph_vlabel bytes"
puts "graph_category regenwolken"
puts "graph_scale no"
puts "graph_info This graph shows the size of all data stored in the database."
puts "size.label database size"
puts "size.info Size of all database on #{ENV['url']}"
puts "size.type GAUGE"
else
puts "size.value #{val}"
end
end
def echo_hits(val)
case @cmd
when 'config'
puts "graph_title Hits (#{ENV['url']})"
puts "graph_args --lower-limit 0"
puts "graph_vlabel hits"
puts "graph_category regenwolken"
puts "graph_scale no"
puts "graph_info This graph shows the number of items served."
puts "hits.label hits"
puts "hits.info Number of items served on #{ENV['url']}"
puts "hits.type GAUGE"
else
puts "hits.value #{val}"
end
end
case @option
when 'users'
echo_users(csv_data[0][1])
when 'files'
echo_files(csv_data[1][1])
when 'size'
echo_size(csv_data[2][1])
when 'hits'
echo_hits(csv_data[3][1])
else
$stderr.puts "Unknown option #{@option} for rw_!"
exit 1
end