influxdb-lineprotocol-writer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +22 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/bin/influxdb-lineprotocol-writer +0 -0
- data/influxdb-lineprotocol-writer.gemspec +31 -0
- data/lib/influxdb-lineprotocol-writer.rb +7 -0
- data/lib/influxdb-lineprotocol-writer/cli.rb +0 -0
- data/lib/influxdb-lineprotocol-writer/core.rb +167 -0
- data/lib/influxdb-lineprotocol-writer/exceptions.rb +10 -0
- data/lib/influxdb-lineprotocol-writer/version.rb +5 -0
- data/oneoff/test.rb +20 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 173c0c4ce86d9a6f831304467ba84a729c8095e7
|
4
|
+
data.tar.gz: 641825007e147abd3989e3ccdd66fab8a7c2a65d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d68b6bc00e556e4353265be592ce5eca44b7f60d53600a99ba1936b4db5fcf8f6309ed30d94d9df1015b9a1ec23fa8eee2a7427ffee2be6c26358af60928d1f
|
7
|
+
data.tar.gz: 2c9320c58376f649ef42f7c1ea87ea54a07867e99578fe9092ca48aa57d02694b75b97153436b3474c24cf13d377cd30d5c34f8ed9bbf9d3924c52362a4fbc8a
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.swp
|
4
|
+
.config
|
5
|
+
coverage/
|
6
|
+
InstalledFiles
|
7
|
+
pkg/
|
8
|
+
spec/reports/
|
9
|
+
test/tmp/
|
10
|
+
test/version_tmp/
|
11
|
+
tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
.yardoc/
|
20
|
+
_yardoc/
|
21
|
+
rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
.bundle/
|
25
|
+
vendor
|
26
|
+
lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
influxdb-lineprotocol-writer (0.1.0)
|
5
|
+
excon (>= 0.45.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
excon (0.45.3)
|
11
|
+
rake (10.1.0)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
influxdb-lineprotocol-writer!
|
18
|
+
rake
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Randy D. Wallace Jr.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'influxdb-lineprotocol-writer/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'influxdb-lineprotocol-writer'
|
7
|
+
s.version = InfluxDB::LineProtocolWriter::VERSION
|
8
|
+
s.licenses = ['MIT']
|
9
|
+
s.summary = "This is a library for the sole purpose of writing one or more datapoints to InfluxDB via the new LineProtocol (https://github.com/influxdb/influxdb/pull/2696)"
|
10
|
+
s.description = <<EOF
|
11
|
+
This is a very basic gem that provides a library that, via Excon, reliably
|
12
|
+
publishes metrics to InfluxDB 0.9.0rc33+ via the LineProtocol Interface.
|
13
|
+
|
14
|
+
This is alpha-quality.
|
15
|
+
|
16
|
+
I wrote this so that I can integrate it into our Sensu infrastructure easily.
|
17
|
+
EOF
|
18
|
+
s.authors = ["Randy D. Wallace Jr."]
|
19
|
+
s.email = 'randy+influxdb-lineprotocol-writer@randywallace.com'
|
20
|
+
|
21
|
+
s.files = `git ls-files -z`.split("\x0")
|
22
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.required_ruby_version = '>= 2.0.0'
|
27
|
+
s.homepage = 'https://github.com/randywallace/influxdb-lineprotocol-writer-ruby'
|
28
|
+
|
29
|
+
s.add_runtime_dependency 'excon', '>= 0.45.3'
|
30
|
+
s.add_development_dependency 'rake'
|
31
|
+
end
|
File without changes
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'excon'
|
2
|
+
|
3
|
+
module InfluxDB
|
4
|
+
module LineProtocolWriter
|
5
|
+
class Core
|
6
|
+
attr_reader :host, :port, :user, :pass, :ssl, :db, :precision, :consistency, :retentionPolicy, :debug
|
7
|
+
def initialize(opts={})
|
8
|
+
# set the defaults
|
9
|
+
opts = {host: 'localhost',
|
10
|
+
port: '8086',
|
11
|
+
user: 'root',
|
12
|
+
pass: 'root',
|
13
|
+
ssl: false,
|
14
|
+
db: 'influxdb',
|
15
|
+
precision: 'ms',
|
16
|
+
consistency: 'one',
|
17
|
+
retentionPolicy: 'default',
|
18
|
+
debug: false}.merge(opts)
|
19
|
+
self.host = opts[:host]
|
20
|
+
self.port = opts[:port]
|
21
|
+
self.user = opts[:user]
|
22
|
+
self.pass = opts[:pass]
|
23
|
+
self.ssl = opts[:ssl]
|
24
|
+
self.db = opts[:db]
|
25
|
+
self.precision = opts[:precision]
|
26
|
+
self.consistency = opts[:consistency]
|
27
|
+
self.retentionPolicy = opts[:retentionPolicy]
|
28
|
+
self.debug = opts[:debug]
|
29
|
+
@metrics = Array.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def connect
|
33
|
+
@conn = Excon.new(get_uri, debug: debug)
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_metric(measurement, tags, fields, timestamp=get_now_timestamp)
|
37
|
+
working = measurement.to_s
|
38
|
+
working += ',' + tags.sort.map{|k,v|"#{k.to_s}=#{v.to_s}"}.join(",") if tags.is_a?(Hash)
|
39
|
+
working += ' '
|
40
|
+
working += fields.sort.map{|k,v|"#{k.to_s}=#{if v.is_a?(String);'"'+v+'"';else;v;end}"}.join(",")
|
41
|
+
working += " #{timestamp}"
|
42
|
+
puts "Adding #{working}"
|
43
|
+
@metrics << working
|
44
|
+
end
|
45
|
+
|
46
|
+
def write
|
47
|
+
@conn.request( expects: [204],
|
48
|
+
method: :post,
|
49
|
+
headers: get_headers,
|
50
|
+
query: get_query_hash,
|
51
|
+
body: metrics
|
52
|
+
)
|
53
|
+
rescue Excon::Errors::InternalServerError => e
|
54
|
+
puts "Internal Server Error: #{e.response.body}"
|
55
|
+
exit 1
|
56
|
+
rescue Excon::Errors::NotFound => e
|
57
|
+
puts "Not Found: #{e.response.body}"
|
58
|
+
exit 1
|
59
|
+
rescue Excon::Errors::Timeout
|
60
|
+
puts "Connect Timout: #{host}:#{port} unreachable"
|
61
|
+
exit 1
|
62
|
+
rescue Excon::Errors::Unauthorized
|
63
|
+
puts "Unauthorized: #{user}/#{pass} not allowed to write to #{db}"
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
|
67
|
+
def metrics
|
68
|
+
@metrics.join("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
def host= val
|
72
|
+
@host = val.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def port= val
|
76
|
+
@port = val.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def user= val
|
80
|
+
@user = val.to_s
|
81
|
+
end
|
82
|
+
|
83
|
+
def pass= val
|
84
|
+
@pass = val.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
def ssl= val
|
88
|
+
# @ssl = !!val
|
89
|
+
if !!val == true
|
90
|
+
raise NotSupportedError, 'Error: SSL is not currently supported!'
|
91
|
+
exit 1
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def db= val
|
96
|
+
@db = val.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
def retentionPolicy= val
|
100
|
+
@retentionPolicy = val
|
101
|
+
end
|
102
|
+
|
103
|
+
def precision= val
|
104
|
+
if %[n u ms s m h].include?(val.to_s)
|
105
|
+
@precision = val.to_s
|
106
|
+
else
|
107
|
+
raise OptionError, 'Precision must be one of (n, u, ms, s, m, h)'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def consistency= val
|
112
|
+
if %[one all any quorum].include?(val.to_s)
|
113
|
+
@consistency = val
|
114
|
+
else
|
115
|
+
raise OptionError, 'Consistency must be one of (one, all, any, quorum)'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def debug= val
|
120
|
+
@debug = !!val
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def get_query_hash
|
126
|
+
{ db: db,
|
127
|
+
rp: retentionPolicy,
|
128
|
+
precision: precision,
|
129
|
+
consistency: consistency,
|
130
|
+
u: user,
|
131
|
+
p: pass
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
def get_uri
|
136
|
+
if self.ssl
|
137
|
+
uri = "https://"
|
138
|
+
else
|
139
|
+
uri = "http://"
|
140
|
+
end
|
141
|
+
"#{uri}#{host}:#{port}/write"
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_headers
|
145
|
+
{ 'Content-Type' => 'plain/text' }
|
146
|
+
end
|
147
|
+
|
148
|
+
def get_now_timestamp
|
149
|
+
case precision
|
150
|
+
when 'n'
|
151
|
+
raise NotSupportedError, 'Nanosecond resolution not currently supported. Pass timestamp in manually'
|
152
|
+
when 'u'
|
153
|
+
raise NotSupportedError, 'Microsecond resolution not currently supported. Pass timestamp in manually'
|
154
|
+
when 'ms'
|
155
|
+
( Time.now.to_f * 1000 ).to_i
|
156
|
+
when 's'
|
157
|
+
Time.now.to_i
|
158
|
+
when 'm'
|
159
|
+
( Time.now.to_i / 60 ).to_i
|
160
|
+
when 'h'
|
161
|
+
( Time.now.to_i / 3600 ).to_i
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/oneoff/test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'influxdb-lineprotocol-writer'
|
2
|
+
|
3
|
+
|
4
|
+
client = InfluxDB::LineProtocolWriter::Core.new host: '10.0.1.159', db: 'graphite', user: 'admin', pass: 'admin'
|
5
|
+
client.debug = true
|
6
|
+
client.connect
|
7
|
+
|
8
|
+
client.add_metric 'test', {test: 'test', test2: 'test2', a: 'val'}, {value: 1.0}
|
9
|
+
sleep 0.1
|
10
|
+
client.add_metric 'test', {z: 'val2', test: 'test', test2: 'test2'}, {value: 2.0}
|
11
|
+
sleep 0.1
|
12
|
+
client.add_metric 'test', {z: 'val2', test: 'test', test2: 'test2'}, {value: 2.0}
|
13
|
+
client.add_metric 'test', {test: 'test', test2: 'test2'}, {value: 3.0}
|
14
|
+
sleep 0.1
|
15
|
+
client.add_metric 'test', nil, {value: 3.0}
|
16
|
+
client.add_metric 'test3', nil, {value: 3.0, test: 'string', deploy: 'v2.0'}
|
17
|
+
sleep 0.1
|
18
|
+
client.add_metric 'test3', nil, {value: 3.0, test: 'string', deploy: 'v2.1'}, 1434077536000
|
19
|
+
|
20
|
+
client.write
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: influxdb-lineprotocol-writer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randy D. Wallace Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: excon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.45.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.45.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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
|
+
description: |
|
42
|
+
This is a very basic gem that provides a library that, via Excon, reliably
|
43
|
+
publishes metrics to InfluxDB 0.9.0rc33+ via the LineProtocol Interface.
|
44
|
+
|
45
|
+
This is alpha-quality.
|
46
|
+
|
47
|
+
I wrote this so that I can integrate it into our Sensu infrastructure easily.
|
48
|
+
email: randy+influxdb-lineprotocol-writer@randywallace.com
|
49
|
+
executables:
|
50
|
+
- influxdb-lineprotocol-writer
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- ".gitignore"
|
55
|
+
- Gemfile
|
56
|
+
- Gemfile.lock
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/influxdb-lineprotocol-writer
|
61
|
+
- influxdb-lineprotocol-writer.gemspec
|
62
|
+
- lib/influxdb-lineprotocol-writer.rb
|
63
|
+
- lib/influxdb-lineprotocol-writer/cli.rb
|
64
|
+
- lib/influxdb-lineprotocol-writer/core.rb
|
65
|
+
- lib/influxdb-lineprotocol-writer/exceptions.rb
|
66
|
+
- lib/influxdb-lineprotocol-writer/version.rb
|
67
|
+
- oneoff/test.rb
|
68
|
+
homepage: https://github.com/randywallace/influxdb-lineprotocol-writer-ruby
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.0.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: This is a library for the sole purpose of writing one or more datapoints
|
92
|
+
to InfluxDB via the new LineProtocol (https://github.com/influxdb/influxdb/pull/2696)
|
93
|
+
test_files: []
|