chaoite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6f4704379949077c95ee64d74ef39a2b46f2662
4
+ data.tar.gz: 53a95f094e72b92d11bd8979df06f69b593b6e12
5
+ SHA512:
6
+ metadata.gz: 845ac8d6a60be405275762093854a671550d675c501ca130c3891b0ac83712a061280a96d5d87768c5f019b81750ee0aeff019850628405c6f35a19264f28bba
7
+ data.tar.gz: a69bf918555467bf5917a33077aa2a1d2419d95497a33107e51a861854030f8fc956fc4dac60d02b89b6bd28dcbc558926a423f4d07f62ad90b08febb3ea313d
@@ -0,0 +1,56 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Created by https://www.gitignore.io/api/intellij,ruby
12
+
13
+ ### Intellij ###
14
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
15
+
16
+ *.iml
17
+
18
+ ## Directory-based project format:
19
+ .idea/
20
+ # if you remove the above rule, at least ignore the following:
21
+
22
+ # Mongo Explorer plugin:
23
+ # .idea/mongoSettings.xml
24
+
25
+ ## File-based project format:
26
+ *.ipr
27
+ *.iws
28
+
29
+ ## Plugin-specific files:
30
+
31
+ # IntelliJ
32
+ /out/
33
+
34
+ # mpeltonen/sbt-idea plugin
35
+ .idea_modules/
36
+
37
+
38
+ ### Ruby ###
39
+ *.gem
40
+ *.rbc
41
+ /.config
42
+
43
+
44
+ ## Environment normalisation:
45
+ .bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ .ruby-version
53
+ .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chaoite.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Aswin
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.
@@ -0,0 +1,56 @@
1
+ # Chaoite
2
+
3
+ A Collector and reported for Graphite. It has 2 types of collector
4
+
5
+ 1. HTTP
6
+ 2. Shell
7
+
8
+ ## HTTP
9
+
10
+ Pass in a Check URL which will be hit and send metrics based on status code
11
+
12
+ ## Shell
13
+
14
+ Execute a given shell command and send metrics based on return status
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'chaoite'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install chaoite
31
+
32
+ ## Usage
33
+
34
+ $ bundle exec chaoite
35
+
36
+ ```
37
+ Usage: chaoite [options]
38
+ -c, --config-file config_file Path to config file. Defaults to config.json
39
+ -g, --graphite-server server Graphite server url. Defaults to localhost
40
+ -p, --graphite-port port Graphite port. Defaults to 2003
41
+ -h, --help Displays Help
42
+ ```
43
+
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bundle install` to install dependencies.
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aswinkarthik93/chaoite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
56
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'chaoite'
4
+
5
+ Chaoite.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chaoite"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chaoite/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chaoite"
8
+ spec.version = Chaoite::VERSION
9
+ spec.authors = ["Aswin"]
10
+ spec.email = ["aswinkarthik93@gmail.com"]
11
+
12
+ spec.summary = "A collector and reporter for Graphite"
13
+ spec.description = "A monitoring data collector that can poll services over http or run shell commands and gather a variety of metrics. Works with JSON/XML based services too, with support for jsonpath/xpath."
14
+ spec.homepage = "https://github.com/aswinkarthik93/chaoite"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "json", "~> 1.8"
30
+ spec.add_runtime_dependency "jsonpath", "~> 0.5"
31
+ spec.add_runtime_dependency "graphite-api", "~> 0.1"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.3"
36
+ end
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "name": "health_check_example",
4
+ "type": "http",
5
+ "value": "state",
6
+ "check": "http://localhost:3001/",
7
+ "key":"chaoite.localservice_state"
8
+ },
9
+ {
10
+ "name": "some_json_field_values",
11
+ "type": "http",
12
+ "value": "metric",
13
+ "parser": "json",
14
+ "check": "http://localhost:3000/some_endpoint/?q=value",
15
+ "key":"chaoite.field_value",
16
+ "jsonpath": "$.somejsonpath[0]"
17
+ }
18
+ ]
@@ -0,0 +1,67 @@
1
+ require 'chaoite/version'
2
+ require 'json'
3
+ require 'chaoite/handler'
4
+ require 'optparse'
5
+ require 'graphite-api'
6
+ require 'graphite-api/core_ext/numeric'
7
+
8
+ module Chaoite
9
+
10
+ DEFAULT_OPTIONS = {
11
+ :config_file => 'config.json',
12
+ :server => 'localhost',
13
+ :port => 2003
14
+ }
15
+
16
+ def self.run(args)
17
+
18
+ options = DEFAULT_OPTIONS
19
+
20
+ parser = setup_parser(options)
21
+ parser.parse!
22
+
23
+ configs = JSON.parse(File.read(options[:config_file]))
24
+
25
+ puts "Starting up Chaoite"
26
+
27
+ client = GraphiteAPI.new(:graphite => "#{options[:server]}:#{options[:port]}")
28
+
29
+ client.every 10.seconds do |c|
30
+ configs.each do |config|
31
+ metric = Handler.send("#{config["type"]}_#{config["value"]}", config)
32
+ puts "Sending metric #{metric}"
33
+ c.metrics(metric)
34
+ end
35
+ end
36
+
37
+ begin
38
+ sleep 2 while true
39
+ rescue Interrupt => e
40
+ puts "Shutting down Chaoite"
41
+ end
42
+
43
+ end
44
+
45
+ def self.setup_parser(options)
46
+ OptionParser.new do |opts|
47
+ opts.banner = "Usage: chaoite [options]"
48
+
49
+ opts.on('-c', '--config-file config_file', "Path to config file. Defaults to #{options[:config_file]}") do |config_file|
50
+ options[:config_file] = config_file
51
+ end
52
+
53
+ opts.on('-g', '--graphite-server server', "Graphite server url. Defaults to #{options[:server]}") do |server|
54
+ options[:server] = server
55
+ end
56
+
57
+ opts.on('-p', '--graphite-port port', "Graphite port. Defaults to #{options[:port]}") do |port|
58
+ options[:port] = port
59
+ end
60
+
61
+ opts.on('-h', '--help', 'Displays Help') do
62
+ puts opts
63
+ exit
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,62 @@
1
+ require 'net/http'
2
+ require 'jsonpath'
3
+
4
+ module Handler
5
+ def self.http_state config
6
+ key = config["key"]
7
+ value = begin
8
+ res = Net::HTTP.get_response(URI(config["check"]))
9
+ res.code == '200' ? 1 : 0
10
+ rescue
11
+ 0
12
+ end
13
+ return key => value
14
+ end
15
+
16
+ def self.http_metric config
17
+ key = config["key"]
18
+ value = begin
19
+ res = Net::HTTP.get_response(URI(config["check"]))
20
+ parse(res.body, config)
21
+ rescue
22
+ nil
23
+ end
24
+ return key => value
25
+ end
26
+
27
+ def self.shell_state config
28
+ key = config["key"]
29
+ command = config["check"]
30
+ value = system(command) ? 1 : 0
31
+ return key => value
32
+ end
33
+
34
+ def self.shell_metric config
35
+ key = config["key"]
36
+ command = config["check"]
37
+
38
+ value = begin
39
+ parse(`#{command}`, config)
40
+
41
+ rescue
42
+ nil
43
+ end
44
+
45
+ return key => value
46
+ end
47
+
48
+ private
49
+ def self.parse(data, config)
50
+ parser = config["parser"] || "text"
51
+ self.send("parse_#{parser}", data, config)
52
+ end
53
+
54
+ def self.parse_text(data, config)
55
+ return data
56
+ end
57
+
58
+ def self.parse_json(data, config)
59
+ raise "jsonpath needs to be specified if using json parser" if(!config["jsonpath"])
60
+ return JsonPath.on(data, config["jsonpath"])[0]
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Chaoite
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chaoite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aswin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jsonpath
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: graphite-api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ description: A monitoring data collector that can poll services over http or run shell
98
+ commands and gather a variety of metrics. Works with JSON/XML based services too,
99
+ with support for jsonpath/xpath.
100
+ email:
101
+ - aswinkarthik93@gmail.com
102
+ executables:
103
+ - chaoite
104
+ - console
105
+ - setup
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".idea/uiDesigner.xml"
111
+ - ".rspec"
112
+ - ".travis.yml"
113
+ - CODE_OF_CONDUCT.md
114
+ - Gemfile
115
+ - LICENSE.txt
116
+ - README.md
117
+ - Rakefile
118
+ - bin/chaoite
119
+ - bin/console
120
+ - bin/setup
121
+ - chaoite.gemspec
122
+ - config.json.example
123
+ - lib/chaoite.rb
124
+ - lib/chaoite/handler.rb
125
+ - lib/chaoite/version.rb
126
+ homepage: https://github.com/aswinkarthik93/chaoite
127
+ licenses:
128
+ - MIT
129
+ metadata:
130
+ allowed_push_host: https://rubygems.org
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.4
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: A collector and reporter for Graphite
151
+ test_files: []