opstat-client 0.3.8
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 +1 -0
- data/.gitlab-ci.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/TODO +4 -0
- data/TODO_NOW +5 -0
- data/bin/opstatd_client.rb +19 -0
- data/init.d/opstatd_client +21 -0
- data/init.d/opstatd_client.redhat +68 -0
- data/lib/opstat-client/client.rb +85 -0
- data/lib/opstat-client/common.rb +28 -0
- data/lib/opstat-client/config/opstat.yml +60 -0
- data/lib/opstat-client/config.rb +72 -0
- data/lib/opstat-client/config_opstat.yml +24 -0
- data/lib/opstat-client/logging.rb +29 -0
- data/lib/opstat-client/plugins.rb +54 -0
- data/lib/opstat-client.rb +26 -0
- data/opstat-client.gemspec +28 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d1ea8176a0ae19152d159fc58fb2b72f8edd52620e7b53fe44b65dbd06ca359
|
4
|
+
data.tar.gz: 7750313b8d5e8f94d722a0e4dd21b6f4344934a98c1ff730105567adeee715b2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63143d45bfbf7634136ab94dfb033de9c24fe1ffdd87bed46d9e332d28a57a068a66a46e8119d50af40227a85227c5602333d72daa1811bc7803545c0fb9cd0e
|
7
|
+
data.tar.gz: 74feed2f2636cb2c7c473ca5c3f7c7f98ac94cc9bea170d68eb952c2a0ee8cd02243a59ac0d82074c7e136c92f22546976264d2b8c8d4ae524b6ae701c82c700
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
before_script:
|
2
|
+
- ruby -v # Print out ruby version for debugging
|
3
|
+
- gem install rspec
|
4
|
+
- gem build opstat-client.gemspec
|
5
|
+
# Uncomment next line if your rails app needs a JS runtime:
|
6
|
+
# - apt-get update -q && apt-get install nodejs -yqq
|
7
|
+
# - gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
|
8
|
+
# - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
9
|
+
|
10
|
+
rspec:
|
11
|
+
script:
|
12
|
+
- rspec spec
|
13
|
+
|
14
|
+
01_create_gem:
|
15
|
+
script:
|
16
|
+
- "cp opstat-client-`ruby -e 'require \"./lib/opstat-client/version.rb\"; puts Opstat.version'`.gem /home/builds/admin/opstat-client"
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Krzysztof Tomczyk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Opstat
|
2
|
+
|
3
|
+
iCollect and analyze statistics for opstat analytics system
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Clone this repository
|
8
|
+
|
9
|
+
cd into repository base
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ gem build
|
14
|
+
|
15
|
+
Next install created gem as:
|
16
|
+
|
17
|
+
$ gem install opstat-client-0.0.2.gem
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Configure it via /etc/opstat/opstat.yml
|
22
|
+
Run command opstatd-client
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/TODO
ADDED
data/TODO_NOW
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/ruby19
|
2
|
+
#
|
3
|
+
require 'rubygems'
|
4
|
+
require 'daemons'
|
5
|
+
require 'optparse'
|
6
|
+
require 'opstat-client'
|
7
|
+
|
8
|
+
|
9
|
+
Daemons.run_proc(
|
10
|
+
'opstatd_client', # name of daemon
|
11
|
+
# :dir_mode => :normal
|
12
|
+
:dir => '/var/run', # directory where pid file will be stored
|
13
|
+
:backtrace => true,
|
14
|
+
# :monitor => true,
|
15
|
+
:log_dir => '/var/log',
|
16
|
+
:log_output => true
|
17
|
+
) do
|
18
|
+
Opstat::Client.main_loop
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/sbin/runscript
|
2
|
+
# Copyright 1999-2013 Gentoo Foundation
|
3
|
+
# Distributed under the terms of the GNU General Public License v2
|
4
|
+
# $Header: $
|
5
|
+
|
6
|
+
depend() {
|
7
|
+
need net
|
8
|
+
}
|
9
|
+
|
10
|
+
#TODO - parameters - log file, config file, etc.
|
11
|
+
start() {
|
12
|
+
ebegin Starting opstat client
|
13
|
+
opstatd_client.rb start
|
14
|
+
eend $?
|
15
|
+
}
|
16
|
+
|
17
|
+
stop() {
|
18
|
+
ebegin Stoping opstat client
|
19
|
+
opstatd_client.rb stop
|
20
|
+
eend $?
|
21
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# Created 2013-04-07 by office@optilabs.eu
|
4
|
+
#
|
5
|
+
# opstatd_client This shell script takes care of starting and stopping
|
6
|
+
# opstatd_client.
|
7
|
+
#
|
8
|
+
# chkconfig: - 90 10
|
9
|
+
# description: opstatd_client is a daemon for gathering system performance data
|
10
|
+
# processname: opstatd_client
|
11
|
+
# config: /etc/opstat/config_opstat.yml
|
12
|
+
|
13
|
+
|
14
|
+
# Source function library
|
15
|
+
if [ -f /etc/rc.d/init.d/functions ]; then
|
16
|
+
. /etc/rc.d/init.d/functions
|
17
|
+
elif [ -f /etc/init.d/functions ]; then
|
18
|
+
. /etc/init.d/functions
|
19
|
+
elif [ -f /etc/rc.d/functions ]; then
|
20
|
+
. /etc/rc.d/functions
|
21
|
+
fi
|
22
|
+
|
23
|
+
# Source networking configuration.
|
24
|
+
. /etc/sysconfig/network
|
25
|
+
|
26
|
+
# Read configuration (environment etc.) for nrpe and plugins
|
27
|
+
if [ -f /etc/sysconfig/opstatd_client ]; then
|
28
|
+
. /etc/sysconfig/opstatd_client
|
29
|
+
fi
|
30
|
+
|
31
|
+
# Check that networking is up.
|
32
|
+
[ ${NETWORKING} = "no" ] && exit 0
|
33
|
+
|
34
|
+
RETVAL=0
|
35
|
+
|
36
|
+
# See how we were called.
|
37
|
+
case "$1" in
|
38
|
+
start)
|
39
|
+
# Start daemons.
|
40
|
+
echo -n "Starting opstatd_client: "
|
41
|
+
opstatd_client.rb start
|
42
|
+
RETVAL=$?
|
43
|
+
echo
|
44
|
+
[ $RETVAL = 0 ]
|
45
|
+
;;
|
46
|
+
stop)
|
47
|
+
# Stop daemons.
|
48
|
+
echo -n "Shutting down opstatd_client: "
|
49
|
+
opstatd_client.rb stop
|
50
|
+
RETVAL=$?
|
51
|
+
echo
|
52
|
+
[ $RETVAL = 0 ]
|
53
|
+
;;
|
54
|
+
restart)
|
55
|
+
$0 stop
|
56
|
+
$0 start
|
57
|
+
;;
|
58
|
+
status)
|
59
|
+
opstatd_client.rb status
|
60
|
+
RETVAL=$?
|
61
|
+
;;
|
62
|
+
*)
|
63
|
+
echo "Usage: opstatd_client {start|stop|restart|status}"
|
64
|
+
RETVAL=2
|
65
|
+
esac
|
66
|
+
|
67
|
+
exit $RETVAL
|
68
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
include Opstat::Common
|
6
|
+
|
7
|
+
|
8
|
+
module Opstat
|
9
|
+
module SendData
|
10
|
+
extend Logging
|
11
|
+
def self.send_from_queue(q, ex, name)
|
12
|
+
#TODO cache-evealuate only at start time
|
13
|
+
begin
|
14
|
+
@hostname ||= Socket.gethostname
|
15
|
+
@ip_address ||= Socket::getaddrinfo(@hostname,"echo",Socket::AF_INET)[0][3]
|
16
|
+
data_to_send = {:collected_data => []}
|
17
|
+
|
18
|
+
|
19
|
+
1.upto(q.size) do
|
20
|
+
q.pop do |data|
|
21
|
+
data_to_send[:collected_data] << data
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# TODO auto register - assign some unique id for a new host instead of hostname, ip_address pai
|
26
|
+
data_to_send[:hostname] = @hostname
|
27
|
+
data_to_send[:ip_address] = @ip_address
|
28
|
+
data_to_send[:version] = Opstat.version
|
29
|
+
custom_tags = Opstat::Config.instance.get('client')['custom_tags']
|
30
|
+
data_to_send[:custom_tags] = Opstat::Config.instance.get('client')['custom_tags'] if custom_tags
|
31
|
+
data_to_send[:send_data_interval] = Opstat::Config.instance.get('client')['send_data_interval']
|
32
|
+
|
33
|
+
ex.publish data_to_send.to_json, :routing_key => name
|
34
|
+
rescue SocketError
|
35
|
+
raise "Unable to resolve hostname #{Socket.gethostname}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def unbind
|
40
|
+
oplogger.info 'AMQP Connection closed'
|
41
|
+
# EventMachine::stop_event_loop
|
42
|
+
end
|
43
|
+
end #module SendData
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
module Client
|
48
|
+
extend Logging
|
49
|
+
def self.main_loop
|
50
|
+
oplogger.info 'Starting client main loop'
|
51
|
+
queue = EM::Queue.new
|
52
|
+
mq_config = Opstat::Config.instance.get_mq_config
|
53
|
+
send_data_interval = Opstat::Config.instance.get('client')['send_data_interval']
|
54
|
+
@a_plugins = Opstat::Plugins.create_plugins(queue)
|
55
|
+
EventMachine::run do
|
56
|
+
AMQP.start(mq_config) do |connection|
|
57
|
+
connection.on_tcp_connection_loss do |conn, settings|
|
58
|
+
oplogger.warn "[network failure] Trying to reconnect..."
|
59
|
+
conn.reconnect(false, 2)
|
60
|
+
end
|
61
|
+
|
62
|
+
oplogger.info "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
|
63
|
+
|
64
|
+
channel = AMQP::Channel.new(connection,:auto_recovery => true)
|
65
|
+
channel.on_error do |ch, channel_close|
|
66
|
+
oplogger.error "AMQP channel error"
|
67
|
+
raise channel_close.reply_text
|
68
|
+
end
|
69
|
+
|
70
|
+
ampqqueue = channel.queue(mq_config['queue_name'], :auto_delete => false, :durable => true)
|
71
|
+
exchange = channel.default_exchange
|
72
|
+
|
73
|
+
@a_plugins.each do |task|
|
74
|
+
if task.external_plugin_needed?
|
75
|
+
task.set_external_plugin = EventMachine::open_datagram_socket task.external_plugin['address'], task.external_plugin['port'], Opstat::Plugins::UDPExternalPlugins::Apache2, task.external_plugin
|
76
|
+
end
|
77
|
+
EventMachine::add_periodic_timer(task.interval) {task.parse_and_queue}
|
78
|
+
end
|
79
|
+
|
80
|
+
EventMachine::add_periodic_timer(send_data_interval) { Opstat::SendData.send_from_queue(queue, exchange, ampqqueue.name) }
|
81
|
+
end
|
82
|
+
end #EventMachine::run do
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Opstat
|
2
|
+
module Common
|
3
|
+
def self.camelize(term)
|
4
|
+
string = term.to_s
|
5
|
+
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
|
6
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.constantize(class_name)
|
10
|
+
names = class_name.split('::')
|
11
|
+
names.shift if names.empty? || names.first.empty?
|
12
|
+
|
13
|
+
constant = Object
|
14
|
+
names.each do |n|
|
15
|
+
name = Opstat::Common.camelize(n)
|
16
|
+
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
17
|
+
end
|
18
|
+
constant
|
19
|
+
end
|
20
|
+
|
21
|
+
def constantize(camel_cased_word)
|
22
|
+
Opstat::Common.constantize(camel_cased_word)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#TODO load only if run on main server
|
@@ -0,0 +1,60 @@
|
|
1
|
+
client:
|
2
|
+
send_data_interval: 60
|
3
|
+
log_level: INFO
|
4
|
+
|
5
|
+
mq:
|
6
|
+
queue_name: amqpgem.test.hello_world
|
7
|
+
:host: 10.5.0.10
|
8
|
+
:user: opstat
|
9
|
+
:password: password
|
10
|
+
|
11
|
+
plugins:
|
12
|
+
cpu:
|
13
|
+
interval: 10
|
14
|
+
load:
|
15
|
+
interval: 15
|
16
|
+
memory:
|
17
|
+
interval: 30
|
18
|
+
network:
|
19
|
+
interval: 30
|
20
|
+
disk:
|
21
|
+
interval: 600
|
22
|
+
facts:
|
23
|
+
interval: 21600
|
24
|
+
# apache2:
|
25
|
+
# log_level: DEBUG
|
26
|
+
# interval: 30
|
27
|
+
# external_plugin:
|
28
|
+
# log_level: DEBUG
|
29
|
+
# address: 127.0.0.1
|
30
|
+
# port: 55555
|
31
|
+
# log_format: '%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O'
|
32
|
+
# oracle_sessions:
|
33
|
+
# interval: 180
|
34
|
+
# su_user: oracle
|
35
|
+
# db_user: db_user
|
36
|
+
# db_password: db_password
|
37
|
+
# oracle_fras_sizes:
|
38
|
+
# interval: 7200
|
39
|
+
# su_user: oracle
|
40
|
+
# db_user: db_user
|
41
|
+
# db_password: db_password
|
42
|
+
# oracle_tablespaces_sizes:
|
43
|
+
# interval: 3600
|
44
|
+
# su_user: oracle
|
45
|
+
# db_user: db_user
|
46
|
+
# db_password: db_password
|
47
|
+
# webobjects:
|
48
|
+
# interval: 60
|
49
|
+
# wotask_password: secret
|
50
|
+
# wotask_url: http://127.0.0.1:1085/cgi-bin/WebObjects/wotaskd.woa/wa/monitorRequest
|
51
|
+
#
|
52
|
+
# fpm:
|
53
|
+
# interval: 30
|
54
|
+
# log_level: DEBUG
|
55
|
+
# pools:
|
56
|
+
# www:
|
57
|
+
# fcgi_socket: /var/run/wypozycz.pl-fpm.socket
|
58
|
+
# status_url: /status
|
59
|
+
# request_method: GET
|
60
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module Opstat
|
3
|
+
# A pretty sucky config class, ripe for refactoring/improving
|
4
|
+
class Config
|
5
|
+
include Opstat::Logging
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@configured = false
|
10
|
+
@config = ''
|
11
|
+
#TODO set defaults
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_config(config_file)
|
15
|
+
unless File.exists?(config_file)
|
16
|
+
preconfig_logger.info 'No config file - create config file with default settings. Please set correct MQ settings'
|
17
|
+
default_config_path = File.dirname(File.expand_path(__FILE__)) + '/config/opstat.yml'
|
18
|
+
system_config_dir = '/etc/opstat'
|
19
|
+
system_config_path = system_config_dir + '/opstat.yml'
|
20
|
+
FileUtils.mkdir(system_config_dir) unless File.exists?(system_config_dir)
|
21
|
+
FileUtils.cp(default_config_path,system_config_path)
|
22
|
+
end
|
23
|
+
@config = YAML.load_file(config_file)
|
24
|
+
self.set_defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_defaults
|
28
|
+
@config['client']['send_data_interval'] ||= 30
|
29
|
+
@config['client']['log_level'] ||= "WARN"
|
30
|
+
end
|
31
|
+
|
32
|
+
def get(key)
|
33
|
+
@config[key]
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_mq_config
|
37
|
+
get('mq')
|
38
|
+
end
|
39
|
+
|
40
|
+
def init_config(options)
|
41
|
+
load_config(options[:config_file])
|
42
|
+
set_defaults
|
43
|
+
@config[:config_file] = options[:config_file]
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
options = {}
|
49
|
+
optparse = OptionParser.new do|opts|
|
50
|
+
# Set a banner, displayed at the top
|
51
|
+
# of the help screen.
|
52
|
+
opts.banner = "Usage: command [options]"
|
53
|
+
|
54
|
+
options[:verbose] = false
|
55
|
+
opts.on( '-v', '--verbose', 'Output more information' ) do
|
56
|
+
options[:verbose] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
#TODO required options
|
60
|
+
opts.on( '-c', '--config-file String', :required, "Config file path" ) do|l|
|
61
|
+
options[:config_file] = l
|
62
|
+
end
|
63
|
+
options[:config_file] ||= '/etc/opstat/opstat.yml'
|
64
|
+
|
65
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
66
|
+
puts opts
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
optparse.parse!
|
71
|
+
|
72
|
+
Opstat::Config.instance.init_config(options)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
client:
|
2
|
+
send_data_interval: 10
|
3
|
+
|
4
|
+
mq:
|
5
|
+
queue_name: opstat
|
6
|
+
queue_address: 10.5.0.10
|
7
|
+
|
8
|
+
plugins:
|
9
|
+
cpu:
|
10
|
+
interval: 3
|
11
|
+
load:
|
12
|
+
interval: 5
|
13
|
+
# nagios:
|
14
|
+
# interval: 1800
|
15
|
+
# meminfo:
|
16
|
+
# interval: 4
|
17
|
+
# diskstats:
|
18
|
+
# interval: 5
|
19
|
+
# vmstat:
|
20
|
+
# interval: 3
|
21
|
+
connectionusage:
|
22
|
+
interval: 3
|
23
|
+
# facter:
|
24
|
+
# interval: 21600
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module Opstat
|
4
|
+
module Logging
|
5
|
+
def preconfig_logger
|
6
|
+
return @logger if @logger
|
7
|
+
@logger = Log4r::Logger.new self.class.to_s
|
8
|
+
@logger.level = @logger.levels.index('INFO')
|
9
|
+
outputter = Log4r::Outputter.stdout
|
10
|
+
outputter.formatter = Log4r::PatternFormatter.new(:pattern => "%l - %C - %m")
|
11
|
+
@logger.outputters << outputter
|
12
|
+
@logger
|
13
|
+
end
|
14
|
+
def oplogger
|
15
|
+
return @logger if @logger
|
16
|
+
@logger = Log4r::Logger.new self.class.to_s
|
17
|
+
@logger.level = @logger.levels.index(log_level)
|
18
|
+
outputter = Log4r::Outputter.stdout
|
19
|
+
outputter.formatter = Log4r::PatternFormatter.new(:pattern => "%l - %C - %m")
|
20
|
+
@logger.outputters << outputter
|
21
|
+
@logger
|
22
|
+
end
|
23
|
+
def log_level
|
24
|
+
@log_level ||= Opstat::Config.instance.get('client')['log_level']
|
25
|
+
@log_level
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Opstat
|
2
|
+
module Plugins
|
3
|
+
extend Opstat::Logging
|
4
|
+
#TODO make subclases of task -> task_command. task_parse <- and then inherit plugins from it?
|
5
|
+
# task_command - u analyze output of the command, task_parse - just parse the file in /proc or other
|
6
|
+
def self.create_plugins(queue)
|
7
|
+
plugins = []
|
8
|
+
Opstat::Config.instance.get('plugins').each_pair do |name, conf|
|
9
|
+
conf['log_level'] ||= Opstat::Config.instance.get('client')['log_level']
|
10
|
+
oplogger.info "Loading #{name} plugin with properties #{conf.inspect}"
|
11
|
+
Opstat::Plugins.load_plugin(name)
|
12
|
+
plugin_name = name
|
13
|
+
class_name = "Opstat::Plugins::#{name}"
|
14
|
+
task = Opstat::Common.constantize(class_name).new(plugin_name, queue, conf)
|
15
|
+
plugins << task
|
16
|
+
end
|
17
|
+
plugins
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
class Task
|
22
|
+
include Opstat::Logging
|
23
|
+
attr_accessor :interval, :next_run#, :next_run#, :data, :data_sended
|
24
|
+
|
25
|
+
def initialize (name, queue, config)
|
26
|
+
@name = name
|
27
|
+
@queue = queue
|
28
|
+
@interval = config['interval']
|
29
|
+
@interval ||= 60
|
30
|
+
@data_sended = {}
|
31
|
+
@count_number = 0 #TODO how big it should be
|
32
|
+
@send_number = 0 #TODO how big it should be
|
33
|
+
@log_level = config['log_level']
|
34
|
+
@run = config['run']
|
35
|
+
@external_plugin = config['external_plugin']
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_and_queue
|
39
|
+
oplogger.info "collecting stats"
|
40
|
+
report = parse
|
41
|
+
oplogger.debug report
|
42
|
+
@queue.push({ :timestamp => Time.now, :plugin => @name, :data => report, :interval => @interval})
|
43
|
+
end
|
44
|
+
|
45
|
+
def external_plugin_needed?
|
46
|
+
if @external_plugin.nil?
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
rescue LoadError
|
4
|
+
end
|
5
|
+
require 'singleton'
|
6
|
+
require 'opstat-client/common.rb'
|
7
|
+
require 'opstat-client/logging.rb'
|
8
|
+
require 'opstat-client/config.rb'
|
9
|
+
require 'yaml'
|
10
|
+
require 'opstat-plugins'
|
11
|
+
require "opstat-client/plugins.rb"
|
12
|
+
require 'eventmachine'
|
13
|
+
require 'amqp'
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
# see the bottom of the file for further inclusions
|
17
|
+
require 'opstat-client/client.rb'
|
18
|
+
|
19
|
+
#------------------------------------------------------------
|
20
|
+
# the top-level module
|
21
|
+
#
|
22
|
+
# all this really does is dictate how the whole system behaves, through
|
23
|
+
# preferences for things like debugging
|
24
|
+
#
|
25
|
+
# it's also a place to find top-level commands like 'debug'
|
26
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require '../version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "opstat-client"
|
8
|
+
spec.version = Opstat::VERSION
|
9
|
+
spec.authors = ["Krzysztof Tomczyk"]
|
10
|
+
spec.email = ["office@optilabs.eu"]
|
11
|
+
spec.description = %q{Systems monitoring tool}
|
12
|
+
spec.summary = %q{Systems monitoring tool that works}
|
13
|
+
spec.homepage = "http://www.optilabs.eu/opstat"
|
14
|
+
spec.license = "GPL-3.0"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "eventmachine", '~> 1'
|
22
|
+
spec.add_dependency "opstat-plugins", Opstat::VERSION
|
23
|
+
spec.add_dependency "json", '~> 2'
|
24
|
+
spec.add_dependency "log4r", '~> 1'
|
25
|
+
spec.add_dependency "amqp", '~> 1'
|
26
|
+
spec.add_dependency "xml-simple", '~> 1'
|
27
|
+
spec.add_dependency "daemons", '~> 1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opstat-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Tomczyk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: opstat-plugins
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.8
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: log4r
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: amqp
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: xml-simple
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: daemons
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1'
|
111
|
+
description: Systems monitoring tool
|
112
|
+
email:
|
113
|
+
- office@optilabs.eu
|
114
|
+
executables:
|
115
|
+
- opstatd_client.rb
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".gitlab-ci.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- TODO
|
126
|
+
- TODO_NOW
|
127
|
+
- bin/opstatd_client.rb
|
128
|
+
- init.d/opstatd_client
|
129
|
+
- init.d/opstatd_client.redhat
|
130
|
+
- lib/opstat-client.rb
|
131
|
+
- lib/opstat-client/client.rb
|
132
|
+
- lib/opstat-client/common.rb
|
133
|
+
- lib/opstat-client/config.rb
|
134
|
+
- lib/opstat-client/config/opstat.yml
|
135
|
+
- lib/opstat-client/config_opstat.yml
|
136
|
+
- lib/opstat-client/logging.rb
|
137
|
+
- lib/opstat-client/plugins.rb
|
138
|
+
- opstat-client.gemspec
|
139
|
+
homepage: http://www.optilabs.eu/opstat
|
140
|
+
licenses:
|
141
|
+
- GPL-3.0
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.2.33
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Systems monitoring tool that works
|
162
|
+
test_files: []
|