embulk-output-influxdb 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c10ec1959bc7881942ba8c3e6a931c2873b224ee
4
- data.tar.gz: b50bbf47ebd9ebd3946337cab7153b219091ecb0
3
+ metadata.gz: 868eadfe20f61efd5c534fcfce549721e3aff05e
4
+ data.tar.gz: 1ea3c8e4828316f494fd727e6487e5e8927faecc
5
5
  SHA512:
6
- metadata.gz: 68fa2e1e642566fae94df91fe29905b43af498894d7749dffff1afc147640f091283430b40eb9d4e0b415e4a952795a68f670e4430b7f01e924c028d266ba2d5
7
- data.tar.gz: 07a4b354f8fecd27a62f2b5445a6f3a09b0f9e6f3f8d86336c62e50821e522b05b80916c01dd66802e00ac74b7fbab9081d1a9d25bf276e73bcf3d9fa7c56926
6
+ metadata.gz: db3d70c5f4f7c123ffcc1fd0c846cd412ea2a5fd04db06945b9ac035fa559afd6d115966eaab601f4bf64f282d966776661ceb5c6ba09a97d03151c13abb3e38
7
+ data.tar.gz: 70b7dc8d8a14558c573d7fda5f63ab5fde14914d119275bd758f97aa494c06674de02441874e9b78b87dfba4bd8049f82bb320d79f3a8116affcacb503ca74ca
data/README.md CHANGED
@@ -19,8 +19,10 @@
19
19
  - **series**: series name (string, required) (can use column value placeholder. see example)
20
20
  - **mode**: "insert", or "replace". See bellow. (string, default: insert)
21
21
  - **timestamp_column**: timestamp column (string, default: nil)
22
- - **ignore_columns**: ignore column names (array[string], default: nil)
22
+ - **ignore_columns**: ignore column names (array[string], default: [])
23
+ - **tag_columns**: tag column names (array[string], default: [])
23
24
  - **default_timezone**: default timezone for column (string, default: 'UTC')
25
+ - **time_precision**: time precision (string, default: 's')
24
26
 
25
27
  ### Modes
26
28
 
@@ -38,6 +40,7 @@ out:
38
40
  password: root
39
41
  database: dbname
40
42
  series: ${key_name}_series
43
+ tag_columns: [name]
41
44
  timestamp_column: day
42
45
  mode: replace
43
46
  ignore_columns:
