yabeda-datadog 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: 76499b2fc49b319aba467fc5ae335b8eb7a8e978cfb2ab1a5b659ba47d7b1dfa
4
+ data.tar.gz: 43c14e0c4f9db28ddb299049cf5c06aeeac5a97ccdb1e3411f71edeb98f2456e
5
+ SHA512:
6
+ metadata.gz: fd582c08f725d7e158119e54ac5b3d6d7edb3d3434725c7652c76d86dec305e09d419bb26bc26392a4e2cf4ec3d9b5987a25b69e5fc330853a22c29910923ad2
7
+ data.tar.gz: dcd61b99c6cf2dcec3ba6aa09678b839cb445315a83351a9744840650a4b4d6993ead2521d72736ac89812e01436a44d45eeb009f57e157dfce3f45e15ef098a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .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,48 @@
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: false
25
+
26
+ RSpec/MultipleExpectations:
27
+ Enabled: false
28
+
29
+ Bundler/OrderedGems:
30
+ Enabled: false
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: true
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: true
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: true
48
+ EnforcedStyleForMultiline: consistent_comma
data/Gemfile ADDED
@@ -0,0 +1,8 @@
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-datadog.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yabeda-datadog (0.1.0)
5
+ dogapi
6
+ yabeda
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ concurrent-ruby (1.1.3)
13
+ diff-lcs (1.3)
14
+ dogapi (1.32.0)
15
+ multi_json
16
+ dry-initializer (2.5.0)
17
+ method_source (0.9.2)
18
+ multi_json (1.13.1)
19
+ pry (0.12.2)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.9.0)
22
+ rake (10.5.0)
23
+ rspec (3.8.0)
24
+ rspec-core (~> 3.8.0)
25
+ rspec-expectations (~> 3.8.0)
26
+ rspec-mocks (~> 3.8.0)
27
+ rspec-core (3.8.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-expectations (3.8.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-mocks (3.8.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-support (3.8.0)
36
+ yabeda (0.1.2)
37
+ concurrent-ruby
38
+ dry-initializer
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.17)
45
+ pry (~> 0.12.2)
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+ yabeda-datadog!
49
+
50
+ BUNDLED WITH
51
+ 1.17.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 shvetsovdm
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,46 @@
1
+ # Yabeda Datadog adapter
2
+
3
+ [Yabeda](https://github.com/yabeda-rb/yabeda) adapter for easy exporting collected custom metrics from your application to the Datadog API.
4
+
5
+
6
+ ## Installation
7
+
8
+ This adapter send metrics to [Datadog API](https://docs.datadoghq.com/api/?lang=ruby) and requires to have and Datadog account with API key. You can obtain your Datadog API key in [Datadog dashboard](https://app.datadoghq.com/account/settings#api). For more information refer to [API documentation](https://docs.datadoghq.com/api/?lang=ruby#authentication).
9
+
10
+ Add line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'yabeda-datadog'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ Require this adapter before Yabeda configuration:
23
+
24
+ ```ruby
25
+ require "yabeda/datadog"
26
+ ```
27
+
28
+ Refer to [Yabeda documentation](https://github.com/yabeda-rb/yabeda) for instruction how to configure and use Yabeda.
29
+
30
+ Refer to [Datadog metrics documentation](https://docs.datadoghq.com/graphing/metrics/) for working with your metrics in Datadog dashboard.
31
+
32
+ Please note that configuring Yabeda you have to use Datadog units. Refer to [Datadog unit for metrics documentation](https://docs.datadoghq.com/developers/metrics/#units).
33
+
34
+ ## Development
35
+
36
+ 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.
37
+
38
+ 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).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shvetsovdm/yabeda-datadog.
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "yabeda/datadog"
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,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "yabeda/datadog"
5
+
6
+ # Put Datadog an API key in DATADOG_API_KEY env variable
7
+ # and appliction key in DATADOG_APP_KEY env variable.
8
+ # Refer to Datadog integrations dashboard for an API key
9
+
10
+ # To Use this script execute it directly with ruby command.
11
+ #
12
+ # Example:
13
+ #
14
+ # DATADOG_API_KEY="your-datadog-api-key-here" ruby script.rb
15
+ #
16
+
17
+ Yabeda.configure do
18
+ group :yabeda_datadog_gem_examples_script
19
+ counter :run_count, comment: "The total number of times the script was executed", unit: "execution"
20
+ gauge :run_time, comment: "Script execution time", unit: "second"
21
+ end
22
+
23
+ start_time = Time.now
24
+ Yabeda.yabeda_datadog_gem_examples_script_run_count.increment(device: "developent_computer")
25
+ finish_time = Time.now
26
+ Yabeda.yabeda_datadog_gem_examples_script_run_time.set({ device: "developent_computer" }, finish_time - start_time)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yabeda"
4
+ require "yabeda/datadog/adapter"
5
+ require "yabeda/datadog/version"
6
+
7
+ module Yabeda
8
+ # Namespace for DataDog adapter
9
+ module Datadog
10
+ end
11
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dogapi"
4
+ require "yabeda/base_adapter"
5
+
6
+ module Yabeda
7
+ module Datadog
8
+ # DataDog adapter. Sends yabeda metrics as custom metrics to DataDog API.
9
+ # https://docs.datadoghq.com/integrations/ruby/
10
+ class Adapter < BaseAdapter
11
+ def register_counter!(counter)
12
+ metric = AdapterMetric.new(counter, "counter")
13
+ dog.update_metadata(metric.name, metric.metadata)
14
+ end
15
+
16
+ def perform_counter_increment!(counter, tags, increment)
17
+ metric = AdapterMetric.new(counter, "counter")
18
+ tags[:type] = "counter"
19
+ dog.emit_point(metric.name, increment, tags)
20
+ end
21
+
22
+ def register_gauge!(gauge)
23
+ metric = AdapterMetric.new(gauge, "gauge")
24
+ dog.update_metadata(metric.name, metric.metadata)
25
+ end
26
+
27
+ def perform_gauge_set!(gauge, tags, value)
28
+ metric = AdapterMetric.new(gauge, "gauge")
29
+ tags[:type] = "gauge"
30
+ dog.emit_point(metric.name, value, tags)
31
+ end
32
+
33
+ private
34
+
35
+ def dog
36
+ ::Dogapi::Client.new(ENV["DATADOG_API_KEY"], ENV["DATADOG_APP_KEY"])
37
+ end
38
+
39
+ Yabeda.register_adapter(:datadog, new)
40
+ end
41
+
42
+ # Internal adapter representation of metrics
43
+ class AdapterMetric
44
+ def initialize(metric, type)
45
+ @metric = metric
46
+ @type = type
47
+ end
48
+
49
+ attr_reader :type
50
+
51
+ def metadata
52
+ {
53
+ type: type,
54
+ description: description,
55
+ short_name: name,
56
+ unit: unit,
57
+ per_unit: per_unit,
58
+ }
59
+ end
60
+
61
+ def name
62
+ parts = ""
63
+ parts += "#{metric.group}." if metric.group
64
+ parts + metric.name.to_s
65
+ end
66
+
67
+ def description
68
+ metric.comment
69
+ end
70
+
71
+ def unit
72
+ metric.unit
73
+ end
74
+
75
+ def per_unit
76
+ metric.per
77
+ end
78
+
79
+ private
80
+
81
+ attr_reader :metric
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Datadog
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,37 @@
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/datadog/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yabeda-datadog"
9
+ spec.version = Yabeda::Datadog::VERSION
10
+ spec.authors = ["Dmitry Shvetsov <@shvetsovdm>"]
11
+ spec.email = ["shvetsovdm@gmail.com"]
12
+
13
+ spec.summary = "DataDog adapter for reporting metrics from Yabeda suite"
14
+ spec.description = <<~DESCRIPTION
15
+ Adapter for reporting custom metrics from Yabeda to DataDog.
16
+ DESCRIPTION
17
+ spec.homepage = "https://github.com/shvetsovdm/yabeda-datadog"
18
+ spec.license = "MIT"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+
23
+ spec.files = Dir.chdir(File.expand_path(__dir__, __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "dogapi"
31
+ spec.add_dependency "yabeda"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.17"
34
+ spec.add_development_dependency "pry", "~> 0.12.2"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-datadog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Shvetsov <@shvetsovdm>
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dogapi
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: yabeda
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: 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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.2
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.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: 'Adapter for reporting custom metrics from Yabeda to DataDog.
98
+
99
+ '
100
+ email:
101
+ - shvetsovdm@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - examples/script.rb
117
+ - lib/yabeda/datadog.rb
118
+ - lib/yabeda/datadog/adapter.rb
119
+ - lib/yabeda/datadog/version.rb
120
+ - yabeda-datadog.gemspec
121
+ homepage: https://github.com/shvetsovdm/yabeda-datadog
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ homepage_uri: https://github.com/shvetsovdm/yabeda-datadog
126
+ source_code_uri: https://github.com/shvetsovdm/yabeda-datadog
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.7.6
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: DataDog adapter for reporting metrics from Yabeda suite
147
+ test_files: []