vm-client 1.0.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.
@@ -0,0 +1,96 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'prometheus/client'
4
+ require 'prometheus/client/formats/text'
5
+
6
+ module Prometheus
7
+ module Middleware
8
+ # Exporter is a Rack middleware that provides a sample implementation of a
9
+ # Prometheus HTTP exposition endpoint.
10
+ #
11
+ # By default it will export the state of the global registry and expose it
12
+ # under `/metrics`. Use the `:registry` and `:path` options to change the
13
+ # defaults.
14
+ class Exporter
15
+ attr_reader :app, :registry, :path
16
+
17
+ FORMATS = [Client::Formats::Text].freeze
18
+ FALLBACK = Client::Formats::Text
19
+
20
+ def initialize(app, options = {})
21
+ @app = app
22
+ @registry = options[:registry] || Client.registry
23
+ @path = options[:path] || '/metrics'
24
+ @port = options[:port]
25
+ @acceptable = build_dictionary(FORMATS, FALLBACK)
26
+ end
27
+
28
+ def call(env)
29
+ if metrics_port?(env['SERVER_PORT']) && env['PATH_INFO'] == @path
30
+ format = negotiate(env, @acceptable)
31
+ format ? respond_with(format) : not_acceptable(FORMATS)
32
+ else
33
+ @app.call(env)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def negotiate(env, formats)
40
+ parse(env.fetch('HTTP_ACCEPT', '*/*')).each do |content_type, _|
41
+ return formats[content_type] if formats.key?(content_type)
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ def parse(header)
48
+ header.split(/\s*,\s*/).map do |type|
49
+ attributes = type.split(/\s*;\s*/)
50
+ quality = extract_quality(attributes)
51
+
52
+ [attributes.join('; '), quality]
53
+ end.sort_by(&:last).reverse
54
+ end
55
+
56
+ def extract_quality(attributes, default = 1.0)
57
+ quality = default
58
+
59
+ attributes.delete_if do |attr|
60
+ quality = attr.split('q=').last.to_f if attr.start_with?('q=')
61
+ end
62
+
63
+ quality
64
+ end
65
+
66
+ def respond_with(format)
67
+ [
68
+ 200,
69
+ { 'content-type' => format::CONTENT_TYPE },
70
+ [format.marshal(@registry)],
71
+ ]
72
+ end
73
+
74
+ def not_acceptable(formats)
75
+ types = formats.map { |format| format::MEDIA_TYPE }
76
+
77
+ [
78
+ 406,
79
+ { 'content-type' => 'text/plain' },
80
+ ["Supported media types: #{types.join(', ')}"],
81
+ ]
82
+ end
83
+
84
+ def build_dictionary(formats, fallback)
85
+ formats.each_with_object('*/*' => fallback) do |format, memo|
86
+ memo[format::CONTENT_TYPE] = format
87
+ memo[format::MEDIA_TYPE] = format
88
+ end
89
+ end
90
+
91
+ def metrics_port?(request_port)
92
+ @port.nil? || @port.to_s == request_port
93
+ end
94
+ end
95
+ end
96
+ end
data/lib/prometheus.rb ADDED
@@ -0,0 +1,5 @@
1
+ # encoding: UTF-8
2
+
3
+ # Prometheus is a generic time-series collection and computation server.
4
+ module Prometheus
5
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vm-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleg Tolmashov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: benchmark-ips
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: concurrent-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: timecop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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
+ - koilanetroc@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - lib/prometheus.rb
65
+ - lib/prometheus/client.rb
66
+ - lib/prometheus/client/config.rb
67
+ - lib/prometheus/client/counter.rb
68
+ - lib/prometheus/client/data_stores/README.md
69
+ - lib/prometheus/client/data_stores/direct_file_store.rb
70
+ - lib/prometheus/client/data_stores/single_threaded.rb
71
+ - lib/prometheus/client/data_stores/synchronized.rb
72
+ - lib/prometheus/client/formats/text.rb
73
+ - lib/prometheus/client/gauge.rb
74
+ - lib/prometheus/client/histogram.rb
75
+ - lib/prometheus/client/label_set_validator.rb
76
+ - lib/prometheus/client/metric.rb
77
+ - lib/prometheus/client/push.rb
78
+ - lib/prometheus/client/registry.rb
79
+ - lib/prometheus/client/summary.rb
80
+ - lib/prometheus/client/version.rb
81
+ - lib/prometheus/client/vm_histogram.rb
82
+ - lib/prometheus/middleware/collector.rb
83
+ - lib/prometheus/middleware/exporter.rb
84
+ homepage: https://github.com/Koilanetroc/vm-client
85
+ licenses:
86
+ - Apache-2.0
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.4.1
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Fork of prometheus-client intended to be a drop-in replacementfor prometheus-client
107
+ to switch from Prometheus to VictoriaMetrics
108
+ test_files: []