yabeda-prometheus2influxdb 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
+ SHA256:
3
+ metadata.gz: 3f15f494fc8c977f0d4f5bd61ac5234872165a902b1227fa1b299acd0758ea00
4
+ data.tar.gz: 733c8ffb3ae626818364dee09e08dc0d5ee7c11706f8e4a244916fb16921b820
5
+ SHA512:
6
+ metadata.gz: c7e85c6baac1cd1d9e24441550ec593a0e7fa8473dd1128b81673ade914873a8e28e3a76a29d2aba5cb1fb0b2911e97feffea177f227b7a9ae0493c1aa5d76eb
7
+ data.tar.gz: 3e8532ce668138428d0bad5ca3c2220bbf7348b4496a01815c9e60d9f806892da0697d1888a8bf102a5ef5b41f8e17cac68a58b72e5a250202b7ce68c6d541ed
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-01
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in yabeda-prometheus2influxdb.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 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,35 @@
1
+ # Yabeda::Prometheus2InfluxDB
2
+
3
+ Experimental gem to push metrics in Prometheus format (especially histograms) to InfluxDB endpoint.
4
+
5
+ Can be useful in environments where deploying Prometheus is complicated, but you can (e.g. for sending metrics to Grafana Cloud from non-containerized application on Cloud66 with many processes per server).
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add yabeda-prometheus2influxdb
12
+
13
+ Configure InfluxDB connection with [anyway_config](https://github.com/palkan/anyway_config). See the [list of configuration options](https://github.com/influxdata/influxdb-ruby#list-of-configuration-options).
14
+
15
+ ## Usage
16
+
17
+ Launch export in a different thread in some process (where applicable):
18
+
19
+ ```ruby
20
+ Yabeda::Prometheus2InfluxDB.start!
21
+ ```
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yabeda-prometheus2influxdb.
32
+
33
+ ## License
34
+
35
+ 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,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anyway_config"
4
+
5
+ module Yabeda
6
+ class Prometheus2InfluxDB
7
+ class Config < ::Anyway::Config
8
+ config_name :yabeda_prometheus2influxdb
9
+
10
+ attr_config export_interval_seconds: 60
11
+ attr_config :url, :host, :port, :use_ssl, :verify_ssl, :ssl_ca_cert,
12
+ :prefix, :database, :username, :password, :auth_method,
13
+ :open_timeout, :read_timeout,
14
+ :retry, :initial_delay, :max_delay,
15
+ :time_precision, :epoch,
16
+ :async, :udp, :discard_write_errors, :chunk_size, :denormalize
17
+
18
+ def configured?
19
+ !!url || !!host
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ class Prometheus2InfluxDB
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+
5
+ require "influxdb"
6
+ require "yabeda/prometheus"
7
+
8
+ require_relative "prometheus2influxdb/config"
9
+ require_relative "prometheus2influxdb/version"
10
+
11
+ module Yabeda
12
+ class Prometheus2InfluxDB
13
+ include Singleton
14
+
15
+ class Error < StandardError; end
16
+
17
+ def self.start!
18
+ instance.start!
19
+ end
20
+
21
+ def self.configured?
22
+ instance.config.configured?
23
+ end
24
+
25
+ attr_reader :influxdb_client, :registry, :instance_label, :config
26
+
27
+ def initialize
28
+ @config = Config.new
29
+ @influxdb_client = ::InfluxDB::Client.new(**config.to_h)
30
+ @registry = Yabeda::Prometheus.registry
31
+ @instance_label = "#{Socket.gethostname}##{Process.pid}"
32
+ end
33
+
34
+ def start!
35
+ Thread.new do
36
+ loop do
37
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
38
+ Yabeda.collect!
39
+ influxdb_client.write_points(prepare_points)
40
+ finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
+ sleep(config.export_interval_seconds - (finish - start))
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def prepare_points
49
+ Yabeda::Prometheus.registry.metrics.map do |metric|
50
+ series = metric.name.to_s
51
+ metric.values.map do |tags, value|
52
+ tags = tags.merge(instance: instance_label)
53
+ case metric
54
+ when ::Prometheus::Client::Counter, ::Prometheus::Client::Gauge
55
+ { series: series, tags: tags, values: { value: value } }
56
+ when ::Prometheus::Client::Histogram
57
+ histogram_points(series, tags, value)
58
+ else
59
+ raise NotImplementedError, "#{metric.class} isn't supported for exporting to InfluxDB yet"
60
+ end
61
+ end
62
+ end.flatten
63
+ end
64
+
65
+ def histogram_points(name, tags, bucketed_values)
66
+ bucketed_values.map do |bucket, value|
67
+ if bucket == "sum"
68
+ { series: "#{name}_sum", tags: tags, values: { value: value } }
69
+ else
70
+ { series: "#{name}_bucket", tags: tags.merge("le" => bucket), values: { value: value } }
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,6 @@
1
+ module Yabeda
2
+ module Prometheus2InfluxDB
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/yabeda/prometheus2influxdb/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "yabeda-prometheus2influxdb"
7
+ spec.version = Yabeda::Prometheus2InfluxDB::VERSION
8
+ spec.authors = ["Andrey Novikov"]
9
+ spec.email = ["envek@envek.name"]
10
+
11
+ spec.summary = "Experimental gem to push metrics in Prometheus format to InfluxDB endpoint."
12
+ spec.homepage = "https://github.com/yabeda-rb/yabeda-prometheus2influxdb"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/yabeda-rb/yabeda-prometheus2influxdb"
18
+ spec.metadata["changelog_uri"] = "https://github.com/yabeda-rb/yabeda-prometheus2influxdb/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "anyway_config"
32
+ spec.add_dependency "influxdb"
33
+ spec.add_dependency "yabeda-prometheus"
34
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-prometheus2influxdb
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: 2022-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: anyway_config
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: influxdb
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: yabeda-prometheus
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
+ description:
56
+ email:
57
+ - envek@envek.name
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/yabeda/prometheus2influxdb.rb
70
+ - lib/yabeda/prometheus2influxdb/config.rb
71
+ - lib/yabeda/prometheus2influxdb/version.rb
72
+ - sig/yabeda/prometheus2influxdb.rbs
73
+ - yabeda-prometheus2influxdb.gemspec
74
+ homepage: https://github.com/yabeda-rb/yabeda-prometheus2influxdb
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://github.com/yabeda-rb/yabeda-prometheus2influxdb
79
+ source_code_uri: https://github.com/yabeda-rb/yabeda-prometheus2influxdb
80
+ changelog_uri: https://github.com/yabeda-rb/yabeda-prometheus2influxdb/blob/master/CHANGELOG.md
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.3.7
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Experimental gem to push metrics in Prometheus format to InfluxDB endpoint.
100
+ test_files: []