htmon-agent 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/htmon-agent +17 -0
- data/htmon-agent.gemspec +27 -0
- data/lib/htmon/agent/version.rb +5 -0
- data/lib/htmon/agent.rb +63 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22ca80734468bbba8b7128f91382ef355e4c1771
|
4
|
+
data.tar.gz: 253453a217bfd31411829f06dfcb36bbbdb34ae7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69aa62359783648f70dc0d674b927511b120605c96ea8726f8457e6776a6f11a341b471313b3f5a3187ae97f8b6c3b8d7704281520c60541151f51d2e0a70048
|
7
|
+
data.tar.gz: b594ed8078e96d79735dc1e8e1985ccaab492cc405837aa55f389804ea07d2d1424bd16a4173aec3ecf2b78db41af5bebe033bdecc95c01a8f840a8e8abd08c9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tim Foerster
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Htmon::Agent
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/htmon/agent`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'htmon-agent'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install htmon-agent
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/htmon-agent.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "htmon/agent"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/htmon-agent
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'htmon/agent'
|
4
|
+
|
5
|
+
Conf = Struct.new(:api, :config).new
|
6
|
+
|
7
|
+
ARGV.each.with_index do |argument,i|
|
8
|
+
case argument
|
9
|
+
when '--api' then Conf.api = ARGV[i+1]
|
10
|
+
when '--config' then Conf.config = ARGV[i+1]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV['htmon_api'] = Conf.api if Conf.api
|
15
|
+
abort("config missing") unless Conf.config
|
16
|
+
|
17
|
+
Htmon::Agent.start(config: Conf.config)
|
data/htmon-agent.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'htmon/agent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "htmon-agent"
|
8
|
+
spec.version = Htmon::Agent::VERSION
|
9
|
+
spec.authors = ["Tim Foerster"]
|
10
|
+
spec.email = ["github@mailserver.1n3t.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{HTTP Monitoring agent.}
|
13
|
+
spec.homepage = "https://github.com/timmyArch/htmon-agent"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
|
25
|
+
spec.add_dependency "rest-client"
|
26
|
+
spec.add_dependency "activesupport"
|
27
|
+
end
|
data/lib/htmon/agent.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "htmon/agent/version"
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module Htmon
|
7
|
+
module Agent
|
8
|
+
|
9
|
+
Check ||= Struct.new :callback, :interval, :launched_at
|
10
|
+
|
11
|
+
def checks
|
12
|
+
@checks ||= []
|
13
|
+
end
|
14
|
+
|
15
|
+
def remote
|
16
|
+
raise "Missing remote, fill ENV['htmon_api']" unless ENV['htmon_api']
|
17
|
+
"#{ENV['htmon_api'].to_s.gsub(/\/$/,'')}/api/v1/metrics/"
|
18
|
+
end
|
19
|
+
|
20
|
+
def start config: nil
|
21
|
+
load config
|
22
|
+
logger = Logger.new(STDOUT)
|
23
|
+
logger.info "Starting processing loop ..."
|
24
|
+
loop do
|
25
|
+
checks.each do |check|
|
26
|
+
if check.launched_at.nil? or
|
27
|
+
(check.launched_at + check.interval).past?
|
28
|
+
logger.debug "Fork check processing ..."
|
29
|
+
Process.detach( fork { check.callback.call } )
|
30
|
+
check.launched_at = Time.now
|
31
|
+
end
|
32
|
+
end
|
33
|
+
sleep 0.2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
extend self
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# config related methods
|
43
|
+
|
44
|
+
def check interval: 60, &block
|
45
|
+
Htmon::Agent.checks << Htmon::Agent::Check.new(block, interval)
|
46
|
+
end
|
47
|
+
|
48
|
+
def push url: nil, metric: nil, expires_after: nil, value: nil,
|
49
|
+
hostname: `hostname`.strip
|
50
|
+
logger = Logger.new(STDOUT)
|
51
|
+
|
52
|
+
url = "#{Htmon::Agent.remote}#{url}?"+({hostname: hostname,
|
53
|
+
value: value,
|
54
|
+
expire: expires_after,
|
55
|
+
metric: metric }).to_param
|
56
|
+
begin
|
57
|
+
RestClient.post url, nil
|
58
|
+
rescue RestClient::ExceptionWithResponse => err
|
59
|
+
logger.error "Push to #{url.inspect} failed ..."
|
60
|
+
logger.error err.response
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmon-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Foerster
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- github@mailserver.1n3t.de
|
86
|
+
executables:
|
87
|
+
- htmon-agent
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- exe/htmon-agent
|
101
|
+
- htmon-agent.gemspec
|
102
|
+
- lib/htmon/agent.rb
|
103
|
+
- lib/htmon/agent/version.rb
|
104
|
+
homepage: https://github.com/timmyArch/htmon-agent
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: HTTP Monitoring agent.
|
128
|
+
test_files: []
|