graphite_metrics_checker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ac5e2afc8895c3a9f6521f5468ab088f2600c97
4
+ data.tar.gz: 868e74da98f26c9eccecd81b2f24f8e43d89221f
5
+ SHA512:
6
+ metadata.gz: 196c391ec745959cf5704d3f15db9f0e6dceba0fbab7197d7489bb576d807a4041e0b17b74ad255cd931aaaa2bad7a40f752b6b465331919643acc8bc1e5a645
7
+ data.tar.gz: c6676f7c93da5b0f81aaf8888ebf2f72ea5036df9a86058076dc40dbd542da408f038e687e71f6ec65d148c7cd290c82f8597a8592464b1e0a3362329e9c1886
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in graphite_metrics_checker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Joan Albornoz
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,31 @@
1
+ # GraphiteMetricsChecker
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'graphite_metrics_checker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install graphite_metrics_checker
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/graphite_metrics_checker/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "graphite_metrics_checker"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["Raj & Balu"]
9
+ spec.email = ["abc.com"]
10
+ spec.summary = "Graphite Metrics Checker"
11
+ spec.description = "Graphite Metrics Checker"
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,81 @@
1
+ require 'net/http'
2
+ class GraphiteMetricsChecker
3
+ def initialize(config,graphite_url,app_id,time_from,time_until)
4
+ @app_name = config['app_name']
5
+ @list_of_api = config['api']
6
+ @graphite_url = graphite_url
7
+ @app_id = app_id
8
+ @time_from = time_from
9
+ @time_until = time_until
10
+ end
11
+
12
+
13
+
14
+ def get_metrics_for_end_points
15
+ set_time
16
+ result_set = []
17
+ @list_of_api.each_pair do |key,api|
18
+ endpoint = api['endpoint']
19
+ metrics = api['metrics']
20
+ metrics.each_pair do |key,metric|
21
+ result = get_metrics(endpoint,metric)
22
+ result =check_result_for_metrics(result)
23
+ #if !result
24
+ # raise "No metrics for #{api} #{metric}"
25
+ #end
26
+ result_set.push(result)
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+
33
+
34
+ private
35
+ def set_time
36
+ @time_from = @time_from - 60*30
37
+ @time_until =@time_until + 60*60
38
+ @time_from = change_to_format(@time_from)
39
+ @time_until = change_to_format(@time_until)
40
+ end
41
+
42
+ def check_result_for_metrics(result)
43
+
44
+ results = JSON.parse(result).first['datapoints']
45
+ results.each do |result|
46
+ if result[0] != nil
47
+ return true
48
+ end
49
+ end
50
+ return false
51
+
52
+ end
53
+
54
+ def get_metrics(end_point,metrics)
55
+ uri = URI.parse("http://#{@graphite_url}/render/?target=#{@app_name}.#{@app_id}.#{end_point}.#{metrics}&yMin=&from=#{@time_from}&until=#{@time_until}&format=json")
56
+ send(uri,Net::HTTP::Get)
57
+ end
58
+
59
+ def change_to_format(time)
60
+ time = time.to_s.split(' ')
61
+ date = time[0].gsub('-','')
62
+ hr = time[1].split(':')[0].to_i
63
+ mins = '00'
64
+ time = "#{hr}%3A#{mins}_#{date}"
65
+ time
66
+ end
67
+
68
+ def send(url, http_class, payload=nil, content_type='application/json')
69
+ request = http_class.new(url.path)
70
+ request.content_type = content_type unless content_type.nil? || content_type.empty?
71
+ request.body = payload unless payload.nil?
72
+
73
+ Net::HTTP.start(url.host, url.port) do |http|
74
+ request = Net::HTTP::Get.new url.request_uri
75
+ response = http.request request
76
+ response.read_body
77
+
78
+ end
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: graphite_metrics_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raj & Balu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-28 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: Graphite Metrics Checker
42
+ email:
43
+ - abc.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - graphite_metrics_checker.gemspec
54
+ - lib/graphite_metrics_checker.rb
55
+ homepage: ''
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Graphite Metrics Checker
79
+ test_files: []