riemann-json-http 0.0.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +15 -0
  3. data/bin/riemann-json-http +79 -0
  4. metadata +60 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 252ea9dd477ddcfabfcbdefdeae7102525a702f5
4
+ data.tar.gz: f82cb181f58d294cf77dc579586f7a21c3ad6683
5
+ SHA512:
6
+ metadata.gz: fe4b37280dd9ee5c419aca36f81af382929bcc3f279033c894f87d34dcc4b904c9648d245d074109a9d1160b91e2c78632b2828aefd84707aa9f3be7b151059c
7
+ data.tar.gz: 7053c4364f261f04a6b18d898d44345c62a88928ed4bc10ac69acfd50d625024c3c5a1e26f0fba3f18f2df1d1ba8667d83bfda94d17b9468b6b263fb8215a3d9
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ Riemann JSON over http
2
+ ======================
3
+
4
+ Riemann client for any system serving metrics through http as JSON documents.
5
+
6
+ Client pull metrics from configured endpoint.
7
+
8
+ Get started
9
+ ==========
10
+
11
+ ``` bash
12
+ gem install riemann-json-http
13
+ riemann-json-http --help
14
+ riemann-json-http --help
15
+ ```
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Gather statistics from system serving metrics through http as json documents.
4
+
5
+ require 'riemann/tools'
6
+
7
+ class Riemann::Tools::HttpJson
8
+ include Riemann::Tools
9
+ require 'net/http'
10
+ require 'rubygems'
11
+ require 'json'
12
+
13
+ opt :http_url, "System metrics url", :default => "http://#{`hostname`.chomp}/metrics"
14
+ opt :service_name, "Prefix for metrics", :type => :string, :default => nil
15
+ opt :json_attributes, "json attributes to post to riemann", :type => :strings, :default =>nil
16
+
17
+ def initialize
18
+ @uri = URI(opts[:http_url])
19
+ @tag = opts[:tag]
20
+ json_attrs = opts[:json_attributes]
21
+ @regexps = json_attrs.map {|item| Regexp.new("^#{item}$") }
22
+ @service_name = opts[:service_name]
23
+ puts "JSON nodes: #{@regexps.to_s}"
24
+ puts "Service name: #{@service_name}"
25
+ puts "URL to try: #{@uri}"
26
+ end
27
+
28
+ def tick
29
+
30
+ json = JSON.parse(get_response(@uri))
31
+ attributes_to_report = filter_attributes(json, @regexps)
32
+
33
+ attributes_to_report.each do |key, value|
34
+ if !value.is_a? Numeric
35
+ next
36
+ end
37
+ name = if @service_name
38
+ "#{@service_name} #{key}"
39
+ else
40
+ key
41
+ end
42
+ report(
43
+ :host => opts[:event_host],
44
+ :service => name,
45
+ :metric => value.to_f,
46
+ :state => "ok"
47
+ )
48
+ end
49
+ end
50
+
51
+ def filter_attributes(hash, regexps, parent_name=nil, results = {})
52
+ hash.each do |key, v|
53
+ value = v || key
54
+ new_parent = if parent_name
55
+ "#{parent_name}.#{key}"
56
+ else
57
+ key
58
+ end
59
+ if value.is_a?(Hash) || value.is_a?(Array)
60
+ filter_attributes(value, regexps, new_parent, results)
61
+ else
62
+ if matching_node(new_parent, regexps)
63
+ results[new_parent] = value
64
+ end
65
+ end
66
+ end
67
+ results
68
+ end
69
+
70
+ def matching_node(name, regexps)
71
+ regexps.map {|r| name.match(r) }.compact.size > 0
72
+ end
73
+
74
+ def get_response(uri)
75
+ Net::HTTP.get(uri)
76
+ end
77
+ end
78
+
79
+ Riemann::Tools::HttpJson.run
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: riemann-json-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lukasz Jastrzebski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: riemann-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.1
27
+ description:
28
+ email: lukasz.jastrzebski@nsn.com
29
+ executables:
30
+ - riemann-json-http
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - bin/riemann-json-http
36
+ homepage: https://github.com/elyast/riemann-json-http
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.3
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: riemann-json-http
55
+ rubygems_version: 2.4.8
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Collect stats for system service metrics over http as json documents and
59
+ submits them to Riemann.
60
+ test_files: []