gbeacon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 453e882c46d4d397f6d8089ea5442b59a13521117ed82a4ea8bf0407d954844c
4
+ data.tar.gz: 4e73c8121f537282e7082e3795191c0bb2017d92ea248607c7f2eabd068f2c21
5
+ SHA512:
6
+ metadata.gz: 502083219c1318691f865f0a7ea40cbfc901bb613f1b0538e19492dac5fc598a24d81f3e43bb3bc82166860a07c6b0a30fa698a6dfe65107cca33d0ff24e8a58
7
+ data.tar.gz: '084259ca6951489892cf82b248b6b832be0849d23b72091d3988244abfb467ffc32db1ce9482d61de9dab81285d8ac2ad0d6ee088fcc295963da220918f9ad92'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -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 fleyhe0@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,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gbeacon.gemspec
6
+ gemspec
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gbeacon (0.1.0)
5
+ graphite-api (~> 0.1.6)
6
+ usagewatch_ext (~> 0.2.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ eventmachine (1.2.7)
13
+ graphite-api (0.1.8)
14
+ eventmachine (>= 0.3.3)
15
+ zscheduler (>= 0.0.3)
16
+ rake (10.5.0)
17
+ rspec (3.8.0)
18
+ rspec-core (~> 3.8.0)
19
+ rspec-expectations (~> 3.8.0)
20
+ rspec-mocks (~> 3.8.0)
21
+ rspec-core (3.8.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-expectations (3.8.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-mocks (3.8.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.8.0)
29
+ rspec-support (3.8.0)
30
+ usagewatch (0.0.7)
31
+ usagewatch_ext (0.2.1)
32
+ usagewatch (~> 0.0.6)
33
+ zscheduler (0.0.8)
34
+ eventmachine
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.16)
41
+ gbeacon!
42
+ rake (~> 10.0)
43
+ rspec (~> 3.0)
44
+
45
+ BUNDLED WITH
46
+ 1.16.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Marlon Henry Schweigert
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.
@@ -0,0 +1,56 @@
1
+ # grafana-beacon
2
+ Full grafana client and service to monitor some resources
3
+
4
+ ## Linux
5
+
6
+ Install docker && Docker Compose:
7
+ ```bash
8
+ sudo apt remove docker docker-engine docker.io
9
+ sudo apt install apt-transport-https ca-certificates curl software-properties-common
10
+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
11
+ sudo apt-key fingerprint 0EBFCD88
12
+ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
13
+ # sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
14
+ sudo apt update
15
+ sudo apt install docker-ce
16
+ sudo usermod -aG docker exampleuser
17
+ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
18
+ sudo chmod +x /usr/local/bin/docker-compose
19
+ ```
20
+
21
+ Docker:
22
+ ```
23
+ docker volume create --name=grafana-volume
24
+ sudo docker-compose up -d
25
+ ```
26
+
27
+ ## Login
28
+
29
+ `admin:admin`
30
+
31
+ ## Add DB
32
+
33
+ Name: Graphite - Or other
34
+ Type: Graphite
35
+
36
+ ### HTTP
37
+
38
+ URL: http://graphite:8080
39
+ Access: Server (default)
40
+
41
+ ### Auth
42
+
43
+ BasicAuth: False
44
+ With Credentials: False
45
+ TLS Client Auth: False
46
+ With CA Cert: False
47
+
48
+ Skip TLS Verification (Insecure): False
49
+
50
+ ### Advanced HTTP Settings
51
+
52
+ None
53
+
54
+ ### Graphite Details
55
+
56
+ Select the newest available
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gbeacon"
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__)
@@ -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,47 @@
1
+ require "gbeacon"
2
+
3
+ params = { graphite: 'tcp://localhost:2003', slice: 0, interval: 0, prefix: ['gbeacon'], cache: 0 }
4
+
5
+ if ARGV[0] == '--help'
6
+ puts 'gbeacon.rb --graphite "tcp://local:2003" --slice 0 --interval 0 --prefix "service_name" --cache 0'
7
+ puts 'Defaults:'
8
+ pp params
9
+ exit 0
10
+ end
11
+
12
+ param = :graphite
13
+
14
+ ARGV.each do |key|
15
+ if key == '--graphite'
16
+ param = :graphite
17
+ next
18
+ elsif key == '--slice'
19
+ param = :slice
20
+ next
21
+ elsif key == '--interval'
22
+ param = :interval
23
+ next
24
+ elsif key == '--prefix'
25
+ param = :prefix
26
+ next
27
+ elsif key == '--cache'
28
+ param = :cache
29
+ next
30
+ end
31
+
32
+ if param != :prefix
33
+ params[param] = key
34
+ else
35
+ params[:prefix] << key
36
+ end
37
+ end
38
+
39
+ puts 'Starting beacon with:'
40
+
41
+ pp params
42
+ b = Gbeacon::Beacon.new(params)
43
+ b.check!
44
+
45
+ loop do
46
+ pp b.send_resources
47
+ end
@@ -0,0 +1,28 @@
1
+ version: "3"
2
+ services:
3
+ grafana:
4
+ image: grafana/grafana
5
+ container_name: grafana
6
+ restart: always
7
+ ports:
8
+ - 3000:3000
9
+ networks:
10
+ - grafana-net
11
+ volumes:
12
+ - grafana-volume
13
+
14
+ graphite:
15
+ image: graphiteapp/graphite-statsd
16
+ container_name: graphite
17
+ ports:
18
+ - 2003:2003
19
+ restart: always
20
+ networks:
21
+ - grafana-net
22
+
23
+ networks:
24
+ grafana-net:
25
+
26
+ volumes:
27
+ grafana-volume:
28
+ external: true
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gbeacon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gbeacon'
8
+ spec.version = Gbeacon::VERSION
9
+ spec.authors = ['Marlon Henry Schweigert']
10
+ spec.email = ['fleyhe0@gmail.com']
11
+
12
+ spec.summary = 'Grafana beacon'
13
+ spec.description = 'Grafana beacon'
14
+ spec.homepage = 'http://www.github.com/schweigert/grafana-beacon'
15
+ spec.license = 'MIT'
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('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'cmd'
23
+ spec.executables = ['gbeacon.rb']
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'graphite-api', '~> 0.1.6'
27
+ spec.add_dependency 'usagewatch_ext', '~> 0.2.1'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ end
@@ -0,0 +1,14 @@
1
+ sudo apt remove docker docker-engine docker.io
2
+ sudo apt install apt-transport-https ca-certificates curl software-properties-common
3
+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4
+ sudo apt-key fingerprint 0EBFCD88
5
+ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
6
+ # sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
7
+ sudo apt update
8
+ sudo apt install docker-ce
9
+ sudo usermod -aG docker exampleuser
10
+ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
11
+ sudo chmod +x /usr/local/bin/docker-compose
12
+
13
+ docker volume create --name=grafana-volume
14
+ sudo docker-compose up -d
@@ -0,0 +1,84 @@
1
+ require 'gbeacon/version'
2
+ require 'graphite-api'
3
+ require 'usagewatch_ext'
4
+
5
+ module Gbeacon
6
+ class Beacon
7
+ def initialize graphite:'tcp://localhost:2003', prefix: ['default', 'beacon'], slice: 60, interval: 60, cache: 60 * 60 * 24
8
+ @client = GraphiteAPI.new(graphite: graphite, prefix: prefix, slice: slice, interval: interval, cache: cache)
9
+ end
10
+
11
+ def send_resources
12
+ @client.metrics(build_resources, Time.now)
13
+ end
14
+
15
+ def check!
16
+ @client.check!
17
+ end
18
+
19
+ private
20
+
21
+ def build_resources
22
+ {
23
+ 'uw_diskused' => Usagewatch.uw_diskused,
24
+ 'uw_diskused_perc' => Usagewatch.uw_diskused_perc,
25
+ 'uw_cpuused' => Usagewatch.uw_cpuused,
26
+ 'uw_tcpused' => Usagewatch.uw_tcpused,
27
+ 'uw_udpused' => Usagewatch.uw_udpused,
28
+ 'uw_memused' => Usagewatch.uw_memused,
29
+ 'uw_load' => Usagewatch.uw_load,
30
+ 'uw_bandrx' => Usagewatch.uw_bandrx,
31
+ 'uw_bandtx' => Usagewatch.uw_bandtx,
32
+ 'uw_diskioreads' => Usagewatch.uw_diskioreads,
33
+ 'uw_diskiowrites' => Usagewatch.uw_diskiowrites,
34
+ 'uw_httpconns' => Usagewatch.uw_httpconns,
35
+ 'total_memory_linux_monitor' => total_memory_linux_monitor,
36
+ 'used_memory_linux_monitor' => used_memory_linux_monitor,
37
+ 'total_swap_linux_monitor' => total_swap_linux_monitor,
38
+ 'used_swap_linux_monitor' => used_swap_linux_monitor,
39
+ 'free_memory_linux_monitor' => free_memory_linux_monitor,
40
+ 'free_swap_linux_monitor' => free_swap_linux_monitor
41
+ }
42
+ end
43
+
44
+ def total_memory_linux_monitor
45
+ free_mem.split("\n")[1].split(" ")[1]
46
+ rescue
47
+ '0'
48
+ end
49
+
50
+ def total_swap_linux_monitor
51
+ free_mem.split("\n")[2].split(" ")[1]
52
+ rescue
53
+ '0'
54
+ end
55
+
56
+ def used_memory_linux_monitor
57
+ free_mem.split("\n")[1].split(" ")[2]
58
+ rescue
59
+ '0'
60
+ end
61
+
62
+ def used_swap_linux_monitor
63
+ free_mem.split("\n")[2].split(" ")[2]
64
+ rescue
65
+ '0'
66
+ end
67
+
68
+ def free_memory_linux_monitor
69
+ free_mem.split("\n")[1].split(" ")[3]
70
+ rescue
71
+ '0'
72
+ end
73
+
74
+ def free_swap_linux_monitor
75
+ free_mem.split("\n")[2].split(" ")[3]
76
+ rescue
77
+ '0'
78
+ end
79
+
80
+ def free_mem
81
+ `free -m`
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module Gbeacon
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gbeacon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marlon Henry Schweigert
8
+ autorequire:
9
+ bindir: cmd
10
+ cert_chain: []
11
+ date: 2018-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphite-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: usagewatch_ext
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Grafana beacon
84
+ email:
85
+ - fleyhe0@gmail.com
86
+ executables:
87
+ - gbeacon.rb
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - cmd/gbeacon.rb
101
+ - docker-compose.yml
102
+ - gbeacon.gemspec
103
+ - install.sh
104
+ - lib/gbeacon.rb
105
+ - lib/gbeacon/version.rb
106
+ homepage: http://www.github.com/schweigert/grafana-beacon
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Grafana beacon
130
+ test_files: []