como_client 0.1.1

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
+ SHA1:
3
+ metadata.gz: ae20fe23f326d495c7edf5f443930b2367aed444
4
+ data.tar.gz: b93f69e2785a6555fe7c98d9cc8827f8453c6cd8
5
+ SHA512:
6
+ metadata.gz: ddb4bcbc381b9c3fc9697e1a778e284fdcac72af88c4d5387902fb3a85753f5ee59574417c896865779c8a979844cdd7828c7afb081af3be529ba687c87c78ed
7
+ data.tar.gz: 0f33065ad30d448a07731b570cf102e639b80bd19f1ff98e47505ba06c895c82d7d82ab16719adc9888c75ecd9ef901dabf201f6f06a6a2a3b6fe06c3b11dad2
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ /.rspec
12
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at Colin.Disler1@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in COMO_Client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Disler Colin, INI-DEV-APO-CAU-LFA
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,34 @@
1
+ # COMOClient
2
+
3
+ If you work in a Cloud Foundry environment and want to actively push your Prometheus Metrics in a certain interval, you definitely have to try the **COMO Client** Gem!
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'COMO_Client'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install COMO_Client
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ # config/initializers/como_client.rb
26
+
27
+ COMOClient.configure do |config|
28
+ config.enabled = true
29
+ config.push_interval = 10
30
+ config.pushgateway_url = "https://your-app.some-prometheus-pushgateway.com"
31
+ config.job_name = "your-app-metrics"
32
+ config.instance_name = "your-app-metrics-1"
33
+ end
34
+ ```
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "como_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ 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
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'como_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "como_client"
8
+ spec.version = COMOClient::VERSION
9
+ spec.authors = ["Disler Colin"]
10
+ spec.email = ["Colin.Disler@gmail.com"]
11
+
12
+ spec.summary = "A Prometheus Client for continuous monitoring"
13
+ spec.description = "A Prometheus Client for continuous monitoring"
14
+ spec.homepage = "https://github.com/lombold/COMO_Client"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against" \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency 'rspec'
34
+ spec.add_dependency 'concurrent-ruby'
35
+ spec.add_dependency 'prometheus-client'
36
+ spec.add_dependency 'usagewatch_ext'
37
+ spec.add_dependency 'mem_info'
38
+ end
@@ -0,0 +1,57 @@
1
+ require 'como_client/version'
2
+ require 'como_client/configuration'
3
+ require 'como_client/tasks/periodic_push'
4
+ require 'como_client/tasks/observer'
5
+ require 'como_client/metrics'
6
+ require 'como_client/metrics/cf'
7
+ require 'concurrent'
8
+ require 'rack'
9
+ require 'prometheus/middleware/exporter'
10
+ require 'prometheus/middleware/collector'
11
+
12
+ module COMOClient
13
+
14
+ class Railtie < Rails::Railtie
15
+ initializer 'como_client.configure_rails_initialization' do
16
+ Rails.configuration.middleware.use Prometheus::Middleware::Collector
17
+ Rails.configuration.middleware.use Prometheus::Middleware::Exporter
18
+ end
19
+ end
20
+
21
+ class << self
22
+ attr_writer :configuration
23
+ end
24
+
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.reset
30
+ @configuration = Configuration.new
31
+ end
32
+
33
+ def self.configure
34
+ yield(configuration)
35
+ self.run
36
+ end
37
+
38
+ def self.run
39
+ logger = Logger.new(STDOUT)
40
+ logger.info("initialize metrics push service...")
41
+ if @pushTask and @pushTask.running?
42
+ logger.info("the metrics push service is already running!")
43
+ return true
44
+ end
45
+
46
+ COMOClient::Metrics.register
47
+ @pushTask = Concurrent::TimerTask.new(execution_interval: 20, timeout_interval: 20){COMOClient::Tasks::PeriodicPush.push}
48
+ @pushTask.add_observer(COMOClient::Tasks::Observer.new)
49
+ @pushTask.execute
50
+ logger.info("successfully initiated metrics push service!")
51
+ @pushTask.running?
52
+ end
53
+
54
+ def self.stop
55
+ @pushTask.shutdown
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module COMOClient
2
+ class Configuration
3
+ attr_accessor :enabled
4
+ attr_accessor :push_interval
5
+ attr_accessor :pushgateway_url
6
+ attr_accessor :job_name
7
+ attr_accessor :instance_name
8
+
9
+ def initialize
10
+ @enabled = false
11
+ @push_interval = 20
12
+ @pushgateway_url = "https://example.com"
13
+ @job_name = "prometheus-metrics"
14
+ @instance_name = "prometheus-metrics#0"
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module COMOClient
2
+ module Metrics
3
+ def self.register
4
+ logger = Logger.new(STDOUT)
5
+ logger.info("register metrics...")
6
+
7
+ #Register Cloud Froundry metrics if the app is pushed to Cloud Foundry
8
+ COMOClient::Metrics::CF.register if !ENV["CF_INSTANCE_GUID"].nil?
9
+
10
+ logger.info("registered metrics")
11
+ end
12
+
13
+ def self.update
14
+ logger = Logger.new(STDOUT)
15
+ logger.info("update metrics...")
16
+
17
+ #Update Cloud Froundry metrics if the app is pushed to Cloud Foundry
18
+ COMOClient::Metrics::CF.update if !ENV["CF_INSTANCE_GUID"].nil?
19
+
20
+ logger.info("updated metrics")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ module COMOClient
2
+ module Metrics
3
+ class CF
4
+
5
+ require 'usagewatch_ext'
6
+ require 'mem_info'
7
+
8
+ def self.register
9
+ logger = Logger.new(STDOUT)
10
+ logger.info("register CF metrics...")
11
+
12
+ prometheus = Prometheus::Client.registry
13
+
14
+ hardwareGauges = Prometheus::Client::Gauge.new(:instance_metrics, 'instance hardware metrics')
15
+ prometheus.register(hardwareGauges)
16
+ logger.info("registered hardware gauges")
17
+
18
+ logger.info("registered CF metrics")
19
+ end
20
+ def self.update
21
+ logger = Logger.new(STDOUT)
22
+ logger.info("update CF metrics...")
23
+ prometheus = Prometheus::Client.registry
24
+
25
+ usw = Usagewatch
26
+ mem = MemInfo.new
27
+ hardwareGauges = prometheus.get(:instance_metrics)
28
+ hardwareGauges.set({ hardware: 'cpu'}, usw.uw_cpuused)
29
+ hardwareGauges.set({ hardware: 'avg_load_past_minute'}, usw.uw_load)
30
+ hardwareGauges.set({ hardware: 'memory_total'}, mem.memtotal)
31
+ hardwareGauges.set({ hardware: 'memory_free'}, mem.memfree)
32
+ hardwareGauges.set({ hardware: 'memory_used'}, mem.memused)
33
+ hardwareGauges.set({ hardware: 'disk_used_perc'}, usw.uw_diskused_perc)
34
+ hardwareGauges.set({ hardware: 'disk_used_gigabytes'}, usw.uw_diskused)
35
+ hardwareGauges.set({ hardware: 'uptime_seconds'}, IO.read('/proc/uptime').split[0].to_i)
36
+ logger.info("instance gauges")
37
+
38
+ logger.info("updated CF metrics")
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ module COMOClient
2
+ module Tasks
3
+ class Observer
4
+ def update(_time, result, ex)
5
+ if result
6
+ Rails.logger.info "Execution successfully returned #{result}\n"
7
+ elsif ex.is_a?(Concurrent::TimeoutError)
8
+ Rails.logger.fatal "Execution timed out\n"
9
+ else
10
+ Rails.logger.fatal "Execution failed with error #{ex}\n"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module COMOClient
2
+ module Tasks
3
+ class PeriodicPush
4
+ require 'prometheus/client'
5
+ require 'prometheus/client/push'
6
+ def self.push
7
+ # register some metrics
8
+ logger = Logger.new(STDOUT)
9
+ logger.info("pushing metrics to #{COMOClient.configuration.pushgateway_url}")
10
+ logger.info("job: #{COMOClient.configuration.job_name}")
11
+ logger.info("instance: #{COMOClient.configuration.instance_name}")
12
+ COMOClient::Metrics.update
13
+ Prometheus::Client::Push.new(COMOClient.configuration.job_name, #job name
14
+ COMOClient.configuration.instance_name,#instance name
15
+ COMOClient.configuration.pushgateway_url)#pushgateway url
16
+ .add(Prometheus::Client.registry)
17
+ logger.info("successfully pushed metrics")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module COMOClient
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: como_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Disler Colin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
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: :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: prometheus-client
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
+ - !ruby/object:Gem::Dependency
56
+ name: usagewatch_ext
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mem_info
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A Prometheus Client for continuous monitoring
84
+ email:
85
+ - Colin.Disler@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - como_client.gemspec
100
+ - lib/como_client.rb
101
+ - lib/como_client/configuration.rb
102
+ - lib/como_client/metrics.rb
103
+ - lib/como_client/metrics/cf.rb
104
+ - lib/como_client/tasks/observer.rb
105
+ - lib/como_client/tasks/periodic_push.rb
106
+ - lib/como_client/version.rb
107
+ homepage: https://github.com/lombold/COMO_Client
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A Prometheus Client for continuous monitoring
132
+ test_files: []