pushgateway-metrics 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc6948aa053495dfa00854c9050a4232377d1eba6192157f7cad341181ab150a
4
+ data.tar.gz: 1a0c4dc06237edd2b16ad1dfc9291195cb2dcca3f3cbbc582df42bc8c756fe41
5
+ SHA512:
6
+ metadata.gz: b24c3b1c87129cefbab217637988df6e47766df1a02b0999ce1da42233b377f6bdd0c8d4203ddaf1cb7ffb88bcde300ab15b5c769fb298705bc5947121e53fa4
7
+ data.tar.gz: 27e5e89a1dbd717e916a0f800a3d24e0da4182cd97e6589f89450989c4813462c90553e120b096cfbe9172524207d8f229fd708299d487511eaf6602c8895a8f
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby interface to a Prometheus pushgateway
4
+ module PushgatewayMetrics
5
+ class << self
6
+ attr_accessor :configuration
7
+ end
8
+
9
+ def self.configure
10
+ self.configuration ||= Configuration.new
11
+ yield(configuration)
12
+ end
13
+
14
+ # Main config for this gem
15
+ class Configuration
16
+ attr_accessor :job
17
+ attr_accessor :instance_name
18
+ attr_accessor :gateway
19
+
20
+ def initialize
21
+ @job = 'local'
22
+ @instance_name = 'instance'
23
+ @gateway = 'http://localhost/'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './configuration.rb'
4
+
5
+ require 'prometheus/client'
6
+ require 'prometheus/client/push'
7
+ require 'active_support/core_ext/string/inflections'
8
+
9
+ # Ruby interface to a Prometheus pushgateway
10
+ module PushgatewayMetrics
11
+
12
+ # Definitions for creating and pushing metrics
13
+ class Metrics
14
+ def self.instance
15
+ @instance ||= new
16
+ end
17
+
18
+ def gateway
19
+ @gateway ||= Prometheus::Client::Push.new(
20
+ PushgatewayMetrics.configuration.job,
21
+ PushgatewayMetrics.configuration.instance_name,
22
+ PushgatewayMetrics.configuration.gateway
23
+ )
24
+ end
25
+
26
+ def errored(value = false)
27
+ @errored ||= value
28
+ end
29
+
30
+ def error(message)
31
+ errored true
32
+ puts message
33
+ end
34
+
35
+ def registry
36
+ @registry ||= Prometheus::Client.registry
37
+ end
38
+
39
+ def push
40
+ push_to_gateway unless errored
41
+ rescue Errno::ECONNREFUSED
42
+ unless errored
43
+ error "Connection to pushgateway on #{gateway} refused. Is it up?"
44
+ end
45
+ rescue Net::OpenTimeout
46
+ unless errored
47
+ error "Connection to pushgateway on #{gateway} timed out. Is it up?"
48
+ end
49
+ end
50
+
51
+ def incr(metric, options = {})
52
+ type = options[:type] || :counter
53
+ labels = options[:labels] || {}
54
+ value = options[:value] || 1
55
+
56
+ registry.send(type, metric, metric.to_s.humanize) unless
57
+ registry.exist?(metric)
58
+ registry.get(metric).increment(labels, value)
59
+ end
60
+
61
+ private
62
+
63
+ def push_to_gateway
64
+ gateway.add(registry)
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushgateway-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ollie Nye
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/configuration.rb
20
+ - lib/pushgateway_metrics.rb
21
+ homepage:
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: An abstracted interface sitting between a Prometheus Pushgateway and your
44
+ app
45
+ test_files: []