jenkins_statsd 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3d4e4612e2d8b6fe7427a5208ea13fabd1c9c66
4
+ data.tar.gz: f59227cdaeb1b714dcb8702cb756ef149b9d1226
5
+ SHA512:
6
+ metadata.gz: 35e8c4512a26432334f8ff85d5ea81589e0e1d4c489c6fa4724055a961b42505c084326706a262f4ef8b414b9a981bdab88218e32c5a65ccac3c84b62a12cf66
7
+ data.tar.gz: 02323e6b532a3f7852102a0ea63e918296a68a0fc2cc438830bdbe7577dcab04e18a2a62a72bc8cc70face3db125ad787fb882ae866aa53f9df7150f659a02f4
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .*.sw[a-z]
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jenkins_statsd.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt Chun-Lum
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
+ # JenkinsStatsd
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/jenkins_statsd`. 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 'jenkins_statsd'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jenkins_statsd
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. Run `bundle exec jenkins_statsd` to use the gem in this directory, ignoring other installed copies of this gem.
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]/jenkins_statsd.
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
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jenkins_statsd"
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
@@ -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,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'jenkins_statsd/cli'
4
+
5
+ JenkinsStatsd::CLI.start
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jenkins_statsd/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jenkins_statsd"
8
+ spec.version = JenkinsStatsd::VERSION
9
+ spec.authors = ["Matt Chun-Lum"]
10
+
11
+ spec.summary = %q{Collect jenkins metrics and send to statsd}
12
+ spec.description =
13
+ %q{Collect jenkins metrics and send to statsd (depends on having the metrics plugin installed on jenkins instance)}
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_dependency "eventmachine"
22
+ spec.add_dependency "rest-client"
23
+ spec.add_dependency "semantic_logger"
24
+ spec.add_dependency "statsd-ruby"
25
+ spec.add_dependency "thor"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ end
@@ -0,0 +1,81 @@
1
+ require 'eventmachine'
2
+ require 'semantic_logger'
3
+ require 'thor'
4
+
5
+ require 'jenkins_statsd/jenkins_client'
6
+ require 'jenkins_statsd/statsd_client'
7
+
8
+ module JenkinsStatsd
9
+ class CLI < Thor
10
+
11
+ desc 'start [OPTIONS]', 'start the client'
12
+ option :jenkins_host,
13
+ aliases: '-j',
14
+ type: :string,
15
+ required: true,
16
+ desc: 'The jenkins base url'
17
+ option :jenkins_token,
18
+ aliases: '-t',
19
+ type: :string,
20
+ required: true,
21
+ desc: 'The jenkins metrics plugin api token'
22
+ option :statsd_host,
23
+ aliases: '-s',
24
+ type: :string,
25
+ required: true,
26
+ desc: 'The statsd host'
27
+ option :statsd_port,
28
+ aliases: '-p',
29
+ type: :numeric,
30
+ required: true,
31
+ desc: 'The statsd port'
32
+ option :namespace,
33
+ aliases: '-n',
34
+ type: :string,
35
+ required: true,
36
+ desc: 'The metric namespace'
37
+ option :interval,
38
+ aliases: '-i',
39
+ type: :numeric,
40
+ default: 30.0,
41
+ desc: 'The interval in seconds'
42
+ option :log_level,
43
+ aliases: '-l',
44
+ type: :string,
45
+ default: 'info',
46
+ desc: 'The log level, one of trace, debug, info, warn, error, crit'
47
+ def start
48
+ SemanticLogger.default_level = options[:log_level].downcase.to_sym
49
+ SemanticLogger.add_appender(io: $stdout, level: :trace, formatter: :color)
50
+ logger = SemanticLogger['JenkinsStatsd']
51
+
52
+ jenkins_client = JenkinsClient.new(options[:jenkins_host],
53
+ options[:jenkins_token])
54
+
55
+ stats_client = StatsdClient.new(options[:statsd_host],
56
+ options[:statsd_port],
57
+ options[:namespace])
58
+
59
+ EventMachine.run do
60
+ logger.info("Starting... first check in #{options[:interval]} seconds")
61
+
62
+ EventMachine.add_periodic_timer(options[:interval]) do
63
+ logger.debug('Fetching metrics')
64
+ begin
65
+ metrics = jenkins_client.get_metrics
66
+ logger.trace(metrics)
67
+
68
+ begin
69
+ logger.debug('Sending metrics')
70
+ stats_client.send_metrics(metrics)
71
+ rescue Exception => e
72
+ logger.error("Error sending metrics: #{e}")
73
+ end
74
+ rescue Exception => e
75
+ logger.error("Error fetching metrics: #{e}")
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ module JenkinsStatsd
5
+ class JenkinsClient
6
+ attr_reader :metrics_url
7
+
8
+ EXCLUDE = [
9
+ %r(^jenkins\.versions)
10
+ ]
11
+
12
+ def initialize(host, api_token)
13
+ @metrics_url = File.join(host, 'metrics', api_token, 'metrics')
14
+ end
15
+
16
+ def get_metrics
17
+ metrics = {}
18
+ response = RestClient.get metrics_url
19
+ parsed = JSON.parse(response.body)
20
+ metrics[:gauges] = extract_gauges(parsed)
21
+ metrics
22
+ end
23
+
24
+ protected
25
+
26
+ def extract_gauges(data)
27
+ gauges = {}
28
+ data['gauges'].each do |key, value|
29
+ EXCLUDE.each do |pattern|
30
+ next if key.match(pattern)
31
+
32
+ gauges[key] = value['value']
33
+ end
34
+ end
35
+ gauges
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'statsd-ruby'
2
+
3
+ module JenkinsStatsd
4
+ class StatsdClient
5
+ attr_reader :statsd
6
+ def initialize(host, port, namespace)
7
+ @statsd = Statsd.new(host, port).tap { |sd| sd.namespace = namespace }
8
+ end
9
+
10
+ def send_metrics(metrics)
11
+ metrics[:gauges].each do |key, value|
12
+ statsd.gauge(key, value)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module JenkinsStatsd
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "jenkins_statsd/version"
2
+
3
+ module JenkinsStatsd
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jenkins_statsd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Chun-Lum
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-21 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: semantic_logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: statsd-ruby
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: thor
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
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Collect jenkins metrics and send to statsd (depends on having the metrics
126
+ plugin installed on jenkins instance)
127
+ email:
128
+ executables:
129
+ - jenkins_statsd
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .travis.yml
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/setup
142
+ - exe/jenkins_statsd
143
+ - jenkins_statsd.gemspec
144
+ - lib/jenkins_statsd.rb
145
+ - lib/jenkins_statsd/cli.rb
146
+ - lib/jenkins_statsd/jenkins_client.rb
147
+ - lib/jenkins_statsd/statsd_client.rb
148
+ - lib/jenkins_statsd/version.rb
149
+ homepage:
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.8
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Collect jenkins metrics and send to statsd
173
+ test_files: []