gri 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.md +132 -0
- data/Rakefile +5 -0
- data/bin/grapher +17 -0
- data/bin/gri +5 -0
- data/bin/gricast +17 -0
- data/bin/grispark +5 -0
- data/bin/griwalk +9 -0
- data/bin/trad +19 -0
- data/bin/trad-http +17 -0
- data/gri.gemspec +21 -0
- data/lib/fluent/plugin/out_gri.rb +56 -0
- data/lib/gri/api.rb +28 -0
- data/lib/gri/app_collector.rb +154 -0
- data/lib/gri/app_walker.rb +23 -0
- data/lib/gri/blank.rb +49 -0
- data/lib/gri/builtindefs.rb +211 -0
- data/lib/gri/cast.rb +84 -0
- data/lib/gri/cgraph.rb +37 -0
- data/lib/gri/clist.rb +163 -0
- data/lib/gri/collector.rb +284 -0
- data/lib/gri/config.rb +134 -0
- data/lib/gri/ds_list.rb +166 -0
- data/lib/gri/format_helper.rb +112 -0
- data/lib/gri/gparams.rb +43 -0
- data/lib/gri/graph.rb +239 -0
- data/lib/gri/grapher.rb +70 -0
- data/lib/gri/ldb.rb +160 -0
- data/lib/gri/list.rb +242 -0
- data/lib/gri/log.rb +140 -0
- data/lib/gri/loop.rb +109 -0
- data/lib/gri/ltsv.rb +58 -0
- data/lib/gri/main.rb +107 -0
- data/lib/gri/mlog.rb +22 -0
- data/lib/gri/mmsgpack.rb +57 -0
- data/lib/gri/msnmp.rb +601 -0
- data/lib/gri/page.rb +235 -0
- data/lib/gri/pcollector.rb +209 -0
- data/lib/gri/plugin.rb +75 -0
- data/lib/gri/plugin/bootstrap.rb +65 -0
- data/lib/gri/plugin/cisco.rb +98 -0
- data/lib/gri/plugin/exec_collector.rb +89 -0
- data/lib/gri/plugin/juniper.rb +5 -0
- data/lib/gri/plugin/netsnmp.rb +8 -0
- data/lib/gri/plugin/ucdavis.rb +176 -0
- data/lib/gri/plugin/writer_fluentd.rb +26 -0
- data/lib/gri/polling_unit.rb +88 -0
- data/lib/gri/q.rb +5 -0
- data/lib/gri/request.rb +29 -0
- data/lib/gri/rrd.rb +438 -0
- data/lib/gri/scheduler.rb +68 -0
- data/lib/gri/sgraph.rb +147 -0
- data/lib/gri/spark.rb +94 -0
- data/lib/gri/tra_collector.rb +80 -0
- data/lib/gri/trad.rb +170 -0
- data/lib/gri/updater.rb +201 -0
- data/lib/gri/util_daemon.rb +19 -0
- data/lib/gri/util_marshal.rb +13 -0
- data/lib/gri/utils.rb +63 -0
- data/lib/gri/vendor.rb +76 -0
- data/lib/gri/version.rb +3 -0
- data/lib/gri/wmain.rb +67 -0
- data/lib/gri/writer.rb +184 -0
- data/mcollector +47 -0
- data/test/mock.rb +60 -0
- data/test/root/gra/.sysdb/sysdb.txt +3 -0
- data/test/root/gra/testhost/.records.txt +2 -0
- data/test/root/if.def +2 -0
- data/test/root/test.conf +4 -0
- data/test/root/testtab +9 -0
- data/test/root/testtab2 +2 -0
- data/test/root/tra/testhost/_/20130614 +20 -0
- data/test/test_app.rb +58 -0
- data/test/test_builtindefs.rb +24 -0
- data/test/test_collector.rb +58 -0
- data/test/test_config.rb +62 -0
- data/test/test_ds_list.rb +48 -0
- data/test/test_exec_collector.rb +33 -0
- data/test/test_format_helper.rb +68 -0
- data/test/test_graph.rb +69 -0
- data/test/test_ldb.rb +29 -0
- data/test/test_list.rb +65 -0
- data/test/test_log.rb +16 -0
- data/test/test_loop.rb +35 -0
- data/test/test_ltsv.rb +38 -0
- data/test/test_main.rb +19 -0
- data/test/test_mmsgpack.rb +27 -0
- data/test/test_msnmp.rb +147 -0
- data/test/test_page.rb +51 -0
- data/test/test_pcollector.rb +71 -0
- data/test/test_plugin.rb +62 -0
- data/test/test_plugin_cisco.rb +23 -0
- data/test/test_polling_unit.rb +58 -0
- data/test/test_request.rb +26 -0
- data/test/test_rrd.rb +53 -0
- data/test/test_rrd_updater.rb +139 -0
- data/test/test_scheduler.rb +31 -0
- data/test/test_tra_collector.rb +40 -0
- data/test/test_trad.rb +33 -0
- data/test/test_util_marshal.rb +17 -0
- data/test/test_utils.rb +15 -0
- data/test/test_vendor.rb +40 -0
- data/test/test_writer.rb +33 -0
- data/test/unittest_helper.rb +27 -0
- metadata +208 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4c84175fc709e40d212ba2e061702b661b7af37
|
4
|
+
data.tar.gz: da221f34b501545a97daa79da88a8432c22adbd2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c445fdeeb8c6bf84b6caedcafe31225b0c604173a2d4e6ca0a0fe5d79dde171d834c0d3016b3abee9e29ac1227ccb362f472936046e49aeabe55c3ede6b53af0
|
7
|
+
data.tar.gz: 9c67f041a8117dfd3d0c25ac1e17b64b0aae7473ed9ba632f3ed0e796bfc0c5f68c714b5a7d9ac8030177ddef9da3bd60edd74a07b44bc2ff560d8d423d1d190
|
data/.gitignore
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013, Internet Initiative Japan Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
## About
|
2
|
+
|
3
|
+
GRI is a monitoring tool that collects various data from network
|
4
|
+
devices such as routers, switches, and hosts, and creates a lot of
|
5
|
+
graphs from the collected data.
|
6
|
+
|
7
|
+
GRI uses rrdtool for data storage and visualization, and the framework
|
8
|
+
is written in Ruby.
|
9
|
+
|
10
|
+
## Quick start guide
|
11
|
+
|
12
|
+
### Requirements
|
13
|
+
|
14
|
+
* Unix OS
|
15
|
+
* apache or other web server that supports cgi
|
16
|
+
* rrdtool (1.0 or later, 1.4 later is highly recommended)
|
17
|
+
* Ruby (1.8.7 or later, 2.0 later is highly recommended)
|
18
|
+
* rack gem
|
19
|
+
|
20
|
+
### Installation
|
21
|
+
|
22
|
+
1. Install rrdtool
|
23
|
+
2. `gem install rack`, `gem install gri --no-ri --no-rdoc`
|
24
|
+
3. Copy the grapher cgi script into the directory for CGI executables used by your web server (commonly named cgi-bin). (e.g. `cp -p /usr/bin/grapher /var/www/cgi-bin`)
|
25
|
+
|
26
|
+
### Configuration
|
27
|
+
1. Create an administrative user for gri, e.g. "admin"
|
28
|
+
2. Set up the gri root directory.
|
29
|
+
<pre>
|
30
|
+
# mkdir /usr/local/gri
|
31
|
+
# chown admin /usr/local/gri
|
32
|
+
</pre>
|
33
|
+
Replace admin with the valid user that you created.
|
34
|
+
3. Create `/usr/local/gri/gritab` file;
|
35
|
+
gritab is a file used to specify the information collection target.
|
36
|
+
<pre>
|
37
|
+
host.example.com ver=2c community=public
|
38
|
+
router.example.com ver=2c community=xxxxxxxx
|
39
|
+
</pre>
|
40
|
+
4. (Optional) Create `/usr/local/gri/gri.conf` file;
|
41
|
+
gri.conf is a configuration file for setting GRI global parameters.
|
42
|
+
<pre>
|
43
|
+
root-dir /usr/local/gri
|
44
|
+
gritab-path /usr/local/gri/gritab
|
45
|
+
font DEFAULT:0:IPAPGothic
|
46
|
+
</pre>
|
47
|
+
5. Add a line to your /etc/crontab file similar to:
|
48
|
+
<pre>
|
49
|
+
*/5 * * * * admin /usr/bin/gri
|
50
|
+
</pre>
|
51
|
+
Replace admin with the valid user that you created.
|
52
|
+
6. visit `http://<your host>/<path to>/grapher`, e.g. `http://localhost/cgi-bin/grapher`
|
53
|
+
|
54
|
+
#### gritab
|
55
|
+
|
56
|
+
gritab is a file used to specify the information collection target.
|
57
|
+
By default, the file path is `/usr/local/gri/gritab`
|
58
|
+
|
59
|
+
Example:
|
60
|
+
<pre>
|
61
|
+
# gritab example
|
62
|
+
host.example.com ver=2c community=public
|
63
|
+
router.example.com ver=2c community=xxxxxxxx
|
64
|
+
</pre>
|
65
|
+
|
66
|
+
* A line beginning with # is a comment line.
|
67
|
+
* Each line consists of one host for which data is to be collected by GRI.
|
68
|
+
* The hosts can be specified in any order. They are SNMP-polled in the order specified.
|
69
|
+
* A host name can be followed by multiple options, each of which is separated by a space. When no option is specified, the default value is assumed.
|
70
|
+
|
71
|
+
##### Description of typical options
|
72
|
+
|
73
|
+
To disable (turn off) any of these options, specify `no-` at the beginning (example: `no-interfaces` stops collecting the interfaces MIB).
|
74
|
+
|
75
|
+
* community=COMMUNITY
|
76
|
+
|
77
|
+
Specifies the text string password for SNMPv1 or SNMPv2c systems. (default: public)
|
78
|
+
|
79
|
+
* interfaces
|
80
|
+
|
81
|
+
Specifies to get interfaces MIB. This option is enabled by default.
|
82
|
+
|
83
|
+
* type=TYPE,...
|
84
|
+
|
85
|
+
Specifies the data collection type. When this option is omitted, snmp is assumed. Multiple sets can be specified with each set separated by a comma.
|
86
|
+
|
87
|
+
* ver=VERSION
|
88
|
+
|
89
|
+
Specifies the snmp version supported by the agent. Available versions are "1" and "2c".
|
90
|
+
|
91
|
+
#### gri.conf
|
92
|
+
|
93
|
+
gri.conf is the settings file that determines the global operation of GRI.
|
94
|
+
By default, the file path is `/usr/local/gri/gri.conf`.
|
95
|
+
|
96
|
+
Example:
|
97
|
+
<pre>
|
98
|
+
# gri.conf example
|
99
|
+
root-dir /usr/local/gri
|
100
|
+
gritab-path /usr/local/gri/gritab
|
101
|
+
font DEFAULT:0:IPAPGothic
|
102
|
+
</pre>
|
103
|
+
|
104
|
+
##### Description of typical options
|
105
|
+
|
106
|
+
* root-dir *path*
|
107
|
+
|
108
|
+
Root directory of the GRI work directory [/usr/local/gri]
|
109
|
+
|
110
|
+
* tra-dir *path*
|
111
|
+
|
112
|
+
tra directory [root-dir + /tra]
|
113
|
+
|
114
|
+
* gra-dir *path*
|
115
|
+
|
116
|
+
gra directory [root-dir + /gra]
|
117
|
+
|
118
|
+
* log-dir *path*
|
119
|
+
|
120
|
+
log directory [root-dir + /log]
|
121
|
+
|
122
|
+
* plugin-dir *path*
|
123
|
+
|
124
|
+
plugin-dir [root-dir + /plugin]
|
125
|
+
|
126
|
+
* option *option*
|
127
|
+
|
128
|
+
Option to be added to all gritab targets. Multiple options can be specified.
|
129
|
+
|
130
|
+
* option-if-host *PAT* *option*
|
131
|
+
|
132
|
+
Option to be added to the default when the host name matches PAT (regexp). Multiple options can be specified.
|
data/Rakefile
ADDED
data/bin/grapher
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
if File.symlink? __FILE__
|
7
|
+
org_path = File.dirname(File.expand_path(File.readlink(__FILE__)))
|
8
|
+
else
|
9
|
+
org_path = File.dirname(File.expand_path(__FILE__))
|
10
|
+
end
|
11
|
+
$:.unshift org_path.untaint + '/../lib'
|
12
|
+
|
13
|
+
require 'gri/grapher'
|
14
|
+
|
15
|
+
wmain = GRI::WMain.new
|
16
|
+
wmain.app = GRI::Grapher.new
|
17
|
+
wmain.run
|
data/bin/gri
ADDED
data/bin/gricast
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
if File.symlink? __FILE__
|
7
|
+
org_path = File.dirname(File.expand_path(File.readlink(__FILE__)))
|
8
|
+
else
|
9
|
+
org_path = File.dirname(File.expand_path(__FILE__))
|
10
|
+
end
|
11
|
+
$:.unshift org_path.untaint + '/../lib'
|
12
|
+
|
13
|
+
require 'gri/cast'
|
14
|
+
|
15
|
+
wmain = GRI::WMain.new
|
16
|
+
wmain.app = GRI::Cast.new
|
17
|
+
wmain.run
|
data/bin/grispark
ADDED
data/bin/griwalk
ADDED
data/bin/trad
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
if File.symlink? __FILE__
|
4
|
+
org_path = File.dirname(File.expand_path(File.readlink(__FILE__)))
|
5
|
+
else
|
6
|
+
org_path = File.dirname(File.expand_path(__FILE__))
|
7
|
+
end
|
8
|
+
$:.unshift org_path.untaint + '/../lib'
|
9
|
+
|
10
|
+
require 'socket'
|
11
|
+
require 'optparse'
|
12
|
+
|
13
|
+
require 'gri/config'
|
14
|
+
require 'gri/log'
|
15
|
+
require 'gri/q'
|
16
|
+
require 'gri/util_daemon'
|
17
|
+
require 'gri/trad'
|
18
|
+
|
19
|
+
GRI::Trad.new.run
|
data/bin/trad-http
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
if File.symlink? __FILE__
|
7
|
+
org_path = File.dirname(File.expand_path(File.readlink(__FILE__)))
|
8
|
+
else
|
9
|
+
org_path = File.dirname(File.expand_path(__FILE__))
|
10
|
+
end
|
11
|
+
$:.unshift org_path.untaint + '/../lib'
|
12
|
+
|
13
|
+
require 'gri/wmain'
|
14
|
+
require 'gri/log'
|
15
|
+
require 'gri/trad'
|
16
|
+
|
17
|
+
GRI::WMain.new(GRI::Trad.new).run
|
data/gri.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "gri/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gri"
|
7
|
+
s.version = GRI::VERSION
|
8
|
+
s.authors = ["maebashi"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{GRI}
|
11
|
+
s.description = %q{GRI}
|
12
|
+
s.files = `git ls-files`.split("\n").select {|e| /^tmp/!~e}
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f
|
15
|
+
) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
# specify any dependencies here; for example:
|
19
|
+
|
20
|
+
s.add_runtime_dependency "rack"
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# coding: us-ascii
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
if File.symlink? __FILE__
|
6
|
+
pdir = File.dirname(File.expand_path(File.readlink(__FILE__)))
|
7
|
+
else
|
8
|
+
pdir = File.dirname(File.expand_path(__FILE__))
|
9
|
+
end
|
10
|
+
$LOAD_PATH.push pdir unless $LOAD_PATH.index pdir
|
11
|
+
pdir = pdir + '/../..'
|
12
|
+
$LOAD_PATH.push pdir unless $LOAD_PATH.index pdir
|
13
|
+
|
14
|
+
require 'gri/log'
|
15
|
+
require 'gri/builtindefs'
|
16
|
+
require 'gri/msnmp'
|
17
|
+
require 'gri/vendor'
|
18
|
+
require 'gri/plugin'
|
19
|
+
require 'gri/updater'
|
20
|
+
require 'gri/rrd'
|
21
|
+
require 'gri/ltsv'
|
22
|
+
|
23
|
+
module Fluent
|
24
|
+
|
25
|
+
class GriOutput < BufferedOutput
|
26
|
+
Plugin.register_output('gri', self)
|
27
|
+
|
28
|
+
config_param :gra_dir, :string, :default=>'/usr/local/gri/gra'
|
29
|
+
|
30
|
+
def configure conf
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
super
|
36
|
+
#::Log.init '/tmp/fluent.log'
|
37
|
+
GRI::Plugin.load_plugins []
|
38
|
+
GRI::Config.init
|
39
|
+
end
|
40
|
+
|
41
|
+
def format tag, time, record
|
42
|
+
[tag, time, record].to_msgpack
|
43
|
+
end
|
44
|
+
|
45
|
+
def write chunk
|
46
|
+
records = []
|
47
|
+
chunk.msgpack_each {|tag, time, record|
|
48
|
+
records.push record
|
49
|
+
}
|
50
|
+
writer = GRI::Writer.create 'rrd', :gra_dir=>@gra_dir
|
51
|
+
writer.write records
|
52
|
+
writer.finalize
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/gri/api.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'gri/updater'
|
3
|
+
|
4
|
+
module GRI
|
5
|
+
class API
|
6
|
+
def call env
|
7
|
+
if env['PATH_INFO'] =~ %r{^/api/(\w+)/(\w+)/(\w+)\b}
|
8
|
+
service_name, section_name, graph_name = $1, $2, $3
|
9
|
+
req = Rack::Request.new env
|
10
|
+
root_dir = Config['root-dir'] || Config::ROOT_PATH
|
11
|
+
cast_dir = root_dir + '/cast'
|
12
|
+
service_dir = "#{cast_dir}/#{service_name}"
|
13
|
+
host = section_name
|
14
|
+
key = "num_#{graph_name}"
|
15
|
+
FileUtils.mkdir_p service_dir
|
16
|
+
|
17
|
+
records = [{'_host'=>host, '_key'=>key, 'num'=>req['number']}]
|
18
|
+
writer = Writer.create 'rrd', :gra_dir=>service_dir, :interval=>60
|
19
|
+
writer.write records
|
20
|
+
writer.finalize
|
21
|
+
res = "OK\n"
|
22
|
+
else
|
23
|
+
res = "NG\n"
|
24
|
+
end
|
25
|
+
[200, {}, [res]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'gri/config'
|
2
|
+
require 'gri/scheduler'
|
3
|
+
require 'gri/collector'
|
4
|
+
require 'gri/loop'
|
5
|
+
require 'gri/writer'
|
6
|
+
require 'gri/q'
|
7
|
+
|
8
|
+
module GRI
|
9
|
+
class AppCollector
|
10
|
+
attr_reader :config, :writers, :metrics
|
11
|
+
|
12
|
+
def initialize config
|
13
|
+
@config = config
|
14
|
+
@writers = []
|
15
|
+
@metrics = Hash.new 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
start_time = Time.now
|
20
|
+
root_dir = config['root-dir'] ||= Config::ROOT_PATH
|
21
|
+
|
22
|
+
lines = load_target_lines config
|
23
|
+
targets = get_targets_from_lines lines, config
|
24
|
+
|
25
|
+
files = Config.getvar 'fake-descr-file'
|
26
|
+
fdh = load_fake_descr_files files if files
|
27
|
+
|
28
|
+
if config['updater']
|
29
|
+
if (tra_str = config['tra'])
|
30
|
+
tra_uri = get_tra_uri tra_str
|
31
|
+
TraCollector.tra_uri = tra_uri
|
32
|
+
TraCollector.db_class = RemoteLDB
|
33
|
+
else
|
34
|
+
tra_dir = config['tra-dir'] || root_dir + '/tra'
|
35
|
+
TraCollector.tra_dir = tra_dir
|
36
|
+
TraCollector.db_class = LocalLDB
|
37
|
+
end
|
38
|
+
|
39
|
+
gra_dir = config['gra-dir'] || root_dir + '/gra'
|
40
|
+
Dir.mkdir gra_dir unless File.directory? gra_dir
|
41
|
+
TraCollector.gra_dir = gra_dir
|
42
|
+
scheduler_class = UScheduler
|
43
|
+
h = {}
|
44
|
+
targets.each {|ary|
|
45
|
+
(hostname = ary[1]['hostname'] || ary[1]['alias']) and
|
46
|
+
(ary[0] = hostname)
|
47
|
+
}
|
48
|
+
targets = targets.select {|host, | f = h[host]; h[host] = true; !f}
|
49
|
+
else
|
50
|
+
scheduler_class = Scheduler
|
51
|
+
end
|
52
|
+
|
53
|
+
Log.info "START: pid #{$$}"
|
54
|
+
if config['para']
|
55
|
+
run_para targets, scheduler_class, start_time.to_i, fdh
|
56
|
+
else
|
57
|
+
run_single targets, scheduler_class, start_time.to_i, fdh
|
58
|
+
end
|
59
|
+
for writer in @writers
|
60
|
+
if writer.respond_to? :merge
|
61
|
+
writer.merge
|
62
|
+
end
|
63
|
+
if writer.respond_to? :purge_logs
|
64
|
+
writer.purge_logs
|
65
|
+
end
|
66
|
+
end
|
67
|
+
Log.info "END: pid #{$$}"
|
68
|
+
@metrics['targets'] = targets.size
|
69
|
+
@metrics['collector_elapsed'] = Time.now - start_time
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_host_key s
|
73
|
+
s.to_s.scan(/\A([-\.A-Za-z0-9]+)_([^_\d]*)(?:_?(.*))/).first
|
74
|
+
end
|
75
|
+
|
76
|
+
def load_fake_descr_files files
|
77
|
+
h = {}
|
78
|
+
for path in files
|
79
|
+
if File.exist? path
|
80
|
+
open(path) {|f|
|
81
|
+
while line = f.gets
|
82
|
+
if line =~ /\A([-\.\dA-Za-z]+_\S+)\s+(.*)/
|
83
|
+
descr = $2
|
84
|
+
host, key = $1.split(/_/, 2)
|
85
|
+
(h[host] ||= {})[key] = descr
|
86
|
+
end
|
87
|
+
end
|
88
|
+
}
|
89
|
+
end
|
90
|
+
end
|
91
|
+
h
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_tra_uri tra_str
|
95
|
+
if tra_str =~ /\A[-\w\.]+(:\d+)\z/
|
96
|
+
tra_str = "http://#{tra_str}/"
|
97
|
+
elsif tra_str =~ /\A[-\w\.]+\z/
|
98
|
+
tra_str = "http://#{tra_str}:7080/"
|
99
|
+
end
|
100
|
+
uri = URI.parse tra_str rescue nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def load_target_lines config
|
104
|
+
if config['updater'] and (tra_str = config['tra']) and
|
105
|
+
!config['gritab-path']
|
106
|
+
tra_uri = get_tra_uri tra_str
|
107
|
+
lines = RemoteLDB.get_gritab_lines tra_uri
|
108
|
+
else
|
109
|
+
root_dir = config['root-dir'] ||= Config::ROOT_PATH
|
110
|
+
gritab_path = config['gritab-path'] || root_dir + '/gritab'
|
111
|
+
lines = []
|
112
|
+
File.open(gritab_path) {|f|
|
113
|
+
while line = f.gets
|
114
|
+
lines.push line
|
115
|
+
end
|
116
|
+
}
|
117
|
+
end
|
118
|
+
lines
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_targets_from_lines lines, config
|
122
|
+
targets = Config.get_targets_from_lines lines
|
123
|
+
goptions = Config.parse_options(*(config.getvar 'option'))
|
124
|
+
goptions.merge!(Config.parse_options(*config['O']))
|
125
|
+
if config['host-pat']
|
126
|
+
hosts_re = config.getvar('host-pat').map {|h| Regexp.new h}
|
127
|
+
targets = targets.select {|host, | hosts_re.detect {|re| re === host}}
|
128
|
+
#re = Regexp.new config['host-pat']
|
129
|
+
#targets = targets.select {|host, options| re === host}
|
130
|
+
end
|
131
|
+
for host, options in targets
|
132
|
+
hoptions = goptions.clone
|
133
|
+
hoptions.merge! Config.option_if_match(host, 'option-if-host', config)
|
134
|
+
hoptions.merge! options
|
135
|
+
options.replace hoptions
|
136
|
+
end
|
137
|
+
targets
|
138
|
+
end
|
139
|
+
|
140
|
+
def run_para targets, scheduler_class, start_time, fdh
|
141
|
+
end
|
142
|
+
|
143
|
+
def run_single targets, scheduler_class, start_time, fdh
|
144
|
+
loop = Loop.new
|
145
|
+
@writers.each {|writer| writer.loop = loop}
|
146
|
+
scheduler = scheduler_class.new loop, @metrics
|
147
|
+
scheduler.writers = @writers
|
148
|
+
scheduler.queue = targets
|
149
|
+
scheduler.process_queue
|
150
|
+
loop.run
|
151
|
+
scheduler.finalize
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|