yabeda-newrelic 0.1.0

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
+ SHA256:
3
+ metadata.gz: 42d707c68a6031d26a3ec7b9d31d9287f9350fa479756e7e9bb20331bb8ed8df
4
+ data.tar.gz: ecc8474600385cc8b4b5333b70806e4a416d176789bf9f7f6363507097c4f374
5
+ SHA512:
6
+ metadata.gz: 1f2d72d4eef6ce67c60c9178eece3f0b4ed3a201350e0ab2b703ee6f5da5473aa2a99ead98595df6077a80d03bc08d17cdbb04250bf03ebd0336376a31c0a2fb
7
+ data.tar.gz: 41064232c183a7b7f70815af49d3f71dcfbbcc4e130689d590a1f605dc5b20724bf29cfaaf57af30fad4a289814000e9600fb7e0477f6a1cc27c72765c069120
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,51 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - "Gemfile"
11
+ - "spec/**/*"
12
+
13
+ Metrics/LineLength:
14
+ Max: 120
15
+
16
+ Style/BracesAroundHashParameters:
17
+ EnforcedStyle: context_dependent
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
21
+
22
+ # Allow to use let!
23
+ RSpec/LetSetup:
24
+ Enabled: no
25
+
26
+ RSpec/MultipleExpectations:
27
+ Enabled: no
28
+
29
+ Bundler/OrderedGems:
30
+ Enabled: no
31
+
32
+ Style/TrailingCommaInArguments:
33
+ Description: 'Checks for trailing comma in argument lists.'
34
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma'
35
+ Enabled: yes
36
+ EnforcedStyleForMultiline: consistent_comma
37
+
38
+ Style/TrailingCommaInArrayLiteral:
39
+ Description: 'Checks for trailing comma in array literals.'
40
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
41
+ Enabled: yes
42
+ EnforcedStyleForMultiline: consistent_comma
43
+
44
+ Style/TrailingCommaInHashLiteral:
45
+ Description: 'Checks for trailing comma in hash literals.'
46
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
47
+ Enabled: yes
48
+ EnforcedStyleForMultiline: consistent_comma
49
+
50
+ RSpec/FilePath:
51
+ Enabled: no
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ - 2.4.5
8
+ - 2.3.8
9
+ before_install: gem install bundler -v 1.17.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
+
8
+
9
+ ## 0.1.0 - 2018-10-30
10
+
11
+ - Initial release: custom metrics being reported to NewRelic. @Envek
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in yabeda-newrelic.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem "pry"
12
+ gem "pry-byebug", platform: :mri
13
+
14
+ gem "rubocop"
15
+ gem "rubocop-rspec"
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrey Novikov
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,67 @@
1
+ # Yabeda::[NewRelic]
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/yabeda-newrelic.svg)](https://rubygems.org/gems/yabeda-newrelic) [![Build Status](https://travis-ci.org/yabeda-rb/yabeda-newrelic.svg?branch=master)](https://travis-ci.org/yabeda-rb/yabeda-newrelic)
4
+
5
+ Adapter for easy exporting collected custom metrics from your application to the [NewRelic Insights].
6
+
7
+ <a href="https://evilmartians.com/?utm_source=yabeda-newrelic&utm_campaign=project_page">
8
+ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
9
+ </a>
10
+
11
+
12
+ ## Installation
13
+
14
+ 1. [Install and configure official NewRelic agent for Ruby](https://docs.newrelic.com/docs/agents/ruby-agent/installation/install-new-relic-ruby-agent).
15
+
16
+ 2. Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'yabeda-newrelic'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+
27
+ ## Usage
28
+
29
+ All metrics registered in [Yabeda] will be sent to NewRelic automatically.
30
+
31
+ Go to [NewRelic Insights] → Data Explorer → Metrics to view them.
32
+
33
+ ### Caveats
34
+
35
+ When testing make sure that your NewRelic agent is enabled (`NewRelic::Agent.config[:agent_enabled]` is `true`) as it is being automatically disabled in console sessions as example.
36
+
37
+
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ Please read following articles about how [NewRelic Ruby Agent](https://github.com/newrelic/rpm/) works under the hood to better understand how to interact with it:
45
+
46
+ - http://mgiroux.me/2016/instrumenting-rails-apps/
47
+ - https://qiita.com/k0kubun/items/4810d2044c47e597540f
48
+
49
+ ### Architecture
50
+
51
+ Every time Yabeda metric is being updated the NewRelic API will be called.
52
+
53
+ `collect` blocks for metrics collected on demand will be called during NewRelic's [harvest cycle](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/getting-started/glossary#harvest-cycle).
54
+
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-newrelic.
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
64
+
65
+ [NewRelic]: https://newrelic.com/
66
+ [NewRelic Insights]: https://insights.newrelic.com/
67
+ [Yabeda]: https://github.com/yabeda-rb/yabeda/ "Extendable framework for collecting and exporting metrics from your Ruby application "
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: %i[rubocop spec]
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "yabeda/newrelic"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yabeda"
4
+ require "yabeda/newrelic/version"
5
+ require "yabeda/newrelic/adapter"
6
+
7
+ module Yabeda
8
+ # Namespace for NewRelic adapter
9
+ module NewRelic
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "newrelic_rpm"
4
+ require "yabeda/base_adapter"
5
+
6
+ module Yabeda
7
+ module NewRelic
8
+ # NewRelic adapter. Sends yabeda metrics as custom metrics to NewRelic.
9
+ # See https://docs.newrelic.com/docs/agents/ruby-agent/api-guides/ruby-custom-metrics
10
+ class Adapter < BaseAdapter
11
+ def register_counter!(_metric)
12
+ # Do nothing. NewRelic don't need to register metrics
13
+ end
14
+
15
+ def perform_counter_increment!(counter, tags, increment)
16
+ ::NewRelic::Agent.increment_metric(build_name(counter, tags), increment)
17
+ end
18
+
19
+ def register_gauge!(_metric)
20
+ # Do nothing. NewRelic don't need to register metrics
21
+ end
22
+
23
+ def perform_gauge_set!(metric, tags, value)
24
+ ::NewRelic::Agent.record_metric(build_name(metric, tags), value)
25
+ end
26
+
27
+ def register_histogram!(_metric)
28
+ # Do nothing. NewRelic don't need to register metrics
29
+ end
30
+
31
+ def perform_histogram_measure!(metric, tags, value)
32
+ ::NewRelic::Agent.record_metric(build_name(metric, tags), value)
33
+ end
34
+
35
+ def initialize(*)
36
+ super
37
+ ::NewRelic::Agent.add_instrumentation(File.join(__dir__, "configure.rb"))
38
+ end
39
+
40
+ private
41
+
42
+ # https://docs.newrelic.com/docs/plugins/plugin-developer-resources/developer-reference/metric-naming-reference
43
+ def build_name(metric, labels = {})
44
+ name = metric.name.to_s
45
+ # Attrs: https://docs.newrelic.com/docs/plugins/plugin-developer-resources/developer-reference/metric-naming-reference#metric_attributes
46
+ name = "#{name}/#{labels.values.join('/')}" if labels.any?
47
+ name += units_for(metric)
48
+
49
+ ["Custom", metric.group&.capitalize, name].compact.join("/")
50
+ end
51
+
52
+ # https://docs.newrelic.com/docs/plugins/plugin-developer-resources/developer-reference/metric-units-reference
53
+ def units_for(metric)
54
+ return "[#{[metric.unit, metric.per].compact.join('/')}]" if metric.unit
55
+ return "#{name}[|#{metric.per}]" if !metric.unit && metric.per
56
+
57
+ ""
58
+ end
59
+
60
+ Yabeda.register_adapter(:newrelic, new)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is required by NewRelic agent when it configures itself
4
+ # Read more on how NewRelic Ruby agent works under the hood:
5
+ # http://mgiroux.me/2016/instrumenting-rails-apps/
6
+ # https://qiita.com/k0kubun/items/4810d2044c47e597540f
7
+ ::NewRelic::Agent.agent.events.subscribe(:before_harvest) do
8
+ Yabeda.collectors.each(&:call)
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module NewRelic
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "yabeda/newrelic/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yabeda-newrelic"
9
+ spec.version = Yabeda::NewRelic::VERSION
10
+ spec.authors = ["Andrey Novikov"]
11
+ spec.email = ["envek@envek.name"]
12
+
13
+ spec.summary = "NewRelic adapter for reporting metrics from Yabeda suite"
14
+ spec.description = <<~DESCRIPTION
15
+ Adapter for reporting custom metrics from Yabeda to the NewRelic Insights.
16
+ DESCRIPTION
17
+ spec.homepage = "https://github.com/yabeda-rb/yabeda-newrelic"
18
+ spec.license = "MIT"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = "https://github.com/yabeda-rb/yabeda-newrelic"
22
+ spec.metadata["changelog_uri"] = "https://github.com/yabeda-rb/yabeda-newrelic/blob/master/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "newrelic_rpm", "~> 5.0"
34
+ spec.add_development_dependency "yabeda", "~> 0.1.0"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.17"
37
+ spec.add_development_dependency "rake", "~> 12.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-newrelic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Novikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: newrelic_rpm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yabeda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: 'Adapter for reporting custom metrics from Yabeda to the NewRelic Insights.
84
+
85
+ '
86
+ email:
87
+ - envek@envek.name
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".travis.yml"
96
+ - CHANGELOG.md
97
+ - Gemfile
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/yabeda/newrelic.rb
104
+ - lib/yabeda/newrelic/adapter.rb
105
+ - lib/yabeda/newrelic/configure.rb
106
+ - lib/yabeda/newrelic/version.rb
107
+ - yabeda-newrelic.gemspec
108
+ homepage: https://github.com/yabeda-rb/yabeda-newrelic
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ homepage_uri: https://github.com/yabeda-rb/yabeda-newrelic
113
+ source_code_uri: https://github.com/yabeda-rb/yabeda-newrelic
114
+ changelog_uri: https://github.com/yabeda-rb/yabeda-newrelic/blob/master/CHANGELOG.md
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.6
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: NewRelic adapter for reporting metrics from Yabeda suite
135
+ test_files: []