embulk-output-influxdb08 0.1.1
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 +6 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +3 -0
- data/embulk-output-influxdb08.gemspec +23 -0
- data/example.csv +13 -0
- data/example.yml +24 -0
- data/lib/embulk/output/influxdb08.rb +178 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 05de8c09ef40e9b5d7b4d55fea895865ec094d6d
|
4
|
+
data.tar.gz: 52bb9d1d246c5438ecc06ec0435c1b0c44ef7f21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03a925fca8c2e5bed91e18596ece84cc0465ff8582568df19cfc520a4038510bda1f3fdeba17458b09adc33b56988a3b1edb315c99a0e60fce344606efac1b72
|
7
|
+
data.tar.gz: 9ff0731225d3eda7bf9aaa5fae8567c2e6a95decefe2bd894fb6b5f692bac5cb6050b37f13bde4a0d3b481f3d646dfdb02646522b1b194d5b42d887452887bbc
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.0.1.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# InfluxDB v0.8 output plugin for Embulk
|
2
|
+
|
3
|
+
**This plug in is the fork of [joker1007/embulk-output-influxdb](https://github.com/joker1007/embulk-output-influxdb) and supports only influxdb v0.8.**
|
4
|
+
**It is strongly recommended to use newer influxdb and [joker1007/embulk-output-influxdb](https://github.com/joker1007/embulk-output-influxdb).**
|
5
|
+
|
6
|
+
|
7
|
+
## Overview
|
8
|
+
|
9
|
+
* **Plugin type**: output
|
10
|
+
* **Load all or nothing**: no
|
11
|
+
* **Resume supported**: no
|
12
|
+
* **Cleanup supported**: yes
|
13
|
+
* **Dynamic Database creating**: yes
|
14
|
+
* **Dynamic Series creating**: yes
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
- **host**: hostname (string, default: localhost)
|
19
|
+
- **port**: port number (integer, default: 8086)
|
20
|
+
- **username**: username (string, default: 'root')
|
21
|
+
- **password**: password (string, default: 'root')
|
22
|
+
- **database**: database name (string, required)
|
23
|
+
- **series**: series name (string, required) (can use column value placeholder. see example)
|
24
|
+
- **mode**: "insert", or "replace". See bellow. (string, default: insert)
|
25
|
+
- **timestamp_column**: timestamp column (string, default: nil)
|
26
|
+
- **ignore_columns**: ignore column names (array[string], default: [])
|
27
|
+
- **default_timezone**: default timezone for column (string, default: 'UTC')
|
28
|
+
|
29
|
+
### Modes
|
30
|
+
|
31
|
+
* **insert**:
|
32
|
+
* Behavior: This mode inserts rows simplly.
|
33
|
+
* **replace**:
|
34
|
+
* Behavior: Same with insert mode excepting that it drops the target series first.
|
35
|
+
|
36
|
+
## Example
|
37
|
+
|
38
|
+
```yaml
|
39
|
+
out:
|
40
|
+
type: influxdb
|
41
|
+
username: root
|
42
|
+
password: root
|
43
|
+
database: dbname
|
44
|
+
series: ${key_name}_series
|
45
|
+
timestamp_column: day
|
46
|
+
mode: replace
|
47
|
+
ignore_columns:
|
48
|
+
- key_name
|
49
|
+
```
|
50
|
+
|
51
|
+
## ToDo
|
52
|
+
- column_options support
|
53
|
+
|
54
|
+
## Build
|
55
|
+
|
56
|
+
```
|
57
|
+
$ rake
|
58
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-output-influxdb08"
|
4
|
+
spec.version = "0.1.1"
|
5
|
+
spec.authors = ["atsaki"]
|
6
|
+
spec.summary = "InfluxDB v0.8 output plugin for Embulk"
|
7
|
+
spec.description = "Dumps records to InfluxDB v0.8."
|
8
|
+
spec.email = ["atsaki01@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/atsaki/embulk-output-influxdb08.git"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_development_dependency 'embulk', ['~> 0.7.4']
|
17
|
+
spec.add_development_dependency 'bundler', ['~> 1.0']
|
18
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
19
|
+
spec.add_development_dependency 'tapp'
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'influxdb', ['0.1.9']
|
22
|
+
spec.add_runtime_dependency 'timezone'
|
23
|
+
end
|
data/example.csv
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
key_name,day,value,name
|
2
|
+
new_clients,2015-08-22,1,a
|
3
|
+
new_clients,2015-08-25,2,b
|
4
|
+
new_clients,2015-08-26,3,c
|
5
|
+
new_clients,2015-08-27,4,a
|
6
|
+
new_clients,2015-08-28,10,b
|
7
|
+
new_clients,2015-08-29,11,c
|
8
|
+
new_clients,2015-09-01,12,a
|
9
|
+
new_clients,2015-09-03,13,b
|
10
|
+
new_clients,2015-09-05,21,c
|
11
|
+
new_clients,2015-09-07,22,a
|
12
|
+
new_clients,2015-09-11,23,b
|
13
|
+
new_clients,2015-09-12,24,c
|
data/example.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
in:
|
2
|
+
type: file
|
3
|
+
path_prefix: example.csv
|
4
|
+
parser:
|
5
|
+
type: csv
|
6
|
+
skip_header_lines: 1
|
7
|
+
columns:
|
8
|
+
- {name: key_name, type: string}
|
9
|
+
- {name: day, type: timestamp, format: '%Y-%m-%d'}
|
10
|
+
- {name: new_clients, type: long}
|
11
|
+
- {name: name, type: string}
|
12
|
+
|
13
|
+
out:
|
14
|
+
type: influxdb
|
15
|
+
username: root
|
16
|
+
password: root
|
17
|
+
database: dbname
|
18
|
+
series: ${key_name}_series
|
19
|
+
# series_per_column: true
|
20
|
+
tag_columns: [name]
|
21
|
+
timestamp_column: day
|
22
|
+
mode: replace
|
23
|
+
ignore_columns:
|
24
|
+
- key_name
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'influxdb'
|
2
|
+
require 'timezone'
|
3
|
+
|
4
|
+
module Embulk
|
5
|
+
module Output
|
6
|
+
|
7
|
+
class Influxdb08 < OutputPlugin
|
8
|
+
Plugin.register_output("influxdb08", self)
|
9
|
+
|
10
|
+
def self.transaction(config, schema, count, &control)
|
11
|
+
# configuration code:
|
12
|
+
task = {
|
13
|
+
"host" => config.param("host", :string, default: nil),
|
14
|
+
"hosts" => config.param("hosts", :array, default: nil),
|
15
|
+
"port" => config.param("port", :integer, default: 8086),
|
16
|
+
"username" => config.param("username", :string, default: "root"),
|
17
|
+
"password" => config.param("password", :string, default: "root"),
|
18
|
+
"database" => config.param("database", :string),
|
19
|
+
"series" => config.param("series", :string, default: nil),
|
20
|
+
"series_per_column" => config.param("series_per_column", :bool, default: false),
|
21
|
+
"timestamp_column" => config.param("timestamp_column", :string, default: nil),
|
22
|
+
"ignore_columns" => config.param("ignore_columns", :array, default: []),
|
23
|
+
"default_timezone" => config.param("default_timezone", :string, default: "UTC"),
|
24
|
+
"mode" => config.param("mode", :string, default: "insert"),
|
25
|
+
"use_ssl" => config.param("use_ssl", :bool, default: false),
|
26
|
+
"verify_ssl" => config.param("verify_ssl", :bool, default: true),
|
27
|
+
"ssl_ca_cert" => config.param("ssl_ca_cert", :string, default: nil),
|
28
|
+
"time_precision" => config.param("time_precision", :string, default: "s"),
|
29
|
+
"initial_delay" => config.param("initial_delay", :float, default: 0.01),
|
30
|
+
"max_delay" => config.param("max_delay", :float, default: 30),
|
31
|
+
"open_timeout" => config.param("open_timeout", :integer, default: 5),
|
32
|
+
"read_timeout" => config.param("read_timeout", :integer, default: 300),
|
33
|
+
"async" => config.param("async", :bool, default: false),
|
34
|
+
"udp" => config.param("udp", :bool, default: false),
|
35
|
+
"retry" => config.param("retry", :integer, default: nil),
|
36
|
+
"denormalize" => config.param("denormalize", :bool, default: true),
|
37
|
+
}
|
38
|
+
|
39
|
+
# resumable output:
|
40
|
+
# resume(task, schema, count, &control)
|
41
|
+
|
42
|
+
# non-resumable output:
|
43
|
+
task_reports = yield(task)
|
44
|
+
next_config_diff = {}
|
45
|
+
return next_config_diff
|
46
|
+
end
|
47
|
+
|
48
|
+
#def self.resume(task, schema, count, &control)
|
49
|
+
# task_reports = yield(task)
|
50
|
+
#
|
51
|
+
# next_config_diff = {}
|
52
|
+
# return next_config_diff
|
53
|
+
#end
|
54
|
+
|
55
|
+
def self.replaced_series
|
56
|
+
@replaced_series ||= {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def init
|
60
|
+
# initialization code:
|
61
|
+
task["hosts"] ||= Array(task["host"] || "localhost")
|
62
|
+
@database = task["database"]
|
63
|
+
@series = task["series"]
|
64
|
+
@series_per_column = task["series_per_column"]
|
65
|
+
unless @series
|
66
|
+
raise "Need series or series_per_column parameter" unless @series_per_column
|
67
|
+
end
|
68
|
+
if task["timestamp_column"]
|
69
|
+
@timestamp_column = schema.find { |col| col.name == task["timestamp_column"] }
|
70
|
+
end
|
71
|
+
@ignore_columns = task["ignore_columns"]
|
72
|
+
@time_precision = task["time_precision"]
|
73
|
+
@replace = task["mode"].downcase == "replace"
|
74
|
+
@default_timezone = task["default_timezone"]
|
75
|
+
|
76
|
+
@connection = InfluxDB::Client.new(@database,
|
77
|
+
task.map { |k, v| [k.to_sym, v] }.to_h
|
78
|
+
)
|
79
|
+
create_database_if_not_exist
|
80
|
+
end
|
81
|
+
|
82
|
+
def close
|
83
|
+
end
|
84
|
+
|
85
|
+
def add(page)
|
86
|
+
data = @series ? build_payload(page) : build_payload_per_column(page)
|
87
|
+
|
88
|
+
Embulk.logger.info { "embulk-output-influxdb08: Writing to #{@database}" }
|
89
|
+
Embulk.logger.debug { "embulk-output-influxdb08: #{data}" }
|
90
|
+
|
91
|
+
@connection.write_points(data, @async, @time_precision)
|
92
|
+
end
|
93
|
+
|
94
|
+
def finish
|
95
|
+
end
|
96
|
+
|
97
|
+
def abort
|
98
|
+
end
|
99
|
+
|
100
|
+
def commit
|
101
|
+
task_report = {}
|
102
|
+
return task_report
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def build_payload(page)
|
108
|
+
data = page.map do |record|
|
109
|
+
series = resolve_placeholder(record, @series)
|
110
|
+
delete_series_if_exist(series)
|
111
|
+
payload = {
|
112
|
+
name: series,
|
113
|
+
data: Hash[
|
114
|
+
target_columns.map { |col| [col.name, convert_timezone(record[col.index])] }
|
115
|
+
],
|
116
|
+
}
|
117
|
+
payload[:data][:time] = convert_timezone(record[@timestamp_column.index]).to_i if @timestamp_column
|
118
|
+
payload
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def build_payload_per_column(page)
|
123
|
+
page.flat_map do |record|
|
124
|
+
target_columns.map do |col|
|
125
|
+
series = col.name
|
126
|
+
delete_series_if_exist(series)
|
127
|
+
payload = {
|
128
|
+
name: series,
|
129
|
+
data: {value: record[col.index]},
|
130
|
+
}
|
131
|
+
payload[:data][:time] = convert_timezone(record[@timestamp_column.index]).to_i if @timestamp_column
|
132
|
+
payload
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def delete_series_if_exist(series)
|
138
|
+
if @replace && self.class.replaced_series[series].nil? && find_series(series)
|
139
|
+
Embulk.logger.info { "embulk-output-influxdb08: Delete series #{series} from #{@database}" }
|
140
|
+
self.class.replaced_series[series] = true
|
141
|
+
@connection.delete_series(series)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def find_series(series)
|
146
|
+
@connection.query('LIST SERIES')["list_series_result"].find { |v|
|
147
|
+
v["name"] == series
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
def create_database_if_not_exist
|
152
|
+
unless @connection.get_database_list.any? { |db| db["name"] == @database }
|
153
|
+
@connection.create_database(@database)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def resolve_placeholder(record, series)
|
158
|
+
series.gsub(/\$\{(.*?)\}/) do |name|
|
159
|
+
index = schema.index { |col| col.name == $1 }
|
160
|
+
record[index]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def target_columns
|
165
|
+
schema.reject do |col|
|
166
|
+
col.name == @timestamp_column.name || @ignore_columns.include?(col.name)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def convert_timezone(value)
|
171
|
+
return value unless value.is_a?(Time)
|
172
|
+
|
173
|
+
timezone = Timezone::Zone.new(zone: @default_timezone)
|
174
|
+
timezone.time(value)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-output-influxdb08
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- atsaki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 0.7.4
|
19
|
+
name: embulk
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.0'
|
33
|
+
name: bundler
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
name: rake
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
name: tapp
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.1.9
|
75
|
+
name: influxdb
|
76
|
+
prerelease: false
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.9
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
name: timezone
|
90
|
+
prerelease: false
|
91
|
+
type: :runtime
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Dumps records to InfluxDB v0.8.
|
98
|
+
email:
|
99
|
+
- atsaki01@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".ruby-version"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- embulk-output-influxdb08.gemspec
|
111
|
+
- example.csv
|
112
|
+
- example.yml
|
113
|
+
- lib/embulk/output/influxdb08.rb
|
114
|
+
homepage: https://github.com/atsaki/embulk-output-influxdb08.git
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.8
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: InfluxDB v0.8 output plugin for Embulk
|
138
|
+
test_files: []
|