psc-opentsdb 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99e084aa8fbe1c70ca5c2b144692ba0e02823e7b
4
+ data.tar.gz: 11d48d113f840f82f84a82f5dbfcb024b10160dc
5
+ SHA512:
6
+ metadata.gz: a416293fb6a1f54bd99103d9123c350462f47b129e631bda6f7ce1c624a5f7b8034ea83662f2caafe397c9558dd7856a5ab6ce7182ab7b41653cc40566cae645
7
+ data.tar.gz: 006163fd4da207789f71bb6f582a3a78ebfbddc8518b20d6ad759de6907e7cbf76faf9433f8919ac5f9d05c72ad188119482924aee30c6172bebdad95755dff6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+ *~
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'httparty' , '~>0.13', '>= 0.13.7'
4
+ # Specify your gem's dependencies in psc-opentsdb.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Rob Light
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,64 @@
1
+ # Psc::Opentsdb
2
+
3
+ Very early gem for interacting with OpenTSDB API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'psc-opentsdb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install psc-opentsdb
20
+
21
+ ## Usage
22
+
23
+ Create server object
24
+ server = OpenTSDB::Server(hostname,port)
25
+
26
+ Get list of metrics (limited to 1000)
27
+ server.suggest('metrics')
28
+
29
+ Specify search string or different limit
30
+ server.suggest('metrics','sys',25)
31
+
32
+ Get list of tagv
33
+ server.suggest('tagv')
34
+
35
+ Get list of tagk
36
+ server.suggest('tagk')
37
+
38
+ Add metric
39
+ server.create_metric('metric_name')
40
+
41
+ Tag class
42
+ newtag = Tag.new(tagname,tagvalue)
43
+
44
+ DataPoint class
45
+ data_point = DataPoint.new(metric,timestamp DateTime,value,tags[])
46
+
47
+ Put data
48
+ server.put(data_points[])
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
54
+ 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).
55
+
56
+ ## Contributing
57
+
58
+ Send bug reports to light@psc.edu
59
+
60
+
61
+ ## License
62
+
63
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
64
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "psc/opentsdb"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,81 @@
1
+ require "psc/opentsdb/version"
2
+ gem 'httparty'
3
+ require 'httparty'
4
+
5
+ module OpenTsdb
6
+ class Server
7
+ include HTTParty
8
+ attr_accessor :port,:server_url
9
+
10
+ def initialize(server_url,port = 4242)
11
+ @server_url = server_url
12
+ @port = port
13
+ self.class.base_uri @server_url + ":" + @port.to_s
14
+ end
15
+
16
+ def suggest(type,query=nil,max=1000)
17
+
18
+ # type must be one of metrics, tagk, tagv
19
+ # query matches entire strings to front of stored data
20
+ # max is max results returned
21
+
22
+ data = Hash.new
23
+ data['type'] = type
24
+ unless query.nil?
25
+ data['q'] = query
26
+ end
27
+ data['max'] = max
28
+ response = self.class.post('/api/suggest',body: data.to_json)
29
+ return response.parsed_response
30
+ end
31
+
32
+ def create_metric(metric)
33
+ data = Hash.new
34
+ data['metric'] = [metric]
35
+ response = self.class.post('/api/uid/assign',body: data.to_json)
36
+
37
+ end
38
+
39
+ def put(data_points)
40
+ # data_points = array of data point objects
41
+ data = Array.new
42
+ data_points.each do |dp|
43
+ data.push(dp.to_hash)
44
+ end
45
+ response = self.class.post('/api/put', body: data.to_json)
46
+ end
47
+ end
48
+
49
+ class DataPoint
50
+ attr_accessor :metric,:timestamp,:value,:tags
51
+ def initialize(metric,timestamp,value,tags)
52
+ @metric = metric
53
+ #DateTime
54
+ @timestamp = timestamp.to_time.to_i
55
+ @value = value
56
+ #Array of Tags
57
+ @tags = tags
58
+ end
59
+
60
+ def to_hash
61
+ h = {}
62
+ h[:metric] = @metric
63
+ h[:timestamp] = @timestamp
64
+ h[:value] = @value
65
+ h[:tags] = {}
66
+ tags.each do |tag|
67
+ h[:tags][tag.tag_name] = tag.tag_value
68
+ end
69
+ h
70
+ end
71
+ end
72
+
73
+ class Tag
74
+ attr_accessor :tag_name,:tag_value
75
+ def initialize(tag_name,tag_value)
76
+ @tag_name = tag_name
77
+ @tag_value = tag_value
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,5 @@
1
+ module Psc
2
+ module Opentsdb
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'psc/opentsdb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "psc-opentsdb"
8
+ spec.version = Psc::Opentsdb::VERSION
9
+ spec.authors = ["Rob Light"]
10
+ spec.email = ["light@psc.edu"]
11
+
12
+ spec.summary = %q{Early Client library interacting with OpenTSDB API.}
13
+ spec.description = %q{Client library interacting with OpenTSDB API.}
14
+ spec.homepage = "http://www.psc.edu"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "https://cutch.psc.edu"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency "httparty", "~> 0.13", ">=0.13.7"
31
+ spec.add_development_dependency "bundler", "~> 1.10"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: psc-opentsdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Light
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.13.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.13'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.13.7
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ description: Client library interacting with OpenTSDB API.
62
+ email:
63
+ - light@psc.edu
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - lib/psc/opentsdb.rb
77
+ - lib/psc/opentsdb/version.rb
78
+ - psc-opentsdb.gemspec
79
+ homepage: http://www.psc.edu
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Early Client library interacting with OpenTSDB API.
103
+ test_files: []