docker_boss-module-influxdb 0.0.4
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/docker_boss-module-influxdb.gemspec +23 -0
- data/lib/docker_boss/module/influxdb.rb +161 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c668bb42eac0f49df34a5af2fd530999ca26a5bb
|
4
|
+
data.tar.gz: 3a3ce91abb109ce345dd130ee81f3227e45e2837
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1b4c4e5b69b50d0517d0b5adeb02720dee0b7943ac82ac9c9bcd47ea05c10ca6fc0bbf20453072766e231368259a651b9c4283d413e956058de989745e660a7
|
7
|
+
data.tar.gz: d11242a6c0151fd4e6fa6b747e3e641acb42fa14f40714f10ea90323320f468af5753e71746b6a85d99d518c4f7b1cba6bfbcafa4228f1ee88feb60d2717ce74
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alex Hornung
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# DockerBoss::Module::InfluxDB
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'docker_boss-module-influxdb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install docker_boss-module-influxdb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Example yaml:
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
influxdb:
|
25
|
+
server:
|
26
|
+
protocol: http
|
27
|
+
host: localhost
|
28
|
+
port: 8086
|
29
|
+
user: root
|
30
|
+
pass: root
|
31
|
+
no_verify: false
|
32
|
+
|
33
|
+
database: db1
|
34
|
+
|
35
|
+
prefix: container.
|
36
|
+
interval: 60
|
37
|
+
|
38
|
+
cgroup_path: /sys/fs/cgroup
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.4
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "docker_boss-module-influxdb"
|
7
|
+
spec.version = File.read("VERSION").strip
|
8
|
+
spec.authors = ["Alex Hornung"]
|
9
|
+
spec.email = ["alex@alexhornung.com"]
|
10
|
+
spec.description = %q{DockerBoss plugin to export container cgroup metrics to InfluxDB}
|
11
|
+
spec.summary = spec.description
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "docker_boss", "~> 0.1.4"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'docker_boss'
|
2
|
+
require 'docker_boss/module'
|
3
|
+
require 'thread'
|
4
|
+
require 'celluloid'
|
5
|
+
require 'timers'
|
6
|
+
require 'net/http'
|
7
|
+
require 'uri'
|
8
|
+
require 'cgi'
|
9
|
+
|
10
|
+
class DockerBoss::Module::InfluxDB < DockerBoss::Module
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
13
|
+
@mutex = Mutex.new
|
14
|
+
@containers = []
|
15
|
+
docker_cg = File.exists? "#{config['cgroup_path']}/blkio/docker"
|
16
|
+
@config['docker_cg'] = docker_cg
|
17
|
+
|
18
|
+
@pool = Worker.pool(args: [@config])
|
19
|
+
DockerBoss.logger.debug "influxdb: Set up to connect to #{@config['server']['protocol']}://[#{@config['server']['host']}]:#{@config['server']['port']}"
|
20
|
+
@timers = Timers::Group.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def connection
|
24
|
+
@http ||= begin
|
25
|
+
raise ArgumentError, "Unknown InfluxDB protocol #{@config['server']['protocol']}" unless ['http', 'https'].include? @config['server']['protocol']
|
26
|
+
http = Net::HTTP.new(@config['server']['host'], @config['server']['port'])
|
27
|
+
http.use_ssl = @config['server']['protocol'] == 'https'
|
28
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @config['server'].fetch('no_verify', false)
|
29
|
+
http
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def do_query(q)
|
34
|
+
request = Net::HTTP::Get.new("/db/#{@config['database']}/series?q=#{CGI.escape(q)}")
|
35
|
+
request.basic_auth @config['server']['user'], @config['server']['pass']
|
36
|
+
connection.request(request)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_connection!
|
40
|
+
response = do_query('list series')
|
41
|
+
raise Error.new response.body unless response.kind_of? Net::HTTPSuccess
|
42
|
+
DockerBoss.logger.debug "influxdb: Connection tested successfully"
|
43
|
+
end
|
44
|
+
|
45
|
+
def do_post!(data)
|
46
|
+
request = Net::HTTP::Post.new("/db/#{@config['database']}/series")
|
47
|
+
request.basic_auth @config['server']['user'], @config['server']['pass']
|
48
|
+
request.add_field('Content-Type', 'application/json')
|
49
|
+
request.body = data.to_json
|
50
|
+
response = connection.request(request)
|
51
|
+
raise Error.new response.body unless response.kind_of? Net::HTTPSuccess
|
52
|
+
end
|
53
|
+
|
54
|
+
def run
|
55
|
+
test_connection!
|
56
|
+
|
57
|
+
@timers.every(@config['interval']) { sample }
|
58
|
+
|
59
|
+
Thread.new do
|
60
|
+
loop { @timers.wait }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def trigger(containers, trigger_id)
|
65
|
+
@mutex.synchronize {
|
66
|
+
@containers = containers
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def sample
|
71
|
+
containers = []
|
72
|
+
|
73
|
+
@mutex.synchronize {
|
74
|
+
containers = @containers.map { |c| { id: c['Id'], name: c['Name'][1..-1] } }
|
75
|
+
}
|
76
|
+
|
77
|
+
futures = containers.map { |c| @pool.future :sample_container, c }
|
78
|
+
|
79
|
+
do_post! futures.map { |f| f.value }
|
80
|
+
end
|
81
|
+
|
82
|
+
class Error < StandardError
|
83
|
+
end
|
84
|
+
|
85
|
+
class Worker
|
86
|
+
include Celluloid
|
87
|
+
|
88
|
+
def initialize(config)
|
89
|
+
@config = config
|
90
|
+
end
|
91
|
+
|
92
|
+
def build_path(id, type, file)
|
93
|
+
if @config['docker_cg']
|
94
|
+
"#{@config['cgroup_path']}/#{type}/docker/#{id}/#{file}"
|
95
|
+
else
|
96
|
+
"#{@config['cgroup_path']}/#{type}/system.slice/docker-#{id}.scope/#{file}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def sample_container(container)
|
101
|
+
time_now = Time.now.to_i
|
102
|
+
data = { time: time_now }
|
103
|
+
|
104
|
+
kv_sample(container[:id], 'memory', 'memory.stat', 'memory') { |k,v| data[k] = v }
|
105
|
+
kv_sample(container[:id], 'cpuacct', 'cpuacct.stat', 'cpuacct') { |k,v| data[k] = v }
|
106
|
+
['blkio.io_serviced', 'blkio.io_service_bytes',
|
107
|
+
'blkio.io_wait_time', 'blkio.io_service_time', 'blkio.io_queued'].each do |f|
|
108
|
+
blkio_sample(container[:id], 'blkio', f, f.gsub(/\./, '_')) { |k,v| data[k] = v }
|
109
|
+
end
|
110
|
+
['blkio.sectors'].each do |f|
|
111
|
+
blkio_v_sample(container[:id], 'blkio', f, f.gsub(/\./, '_')) { |k,v| data[k] = v }
|
112
|
+
end
|
113
|
+
|
114
|
+
name = container[:name].empty? ? container[:id] : container[:name]
|
115
|
+
|
116
|
+
{
|
117
|
+
name: "#{@config['prefix']}#{name}",
|
118
|
+
columns: data.keys,
|
119
|
+
points: [ data.values ],
|
120
|
+
time_precision: 's'
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def kv_sample(id, type, file, key_prefix)
|
125
|
+
return to_enum(:kv_sample, id, type, file, key_prefix) unless block_given?
|
126
|
+
|
127
|
+
File.readlines(build_path(id, type, file)).each do |line|
|
128
|
+
(k,v) = line.chomp.split(/\s+/, 2)
|
129
|
+
yield "#{key_prefix}_#{k.downcase}", v.to_i
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def blkio_sample(id, type, file, key_prefix)
|
134
|
+
return to_enum(:blkio_sample, id, type, file, key_prefix) unless block_given?
|
135
|
+
data = {}
|
136
|
+
|
137
|
+
File.readlines(build_path(id, type, file)).each do |line|
|
138
|
+
(maj_min,k,v) = line.chomp.split(/\s+/, 3)
|
139
|
+
if maj_min != 'Total'
|
140
|
+
data["#{key_prefix}_#{k.downcase}"] ||= 0
|
141
|
+
data["#{key_prefix}_#{k.downcase}"] += v.to_i
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
data.each { |k,v| yield k, v }
|
146
|
+
end
|
147
|
+
|
148
|
+
def blkio_v_sample(id, type, file, key)
|
149
|
+
return to_enum(:blkio_v_sample, id, type, file, key) unless block_given?
|
150
|
+
data = {}
|
151
|
+
|
152
|
+
File.readlines(build_path(id, type, file)).each do |line|
|
153
|
+
(maj_min,v) = line.chomp.split(/\s+/, 2)
|
154
|
+
data[key] ||= 0
|
155
|
+
data[key] += v.to_i
|
156
|
+
end
|
157
|
+
|
158
|
+
data.each { |k,v| yield k, v }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docker_boss-module-influxdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Hornung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docker_boss
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.4
|
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.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: DockerBoss plugin to export container cgroup metrics to InfluxDB
|
56
|
+
email:
|
57
|
+
- alex@alexhornung.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- VERSION
|
68
|
+
- docker_boss-module-influxdb.gemspec
|
69
|
+
- lib/docker_boss/module/influxdb.rb
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.14
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: DockerBoss plugin to export container cgroup metrics to InfluxDB
|
94
|
+
test_files: []
|