umbrtonic 0.2.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: 2f6c51022dc73df0c8bc6e5335b86a1614b1fe1a613412f53679ed9aef067da0
4
+ data.tar.gz: f748c9a4046aebe509409ee2a340459ef8171293961ab4a0e44f6adb5f691784
5
+ SHA512:
6
+ metadata.gz: 0e3d96b49d8703d3faa3a7b3c9fe92aea46d6f95129cb719806fbc6387c161653142f319626d0ce2541d044d3974205277081d2dc46ebbac53f4d34da60539c0
7
+ data.tar.gz: 3f4c98044e37342709131ddfb87b1a66a4c628da80170a2cdad93b7bfcf049a3077856df384fcdf4cfe24abbb2b88f1b54891d7a3788dbc1661158510879a022
@@ -0,0 +1,45 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ lint:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: 3.0
26
+ bundler-cache: true
27
+ - name: Run rubocop
28
+ run: bundle exec rubocop
29
+
30
+ test:
31
+ runs-on: ubuntu-latest
32
+ strategy:
33
+ matrix:
34
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
35
+
36
+ steps:
37
+ - name: Checkout
38
+ uses: actions/checkout@v2
39
+ - name: Set up Ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby-version }}
43
+ bundler-cache: true
44
+ - name: Run tests
45
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /log/*
2
+ !/log/.keep
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ .ruby-version
12
+ .rspec_status
13
+ Gemfile.lock
14
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.5
6
+ Include:
7
+ - bin/*
8
+ - lib/**/*.rb
9
+ - spec/**/*.rb
10
+ - Gemfile
11
+ - Rakefile
12
+ - umbrtonic.gemspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [0.2.0] - 2021-03-04
5
+ - Public Release :)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in umbrtonic.gemspec
6
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Umbrellio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Umbrtonic
2
+
3
+ [![build](https://github.com/umbrellio/umbrtonic/workflows/build/badge.svg)](https://github.com/umbrellio/umbrtonic/actions)
4
+
5
+ Gem for transferring Active Support Instrumentation events
6
+ to the InfluxDB database via UDP without boilerplate code.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'umbrtonic'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install umbrtonic
24
+
25
+
26
+ ## Configuration
27
+ Under the hood Umbrtonic uses [Qonfig](https://github.com/0exp/qonfig) gem.
28
+
29
+ By default, gem sends data to 127.0.0.1:8089. You are able to change this easily:
30
+
31
+ ```ruby
32
+ Umbrtonic.configure do |conf|
33
+ conf.influxdb.host = "another.machine"
34
+ conf.influxdb.port = 4444
35
+ end
36
+ ```
37
+
38
+
39
+ ### Using a custom prefix
40
+ Optionally you are able to set a prefix:
41
+
42
+ ```ruby
43
+ Umbrtonic.configure do |conf|
44
+ conf.prefix = "my_app"
45
+ end
46
+ ```
47
+
48
+ For example, when you subscribe to `actions`,
49
+ points to InfluxDB will be sent as `my_app_actions`.
50
+
51
+ Alternatively, it is possible to configure with file:
52
+
53
+ ```yaml
54
+ production:
55
+ prefix: custom
56
+ influxdb:
57
+ host: 127.0.0.1
58
+ port: 8094
59
+ # etc
60
+ ```
61
+
62
+ and then load configuration:
63
+
64
+ ```ruby
65
+ Umbrtonic.config.load_from_yaml(
66
+ Rails.root / "config" / "umbrtonic.yml",
67
+ expose: Rails.env
68
+ )
69
+ ```
70
+
71
+ ## Usage
72
+ ```ruby
73
+ Umbrtonic.bind("process_action.action_controller") do |inf, event, payload|
74
+ inf.values(
75
+ count: 1,
76
+ duration: event.duration,
77
+ db_runtime: event.payload[:db_runtime],
78
+ )
79
+
80
+ inf.tags(
81
+ controller: payload[:controller],
82
+ action: payload[:action],
83
+ )
84
+ end
85
+ ```
86
+
87
+ Gem provides instance of InfluxDB data builder
88
+ and information about the event and payload for quick access:
89
+
90
+ ```ruby
91
+ Umbrtonic.bind("process_action.action_controller") do |inf, event, payload|
92
+ event.name # => "process_action.action_controller"
93
+ event.duration # => 10 (in milliseconds)
94
+ event.payload # => event-specific payload
95
+
96
+ payload # => event-specific payload, alias for event.payload
97
+ end
98
+ ```
99
+
100
+
101
+
102
+ See more information about Active Support Notifications
103
+ [here](https://guides.rubyonrails.org/active_support_instrumentation.html)
104
+
105
+ You are able to set custom name for event:
106
+
107
+ ```ruby
108
+ Umbrtonic.bind("process_action.action_controller", measurement: "actions") do |inf, event, payload|
109
+ # your bindings
110
+ end
111
+ ```
112
+
113
+ In this example events will be sent as `actions`.
114
+
115
+ There is complete list of
116
+ [Ruby on Rails hooks](https://guides.rubyonrails.org/v5.1/active_support_instrumentation.html#rails-framework-hooks)
117
+
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome on GitHub
122
+ at https://github.com/umbrellio/umbrtonic.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "umbrtonic"
5
+ require "logger"
6
+ require "influxdb"
7
+ require "irb"
8
+
9
+ IRB.start(__FILE__)
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
data/lib/umbrtonic.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/notifications"
4
+ require "influxdb/point_value"
5
+ require "socket"
6
+ require "qonfig"
7
+
8
+ module Umbrtonic
9
+ require_relative "umbrtonic/influxdb"
10
+ require_relative "umbrtonic/version"
11
+
12
+ include Qonfig::Configurable
13
+
14
+ configuration do
15
+ setting :influxdb do
16
+ setting :host, "127.0.0.1"
17
+ setting :port, 8089
18
+ end
19
+
20
+ setting :prefix
21
+ end
22
+
23
+ module_function
24
+
25
+ def bind(name, measurement: name)
26
+ ActiveSupport::Notifications.subscribe(name) do |*args|
27
+ event = ActiveSupport::Notifications::Event.new(*args)
28
+ influx = Umbrtonic::InfluxDB.new(measurement)
29
+
30
+ yield influx, event, event.payload
31
+ send_via_udp influx
32
+ end
33
+ end
34
+
35
+ def unbind(name)
36
+ ActiveSupport::Notifications.unsubscribe(name)
37
+ end
38
+
39
+ def send_via_udp(influx)
40
+ config = self.config.settings.influxdb
41
+ socket.send(influx.build, 0, config.host, config.port)
42
+ end
43
+
44
+ def socket
45
+ @socket ||= UDPSocket.new
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Umbrtonic::InfluxDB
4
+ def initialize(measurement, values: {}, tags: {})
5
+ @measurement = measurement
6
+ @values = values
7
+ @tags = tags
8
+ end
9
+
10
+ def value(name, value)
11
+ @values[name] = value
12
+ end
13
+
14
+ def values(**values)
15
+ @values = @values.merge(**values)
16
+ end
17
+
18
+ def tag(name, value)
19
+ @tags[name] = value
20
+ end
21
+
22
+ def tags(**tags)
23
+ @tags = @tags.merge(**tags)
24
+ end
25
+
26
+ def data
27
+ { values: @values,
28
+ tags: @tags,
29
+ series: series }
30
+ end
31
+
32
+ def build
33
+ ::InfluxDB::PointValue.new(data).dump
34
+ end
35
+
36
+ private
37
+
38
+ def series
39
+ [Umbrtonic.config.settings.prefix, @measurement].compact.join("_")
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Umbrtonic
4
+ VERSION = "0.2.0"
5
+ end
data/umbrtonic.gemspec ADDED
@@ -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
+
6
+ require "umbrtonic/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "umbrtonic"
10
+ spec.version = Umbrtonic::VERSION
11
+ spec.authors = ["Umbrellio Team", "Eugene Yak"]
12
+ spec.email = ["oss@umbrellio.biz", "eugene.yak@umbrellio.biz"]
13
+
14
+ spec.summary = "Gem for transferring Active Support Instrumentation events " \
15
+ "to the InfluxDB database via UDP without boilerplate code."
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.required_ruby_version = ">= 2.5"
27
+
28
+ spec.add_runtime_dependency "activesupport"
29
+ spec.add_runtime_dependency "influxdb"
30
+ spec.add_runtime_dependency "qonfig"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.8"
35
+ spec.add_development_dependency "rubocop"
36
+ spec.add_development_dependency "rubocop-config-umbrellio"
37
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: umbrtonic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Umbrellio Team
8
+ - Eugene Yak
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2021-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: influxdb
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: qonfig
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.8'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.8'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rubocop
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rubocop-config-umbrellio
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description:
127
+ email:
128
+ - oss@umbrellio.biz
129
+ - eugene.yak@umbrellio.biz
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".github/workflows/build.yml"
135
+ - ".gitignore"
136
+ - ".rspec"
137
+ - ".rubocop.yml"
138
+ - CHANGELOG.md
139
+ - Gemfile
140
+ - LICENSE.md
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - lib/umbrtonic.rb
146
+ - lib/umbrtonic/influxdb.rb
147
+ - lib/umbrtonic/version.rb
148
+ - umbrtonic.gemspec
149
+ homepage:
150
+ licenses: []
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '2.5'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubygems_version: 3.2.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Gem for transferring Active Support Instrumentation events to the InfluxDB
171
+ database via UDP without boilerplate code.
172
+ test_files: []