api-harvester 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5b682cb063b69e48cbfeede8e43532baa68e215
4
- data.tar.gz: 0ce1ac7b04883ced29df0f87ab33120082de583b
3
+ metadata.gz: dc8ef7a9dc5793b2fd06186d813b03a2d59823e4
4
+ data.tar.gz: 74a6f1fedc4980a92e5c21c05321b76c75a70e2d
5
5
  SHA512:
6
- metadata.gz: 6152657838bec26fe2dba1282f18084ef881da2979e32df86c7961f456687cc0982b53c653a8af30e7128908f557302005f02f5932b0c26867f5a888c2bcda2b
7
- data.tar.gz: 6ac7666c38611eb685c2ad10d6055020f1b61f2779e55a4af3d40f1a2a9537c5845d310f246d73c7466e1d2eb79d90697f84b711a3f7d321c1a4b76e756b5630
6
+ metadata.gz: 7fb3e490ca07a6f5aa8183b9a0e33ee8b3248c0b3377ff064a60a603552b56c2a0fb61a293db1d4de9b3bf0bb5235e0b483abac5a8287fad4fd9cd92ed3aa4d4
7
+ data.tar.gz: 06d77bd4b468a0f7a12fdb8d1b3a8c144d084075aaf2a02bb90ec6581989237ce39e337874aeb0c6d49c9f3cce5a0223604b817156c100bc5fd4080b80a0c39b
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+ vendor
15
+ # jeweler generated
16
+ pkg
17
+
18
+ harvester.yaml
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ .DS_Store
33
+
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+
38
+ # For emacs:
39
+ #*~
40
+ #\#*
41
+ #.\#*
42
+
43
+ # For vim:
44
+ #*.swp
45
+
46
+ # For redcar:
47
+ #.redcar
48
+
49
+ # For rubinius:
50
+ #*.rbc
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source 'http://rubygems.org'
2
+ group :development do
3
+ gem "shoulda", ">= 0"
4
+ gem "rdoc", "~> 3.12"
5
+ gem "bundler", "~> 1.0"
6
+ gem "jeweler", "~> 2.0.1"
7
+ gem "simplecov", ">= 0"
8
+ gem 'pry'
9
+ gem 'pry-nav'
10
+ end
11
+
12
+
13
+ gem 'faraday'
14
+ gem 'excon'
15
+ gem 'commander'
16
+ gem 'ezmq'
17
+ gem 'msgpack'
18
+
19
+
20
+ gem 'influxdb', '~> 0.1.9'
21
+ gem 'eye'
22
+ gem 'moneta'
23
+ gem 'sinatra'
24
+ gem 'rainbow'
25
+ gem 'oj'
26
+
27
+ gem 'terminal-announce'
28
+ gem 'settingslogic'
data/Gemfile.lock ADDED
@@ -0,0 +1,154 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.3)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.8)
11
+ builder (3.2.2)
12
+ cause (0.1)
13
+ celluloid (0.15.2)
14
+ timers (~> 1.1.0)
15
+ celluloid-io (0.15.0)
16
+ celluloid (>= 0.15.0)
17
+ nio4r (>= 0.5.0)
18
+ coderay (1.1.0)
19
+ commander (4.3.4)
20
+ highline (~> 1.7.2)
21
+ contracts (0.11.0)
22
+ descendants_tracker (0.0.4)
23
+ thread_safe (~> 0.3, >= 0.3.1)
24
+ docile (1.1.5)
25
+ excon (0.45.4)
26
+ eye (0.6.4)
27
+ celluloid (~> 0.15.0)
28
+ celluloid-io (~> 0.15.0)
29
+ sigar (~> 0.7.2)
30
+ state_machine
31
+ thor
32
+ ezmq (0.4.4)
33
+ ffi-rzmq (~> 2.0)
34
+ faraday (0.9.1)
35
+ multipart-post (>= 1.2, < 3)
36
+ ffi (1.9.10)
37
+ ffi-rzmq (2.0.4)
38
+ ffi-rzmq-core (>= 1.0.1)
39
+ ffi-rzmq-core (1.0.3)
40
+ ffi (~> 1.9)
41
+ git (1.2.9.1)
42
+ github_api (0.12.4)
43
+ addressable (~> 2.3)
44
+ descendants_tracker (~> 0.0.4)
45
+ faraday (~> 0.8, < 0.10)
46
+ hashie (>= 3.4)
47
+ multi_json (>= 1.7.5, < 2.0)
48
+ nokogiri (~> 1.6.6)
49
+ oauth2
50
+ hashie (3.4.2)
51
+ highline (1.7.2)
52
+ i18n (0.7.0)
53
+ influxdb (0.1.9)
54
+ cause
55
+ json
56
+ jeweler (2.0.1)
57
+ builder
58
+ bundler (>= 1.0)
59
+ git (>= 1.2.5)
60
+ github_api
61
+ highline (>= 1.6.15)
62
+ nokogiri (>= 1.5.10)
63
+ rake
64
+ rdoc
65
+ json (1.8.3)
66
+ jwt (1.5.1)
67
+ method_source (0.8.2)
68
+ mini_portile (0.6.2)
69
+ minitest (5.8.0)
70
+ moneta (0.8.0)
71
+ msgpack (0.6.2)
72
+ multi_json (1.11.2)
73
+ multi_xml (0.5.5)
74
+ multipart-post (2.0.0)
75
+ nio4r (1.1.1)
76
+ nokogiri (1.6.6.2)
77
+ mini_portile (~> 0.6.0)
78
+ oauth2 (1.0.0)
79
+ faraday (>= 0.8, < 0.10)
80
+ jwt (~> 1.0)
81
+ multi_json (~> 1.3)
82
+ multi_xml (~> 0.5)
83
+ rack (~> 1.2)
84
+ oj (2.12.10)
85
+ pry (0.10.1)
86
+ coderay (~> 1.1.0)
87
+ method_source (~> 0.8.1)
88
+ slop (~> 3.4)
89
+ pry-nav (0.2.4)
90
+ pry (>= 0.9.10, < 0.11.0)
91
+ rack (1.6.4)
92
+ rack-protection (1.5.3)
93
+ rack
94
+ rainbow (2.0.0)
95
+ rake (10.4.2)
96
+ rdoc (3.12.2)
97
+ json (~> 1.4)
98
+ settingslogic (2.0.9)
99
+ shoulda (3.5.0)
100
+ shoulda-context (~> 1.0, >= 1.0.1)
101
+ shoulda-matchers (>= 1.4.1, < 3.0)
102
+ shoulda-context (1.2.1)
103
+ shoulda-matchers (2.8.0)
104
+ activesupport (>= 3.0.0)
105
+ sigar (0.7.3)
106
+ simplecov (0.10.0)
107
+ docile (~> 1.1.0)
108
+ json (~> 1.8)
109
+ simplecov-html (~> 0.10.0)
110
+ simplecov-html (0.10.0)
111
+ sinatra (1.4.6)
112
+ rack (~> 1.4)
113
+ rack-protection (~> 1.4)
114
+ tilt (>= 1.3, < 3)
115
+ slop (3.6.0)
116
+ state_machine (1.2.0)
117
+ terminal-announce (1.0.0)
118
+ bundler
119
+ contracts
120
+ rainbow
121
+ thor (0.19.1)
122
+ thread_safe (0.3.5)
123
+ tilt (2.0.1)
124
+ timers (1.1.0)
125
+ tzinfo (1.2.2)
126
+ thread_safe (~> 0.1)
127
+
128
+ PLATFORMS
129
+ ruby
130
+
131
+ DEPENDENCIES
132
+ bundler (~> 1.0)
133
+ commander
134
+ excon
135
+ eye
136
+ ezmq
137
+ faraday
138
+ influxdb (~> 0.1.9)
139
+ jeweler (~> 2.0.1)
140
+ moneta
141
+ msgpack
142
+ oj
143
+ pry
144
+ pry-nav
145
+ rainbow
146
+ rdoc (~> 3.12)
147
+ settingslogic
148
+ shoulda
149
+ simplecov
150
+ sinatra
151
+ terminal-announce
152
+
153
+ BUNDLED WITH
154
+ 1.10.4
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ harvest key_transactions --from https://api.newrelic.com/v2/key_transactions.json --every 5s
2
+ harvester harvest key_transactions --from https://api.newrelic.com/v2/key_transactions.json --every 5
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "harvester"
18
+ gem.homepage = "http://github.com/kkwoker/harvester"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{TODO: one-line summary of your gem}
21
+ gem.description = %Q{TODO: longer description of your gem}
22
+ gem.email = "kkwoker@gmail.com"
23
+ gem.authors = ["kkwoker"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "harvester #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/bin/harvester ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander'
4
+ require_relative '../lib/harvester'
5
+
6
+ Commander.configure do
7
+ program :name, 'Harvester'
8
+ program :version, '0.0.1'
9
+ program :description, 'harvest from endpoints'
10
+ program :help, 'Author', 'Kinnan Kwok <kkwoker@gmail.com>'
11
+
12
+ default_command :harvest
13
+
14
+ command :harvest do |command|
15
+ command.syntax = 'harvester harvest [options]'
16
+ command.summary = ''
17
+ command.description = 'Starts processes for harvesting data'
18
+ command.example 'description', 'command example'
19
+ command.option '--from STRING', String, 'Adds an endpoint to harvest from'
20
+ command.option '--with STRING', String, 'Adds a parsing method ruby file'
21
+ command.option '--every INTEGER', Integer, 'Adds an interval for polling'
22
+ command.action do |_args, options|
23
+ # Do something or c.when_called Harvester::Commands::Harvest
24
+ abort 'Must provide parameters --from, --with, and --every' unless options.from && options.with && options.every
25
+ name = options.with
26
+ endpoint = options.from
27
+ timeout = options.every
28
+
29
+ # Create an eye file.
30
+ EyeGenerator.initialize name, endpoint, timeout
31
+ # Load Eye file
32
+ system "eye load #{name}.d/config.eye"
33
+ system "eye restart #{name}"
34
+
35
+ end
36
+ end
37
+ end
data/harvester.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'api-harvester'
3
+ gem.version = '0.0.2'
4
+ gem.licenses = 'MIT'
5
+ gem.authors = ['Kinnan Kwok']
6
+ gem.email = 'kkwoker@gmail.com'
7
+ gem.summary = 'Allows you to specify an endpoint to retrieve data from, parse it, and store into any database'
8
+ gem.require_paths = ["lib"]
9
+ # gem.executables = ["harvester"]
10
+ # gem.files = [
11
+ # ".document",
12
+ # ".gitignore",
13
+ # "Gemfile",
14
+ # "Gemfile.lock",
15
+ # "README.md",
16
+ # "Rakefile",
17
+ # "bin/harvester",
18
+ # "harvester.gemspec",
19
+ # "lib/harvester.rb",
20
+ # "lib/harvester/eye_generator.rb"
21
+ # "lib/harvester/parser.rb"
22
+ # "lib/harvester/pusher.rb"
23
+ # "lib/harvester/puller.rb"
24
+ # "lib/harvester/settings.rb"
25
+ # ]
26
+
27
+ gem.homepage = "http://github.com/kkwoker/api-harvester"
28
+ gem.add_runtime_dependency 'ezmq', '~> 0.4.4'
29
+ gem.add_runtime_dependency 'faraday'
30
+ gem.add_runtime_dependency 'excon'
31
+ gem.add_runtime_dependency 'commander'
32
+ gem.add_runtime_dependency 'msgpack'
33
+ gem.add_runtime_dependency 'influxdb', '~> 0.1.9'
34
+ gem.add_runtime_dependency 'eye'
35
+ gem.add_runtime_dependency 'moneta'
36
+ gem.add_runtime_dependency 'sinatra'
37
+ gem.add_runtime_dependency 'rainbow'
38
+ gem.add_runtime_dependency 'oj'
39
+ gem.add_runtime_dependency 'terminal-announce'
40
+ gem.add_runtime_dependency 'settingslogic'
41
+
42
+ gem.add_development_dependency 'pry'
43
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../template/default_eye'
2
+
3
+ module EyeGenerator
4
+ def self.create_eye_config name
5
+ config = Default.eye_config name
6
+ File.open("#{name}.d/config.eye", 'w') { |file| file.write(config)}
7
+ end
8
+
9
+ def self.create_puller name, endpoint, timeout
10
+ puller = Default.puller name, endpoint, timeout
11
+ File.open("#{name}.d/puller.rb", 'w') { |file| file.write(puller)}
12
+ end
13
+
14
+ def self.create_parser name, endpoint
15
+ parser = Default.parser name, endpoint
16
+ File.open("#{name}.d/parser.rb", 'w') { |file| file.write(parser)}
17
+ end
18
+
19
+ def self.create_pusher name, endpoint
20
+ pusher = Default.pusher name, endpoint
21
+ File.open("#{name}.d/pusher.rb", 'w') { |file| file.write(pusher)}
22
+ end
23
+
24
+ def self.initialize name, endpoint, timeout
25
+ system "mkdir -p #{name}.d"
26
+ system "mkdir -p #{name}.d/logs"
27
+ system "mkdir -p #{name}.d/pids"
28
+ create_eye_config name
29
+ create_puller name, endpoint, timeout
30
+ create_parser name, endpoint
31
+ create_pusher name, endpoint
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ require 'pry'
2
+ require 'ezmq'
3
+ require 'msgpack'
4
+ require 'oj'
5
+ require_relative 'settings'
6
+ require_relative '../../key_transactions'
7
+ module Parser
8
+ @broadcaster = EZMQ::Publisher.new :bind, port: 6000, encode: -> m { Oj.dump m }
9
+ def self.activate topic, endpoint
10
+ puts topic, endpoint
11
+ listener = EZMQ::Subscriber.new :connect, port: 5000, topic: topic, decode: -> m { Oj.load m }
12
+ listener.listen do |message, topic|
13
+ data = plow message, topic
14
+ data.each do |item|
15
+ puts @broadcaster.send item, topic: topic
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.plow message, parse
21
+ send(parse, message)
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'ezmq'
2
+ require 'msgpack'
3
+ require 'faraday'
4
+ require 'oj'
5
+ require 'excon'
6
+ require_relative 'settings'
7
+
8
+ module Puller
9
+ @broadcaster = EZMQ::Publisher.new :bind, port: 5000
10
+ def self.fetch_data(endpoint)
11
+ conn = Faraday.new(url: endpoint) do |faraday|
12
+ faraday.adapter :excon
13
+ faraday.headers['X-Api-Key'] = Settings.newrelic_key
14
+ end
15
+ conn.get.body
16
+ # rescue Exception => e
17
+ # puts "Puller#fetch_data"
18
+ # puts "#{e.inspect}: #{e.message}"
19
+ end
20
+
21
+ def self.send(data, topic)
22
+ # puts "Puller#send"
23
+ @broadcaster.send data, topic: topic
24
+ end
25
+
26
+ def self.activate(name, endpoint, timeout)
27
+ loop do
28
+ puts send fetch_data(endpoint), name
29
+ sleep timeout
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require 'pry'
2
+ require 'ezmq'
3
+ require 'oj'
4
+ require 'influxdb'
5
+ require_relative 'settings'
6
+
7
+ module Pusher
8
+ @connection = InfluxDB::Client.new host: Settings.influx_host, username: Settings.influx_user, password: Settings.influx_pass
9
+
10
+ def self.activate topic, endpoint
11
+ listener = EZMQ::Subscriber.new :connect, port: 6000, topic: topic, decode: -> m { Oj.load m }
12
+ listener.listen do |message, topic|
13
+ puts write message
14
+ end
15
+ end
16
+
17
+ def self.write data
18
+ series = data.delete :series_name
19
+ db = data.delete :database_name
20
+ use_or_create db
21
+ @connection.write_point(series, data)
22
+ data.length
23
+ end
24
+
25
+ def self.use_or_create(db_name)
26
+ dbs = @connection.get_database_list.map { |db| db["name"] }
27
+ @connection.create_database db_name unless dbs.include? db_name
28
+ @connection = InfluxDB::Client.new db_name, host: Settings.influx_host,
29
+ username: Settings.influx_user,
30
+ password: Settings.influx_pass
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ require 'settingslogic'
2
+ require 'terminal-announce'
3
+ class Settings < Settingslogic
4
+ config_paths = %w(/etc /usr/local/etc ~/.config . ../)
5
+
6
+ config_paths.each do |config_path|
7
+ config_file = File.expand_path "#{ config_path }/harvester.yaml"
8
+ source config_file if File.exist? config_file
9
+ end
10
+
11
+ load!
12
+ rescue Errno::ENOENT
13
+ Announce.failure "Unable to locate configuration in #{ config_paths }."
14
+ abort
15
+ end
data/lib/harvester.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative 'harvester/puller'
2
+ require_relative 'harvester/parser'
3
+ require_relative 'harvester/pusher'
4
+ require_relative 'harvester/eye_generator'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-harvester
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinnan Kwok
@@ -208,10 +208,25 @@ dependencies:
208
208
  version: '0'
209
209
  description:
210
210
  email: kkwoker@gmail.com
211
- executables: []
211
+ executables:
212
+ - harvester
212
213
  extensions: []
213
214
  extra_rdoc_files: []
214
- files: []
215
+ files:
216
+ - ".document"
217
+ - ".gitignore"
218
+ - Gemfile
219
+ - Gemfile.lock
220
+ - README.md
221
+ - Rakefile
222
+ - bin/harvester
223
+ - harvester.gemspec
224
+ - lib/harvester.rb
225
+ - lib/harvester/eye_generator.rb
226
+ - lib/harvester/parser.rb
227
+ - lib/harvester/puller.rb
228
+ - lib/harvester/pusher.rb
229
+ - lib/harvester/settings.rb
215
230
  homepage: http://github.com/kkwoker/api-harvester
216
231
  licenses:
217
232
  - MIT