influx_remix 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 426f529a643038791221812128dc738832d47bbf8e412ac7c59f5702e4c3ed69
4
+ data.tar.gz: 9e7838539c904519f86bb3a81d9825c1155380462126985b37b45b183c8667c2
5
+ SHA512:
6
+ metadata.gz: 8d4cbf494d8a77329c92a1da12f633783c00cb488c3586193b411365a00dec8a03b87a81e62122740e152a3ca073a57deacee60aba81b9e583b8ccd301b9e1a6
7
+ data.tar.gz: 95efaa927d77f101aed461040717226fa0658d97bdd1d85f4195acc3a4623b49e9b07a4d960918ee219dcf8cc5755c8ca8994c44d47319f91b061ea77228092c
data/.gitignore ADDED
@@ -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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.1
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,11 @@
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 influx_remix.gemspec
6
+ gemspec
7
+
8
+ gem 'rspec'
9
+ gem 'faraday'
10
+ gem 'slop'
11
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ influx_remix (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ diff-lcs (1.3)
11
+ faraday (0.17.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ method_source (0.9.2)
14
+ multipart-post (2.1.1)
15
+ pry (0.12.2)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.5.0)
19
+ rspec (3.9.0)
20
+ rspec-core (~> 3.9.0)
21
+ rspec-expectations (~> 3.9.0)
22
+ rspec-mocks (~> 3.9.0)
23
+ rspec-core (3.9.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-expectations (3.9.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-mocks (3.9.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.9.0)
31
+ rspec-support (3.9.0)
32
+ slop (4.7.0)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 1.17)
39
+ faraday
40
+ influx_remix!
41
+ pry
42
+ rake (~> 10.0)
43
+ rspec
44
+ slop
45
+
46
+ BUNDLED WITH
47
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Katy Farmer
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.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # InfluxRemix
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/influx_remix`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'influx_remix'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install influx_remix
22
+
23
+ # What you Need
24
+ You need a text file in line protocol format.
25
+
26
+ Remix is a Ruby gem, so you need Ruby in order to run it. #sorrynotsorry
27
+
28
+ ## How does it work?
29
+
30
+ The first data point in your file will become "now". All other points will be reassigned in relation to now. Two points that are five seconds apart will remain five seconds apart, just at a fresher point in time. Only the timestamp changes--nothing else about your data will be changed.
31
+
32
+ ## Usage
33
+
34
+ $ influx_remix -org "myOrg" -bucket "lilbucket" mylineprotocol.txt
35
+
36
+ $ influx_remix -o "MyOrg" -b "lilbucket" -t "secrettoken" mylineprotocol.txt
37
+
38
+ $ influx_remix -o "MyOrg" -b "lilbucket" -h "http://localhost:9999" -t "secrettoken" mylineprotocol.txt
39
+
40
+
41
+ # Defaults
42
+ The default host is http://localhost:9999
43
+ If you're using InfluxDB Cloud 2.0, simply add the host flag with the url to your instance.
44
+
45
+ The default token is $INFLUX_TOKEN, but you can specify the token with the token flag.
46
+
47
+ # Flags
48
+
49
+ --host, -h: host url of your InfluxDB 2.0 instance
50
+ --org, -o: name of your InfluxDB organization
51
+ --bucket, -b: name of the InfluxDB bucket to write to
52
+ --token, -t: your InfluxDB 2.0 token
53
+
54
+ You can always use the help flag to see the available options.
55
+ $ influx_remix --help
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remix.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "influx_remix"
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__)
data/bin/setup ADDED
@@ -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
data/exe/influx_remix ADDED
@@ -0,0 +1,26 @@
1
+ require 'influx_remix'
2
+ require 'slop'
3
+
4
+ #!/usr/bin/env ruby
5
+ begin
6
+ opts = Slop.parse do |o|
7
+ o.string '-h', '--host', 'a hostname', default: 'http://localhost:9999'
8
+ o.string '-o', '--org', 'an organization', required: true
9
+ o.string '-b', '--bucket', 'a bucket', required: true
10
+ o.string '-t', '--token', 'a token', default: ENV["INFLUX_TOKEN"]
11
+
12
+ o.on '--help' do
13
+ puts o
14
+ exit
15
+ end
16
+ end
17
+ rescue Slop::Error => ex
18
+ puts ex
19
+ exit
20
+ end
21
+
22
+ load = InfluxRemix::Loader.new(ARGV.last)
23
+ load.update_time
24
+
25
+ writer = InfluxRemix::Writer.new(opts[:host], opts[:org], opts[:bucket], opts[:token])
26
+ writer.write(load.blob)
@@ -0,0 +1,43 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "influx_remix/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "influx_remix"
8
+ spec.version = InfluxRemix::VERSION
9
+ spec.authors = ["Katy Farmer"]
10
+ spec.email = ["dreadpiratekaty@gmail.com"]
11
+
12
+ spec.summary = %q{Influx Remix is a command line tool to import historical data into InfluxDB 2.0 with current timestamps.}
13
+ spec.homepage = "https://github.com/TheKaterTot/remix"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/TheKaterTot/remix"
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.17"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "faraday", "~> 0.17.0"
41
+ spec.add_development_dependency "slop", "~> 4.7.0"
42
+
43
+ end
@@ -0,0 +1,7 @@
1
+ require "influx_remix/version"
2
+ require "influx_remix/loader"
3
+ require "influx_remix/writer"
4
+ require "influx_remix/remix"
5
+
6
+ module InfluxRemix
7
+ end
@@ -0,0 +1,36 @@
1
+ require 'time'
2
+
3
+ module InfluxRemix
4
+ class Loader
5
+ def initialize(file)
6
+ @file = file
7
+ @blob = []
8
+ parse
9
+ end
10
+
11
+ def blob
12
+ @blob
13
+ end
14
+
15
+ def update_time
16
+ now = time_nsec
17
+ diff = now.to_i - (blob[0].time).to_i
18
+ @blob.each do |remix|
19
+ remix.update_time((remix.time).to_i + diff)
20
+ end
21
+ end
22
+
23
+ private
24
+ def parse
25
+ File.open(@file).each do |line|
26
+ @blob.push(Remix.new(line))
27
+ end
28
+ end
29
+
30
+ def time_nsec
31
+ now = "%10.9f" % Time.now.to_f
32
+ now.delete!('.')
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,64 @@
1
+ module InfluxRemix
2
+ class Remix
3
+ def initialize(data)
4
+ @data = data
5
+ end
6
+
7
+ def measurement
8
+ elements = @data.split(',')
9
+ if has_measurement?
10
+ return elements.first
11
+ else
12
+ return nil
13
+ end
14
+ end
15
+
16
+ def tags
17
+ elements = @data.split(' ')
18
+ chunk = elements.first.split(',')
19
+ if has_measurement?
20
+ chunk.shift
21
+ end
22
+ transform_data(chunk)
23
+ end
24
+
25
+ def fields
26
+ elements = @data.split(' ')
27
+ chunk = elements[1].split(',')
28
+ transform_data(chunk)
29
+ end
30
+
31
+ def time
32
+ @data.split(' ').last
33
+ end
34
+
35
+ def update_time(time)
36
+ info = @data.split(' ')
37
+ info.pop
38
+ info.push(time.to_s)
39
+ @data = info.join(' ')
40
+ end
41
+
42
+ def line_protocol
43
+ @data
44
+ end
45
+
46
+ private
47
+
48
+ def has_measurement?
49
+ elements = @data.split(',')
50
+ !elements.first.include?('=')
51
+ end
52
+
53
+ def transform_data(chunk)
54
+ chunk.reduce({}) do |memo, val|
55
+ elements = val.split('=')
56
+ if !memo.has_key?(elements[0])
57
+ memo[elements[0]] = []
58
+ end
59
+ memo[elements[0]].push(elements[1])
60
+ memo
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module InfluxRemix
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+
3
+ module InfluxRemix
4
+ class Writer
5
+ def initialize(host, org, bucket, token)
6
+ @url = host
7
+ @org = org
8
+ @bucket = bucket
9
+ @token = token
10
+ end
11
+
12
+ def write(data)
13
+ stringData = data.reduce("") do |blob, line|
14
+ blob + line.line_protocol + "\n"
15
+ end
16
+ conn = Faraday.new(
17
+ url: @url,
18
+ params: {org: @org, bucket: @bucket},
19
+ headers: {"Authorization" => "Token #{@token}"}
20
+ )
21
+ res = conn.post('api/v2/write') do |req|
22
+ req.body = stringData.chomp
23
+ end
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: influx_remix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Katy Farmer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.17.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.17.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: slop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.7.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.7.0
83
+ description:
84
+ email:
85
+ - dreadpiratekaty@gmail.com
86
+ executables:
87
+ - influx_remix
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/influx_remix
102
+ - influx_remix.gemspec
103
+ - lib/influx_remix.rb
104
+ - lib/influx_remix/loader.rb
105
+ - lib/influx_remix/remix.rb
106
+ - lib/influx_remix/version.rb
107
+ - lib/influx_remix/writer.rb
108
+ homepage: https://github.com/TheKaterTot/remix
109
+ licenses:
110
+ - MIT
111
+ metadata:
112
+ allowed_push_host: https://rubygems.org
113
+ homepage_uri: https://github.com/TheKaterTot/remix
114
+ source_code_uri: https://github.com/TheKaterTot/remix
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.0.6
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Influx Remix is a command line tool to import historical data into InfluxDB
134
+ 2.0 with current timestamps.
135
+ test_files: []