@@ -45,7 +48,6 @@ out:
45
48
  ```
46
49
 
47
50
  ## ToDo
48
- - tags support
49
51
  - column_options support
50
52
 
51
53
  ## Build
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-output-influxdb"
4
- spec.version = "0.1.1"
4
+ spec.version = "0.2.0"
5
5
  spec.authors = ["joker1007"]
6
6
  spec.summary = "InfluxDB output plugin for Embulk"
7
7
  spec.description = "Dumps records to InfluxDB."
@@ -1,13 +1,13 @@
1
- key_name,day,value
2
- new_clients,2015-08-22,1
3
- new_clients,2015-08-25,2
4
- new_clients,2015-08-26,3
5
- new_clients,2015-08-27,4
6
- new_clients,2015-08-28,10
7
- new_clients,2015-08-29,11
8
- new_clients,2015-09-01,12
9
- new_clients,2015-09-03,13
10
- new_clients,2015-09-05,21
11
- new_clients,2015-09-07,22
12
- new_clients,2015-09-11,23
13
- new_clients,2015-09-12,24
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
@@ -8,14 +8,16 @@ in:
8
8
  - {name: key_name, type: string}
9
9
  - {name: day, type: timestamp, format: '%Y-%m-%d'}
10
10
  - {name: new_clients, type: long}
11
+ - {name: name, type: string}
11
12
 
12
13
  out:
13
14
  type: influxdb
14
15
  username: root
15
16
  password: root
16
17
  database: dbname
17
- # series: ${key_name}_series
18
- series_per_column: true
18
+ series: ${key_name}_series
19
+ # series_per_column: true
20
+ tag_columns: [name]
19
21
  timestamp_column: day
20
22
  mode: replace
21
23
  ignore_columns:
@@ -20,6 +20,7 @@ module Embulk
20
20
  "series_per_column" => config.param("series_per_column", :bool, default: false),
21
21
  "timestamp_column" => config.param("timestamp_column", :string, default: nil),
22
22
  "ignore_columns" => config.param("ignore_columns", :array, default: []),
23
+ "tag_columns" => config.param("tag_columns", :array, default: []),
23
24
  "default_timezone" => config.param("default_timezone", :string, default: "UTC"),
24
25
  "mode" => config.param("mode", :string, default: "insert"),
25
26
  "use_ssl" => config.param("use_ssl", :bool, default: false),
@@ -62,8 +63,10 @@ module Embulk
62
63
  @database = task["database"]
63
64
  @series = task["series"]
64
65
  @series_per_column = task["series_per_column"]
65
- unless @series || @series_per_column
66
- raise "Need series or series_per_column parameter"
66
+ @tag_columns = task["tag_columns"]
67
+ unless @series
68
+ raise "Need series or series_per_column parameter" unless @series_per_column
69
+ raise "Need series parameter when you specify tag_columns" unless @tag_columns.empty?
67
70
  end
68
71
  if task["timestamp_column"]
69
72
  @timestamp_column = schema.find { |col| col.name == task["timestamp_column"] }
@@ -111,10 +114,13 @@ module Embulk
111
114
  payload = {
112
115
  series: series,
113
116
  values: Hash[
114
- target_columns.map { |col| [col.name, convert_timezone(record[col.index])] }
117
+ target_value_columns.map { |col| [col.name, convert_timezone(record[col.index])] }
118
+ ],
119
+ tags: Hash[
120
+ target_tag_columns.map { |col| [col.name, convert_timezone(record[col.index])] }
115
121
  ],
116
122
  }
117
- payload[:timestamp] = convert_timezone(record[@timestamp_column.index]).to_i if @timestamp_column
123
+ payload[:timestamp] = unixtime(convert_timezone(record[@timestamp_column.index])) if @timestamp_column
118
124
  payload
119
125
  end
120
126
  end
@@ -128,7 +134,7 @@ module Embulk
128
134
  series: series,
129
135
  values: {value: record[col.index]},
130
136
  }
131
- payload[:timestamp] = convert_timezone(record[@timestamp_column.index]).to_i if @timestamp_column
137
+ payload[:timestamp] = unixtime(convert_timezone(record[@timestamp_column.index])) if @timestamp_column
132
138
  payload
133
139
  end
134
140
  end
@@ -168,12 +174,32 @@ module Embulk
168
174
  end
169
175
  end
170
176
 
177
+ def target_value_columns
178
+ target_columns.reject do |col|
179
+ @tag_columns.include?(col.name)
180
+ end
181
+ end
182
+
183
+ def target_tag_columns
184
+ target_columns.select do |col|
185
+ @tag_columns.include?(col.name)
186
+ end
187
+ end
188
+
171
189
  def convert_timezone(value)
172
190
  return value unless value.is_a?(Time)
173
191
 
174
192
  timezone = Timezone::Zone.new(zone: @default_timezone)
175
193
  timezone.time(value)
176
194
  end
195
+
196
+ def unixtime(time)
197
+ if @time_precision == 'u'
198
+ format("%d%06d", time.to_i, time.usec).to_i
199
+ else
200
+ time.to_i
201
+ end
202
+ end
177
203
  end
178
204
  end
179
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-15 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: embulk
@@ -136,4 +136,3 @@ signing_key:
136
136
  specification_version: 4
137
137
  summary: InfluxDB output plugin for Embulk
138
138
  test_files: []
139
- has_rdoc: