latias-influxdb 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +18 -0
- data/app/assets/config/latias_influxdb_manifest.js +1 -0
- data/app/assets/stylesheets/latias/influxdb/application.css +15 -0
- data/app/controllers/latias/influxdb/application_controller.rb +6 -0
- data/app/helpers/latias/influxdb/application_helper.rb +6 -0
- data/app/jobs/latias/influxdb/application_job.rb +6 -0
- data/app/mailers/latias/influxdb/application_mailer.rb +8 -0
- data/app/models/latias/influxdb/application_record.rb +7 -0
- data/app/views/layouts/latias/influxdb/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/lib/latias/influxdb.rb +12 -0
- data/lib/latias/influxdb/bucket.rb +81 -0
- data/lib/latias/influxdb/configuration.rb +28 -0
- data/lib/latias/influxdb/engine.rb +10 -0
- data/lib/latias/influxdb/version.rb +7 -0
- data/lib/tasks/latias/influxdb_tasks.rake +4 -0
- metadata +77 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5cdc7761baa96c1098ef82d6b6cdb57f063a6a058cb60d71a7798a22ddab7a09
|
|
4
|
+
data.tar.gz: 461ff0a30fc85dd7ed746f563af10f526d1ec9a0117f1f0b3606df873125ed8b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8c5b545748dc93ec56a5773f11a319bd7ea592477cfa04cf793526eb1c38609a1c122918b0f75adb3981ffc7eed227828716cd6cdad41a7378a05ad0837c6bc3
|
|
7
|
+
data.tar.gz: 2248f45726402f2ed31f7df186ad61ac79c70ddf015d19b1527b47761b745b19990d48b93c81e06006b845a3c99ba5429c9094f9ef2f2a3e4ac6221d9757cc94
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2021 nattanon
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Latias::Influxdb
|
|
2
|
+
|
|
3
|
+
Ruby lib for use influxdb version 2 on Ruby language
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
|
9
|
+
def initialize
|
|
10
|
+
@url = 'http://localhost:8086'
|
|
11
|
+
@token = 'your token'
|
|
12
|
+
@bucket = 'MDBEnergy'
|
|
13
|
+
@org = 'MDBEnergy'
|
|
14
|
+
@use_ssl = false
|
|
15
|
+
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
16
|
+
@precision = InfluxDB2::WritePrecision::NANOSECOND
|
|
17
|
+
@client = client
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
mdb_energy_bucket = MdbEnergyBucket.new
|
|
22
|
+
mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
|
|
23
|
+
mdb_energy_bucket.call
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Add this line to your application's Gemfile:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
gem 'latias-influxdb'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
And then execute:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
$ bundle
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Or install it yourself as:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
$ gem install latias-influxdb
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Contributing
|
|
47
|
+
|
|
48
|
+
Contribution directions go here.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
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,18 @@
|
|
|
1
|
+
require "bundler/setup"
|
|
2
|
+
|
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
|
4
|
+
load "rails/tasks/engine.rake"
|
|
5
|
+
|
|
6
|
+
load "rails/tasks/statistics.rake"
|
|
7
|
+
|
|
8
|
+
require "bundler/gem_tasks"
|
|
9
|
+
|
|
10
|
+
require "rake/testtask"
|
|
11
|
+
|
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
|
13
|
+
t.libs << 'test'
|
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
|
15
|
+
t.verbose = false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
task default: :test
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//= link_directory ../stylesheets/latias/influxdb .css
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
|
11
|
+
* It is generally better to create a new file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Latias influxdb</title>
|
|
5
|
+
<%= csrf_meta_tags %>
|
|
6
|
+
<%= csp_meta_tag %>
|
|
7
|
+
|
|
8
|
+
<%= stylesheet_link_tag "latias/influxdb/application", media: "all" %>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
|
|
12
|
+
<%= yield %>
|
|
13
|
+
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'influxdb-client'
|
|
4
|
+
|
|
5
|
+
module Latias
|
|
6
|
+
# Influxdb
|
|
7
|
+
module Influxdb
|
|
8
|
+
# Bucket
|
|
9
|
+
class Bucket
|
|
10
|
+
attr_reader :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@query = ''
|
|
14
|
+
@url = 'http://localhost:8086'
|
|
15
|
+
@token = 'token'
|
|
16
|
+
@bucket = 'bucket'
|
|
17
|
+
@org = 'org'
|
|
18
|
+
@use_ssl = false
|
|
19
|
+
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def call
|
|
23
|
+
all_query = "from(bucket: \"#{@bucket}\") #{@query}"
|
|
24
|
+
@query = ''
|
|
25
|
+
@client.create_query_api.query(query: all_query, org: @org)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# old code
|
|
29
|
+
# def call
|
|
30
|
+
# all_query = "from(bucket: \"#{@bucket}\")" \
|
|
31
|
+
# '|> range(start: -1m)
|
|
32
|
+
# |> filter(fn: (r) => r["_measurement"] == "cpu")
|
|
33
|
+
# |> filter(fn: (r) => r["_field"] == "usage_user")
|
|
34
|
+
# |> filter(fn: (r) => r["cpu"] == "cpu-total" or r["cpu"] == "cpu0" or r["cpu"] == "cpu1")
|
|
35
|
+
# |> yield(name: "sum")'
|
|
36
|
+
|
|
37
|
+
# @client.create_query_api.query(query: all_query, org: @org)
|
|
38
|
+
# end
|
|
39
|
+
|
|
40
|
+
def yield(query)
|
|
41
|
+
@query += yield_format(query)
|
|
42
|
+
self
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def range(query)
|
|
46
|
+
@query += range_format(query)
|
|
47
|
+
self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def filter(query)
|
|
51
|
+
@query += filter_format(query)
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def yield_format(query)
|
|
58
|
+
"#{new_command} yield(#{query})"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def range_format(query)
|
|
62
|
+
"#{new_command} range(#{query})"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def filter_format(query)
|
|
66
|
+
"#{new_command} filter(#{query})"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def new_command
|
|
70
|
+
'|> '
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def client
|
|
74
|
+
@client = InfluxDB2::Client.new(@url, @token,
|
|
75
|
+
use_ssl: @use_ssl,
|
|
76
|
+
verify_mode: @verify_mode.present? ? @verify_mode : OpenSSL::SSL::VERIFY_NONE,
|
|
77
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latias
|
|
4
|
+
# Influxdb
|
|
5
|
+
module Influxdb
|
|
6
|
+
# Configuration
|
|
7
|
+
class Configuration
|
|
8
|
+
attr_accessor :async
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@async = true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Borrow syntax from Clearance: https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
|
|
16
|
+
def self.configuration
|
|
17
|
+
@configuration ||= Configuration.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.configuration=(config)
|
|
21
|
+
@configuration = config
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.configure
|
|
25
|
+
yield configuration
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: latias-influxdb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- nattanon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 6.1.4
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 6.1.4
|
|
27
|
+
description:
|
|
28
|
+
email:
|
|
29
|
+
- nattanon@hospital-os.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- MIT-LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- Rakefile
|
|
37
|
+
- app/assets/config/latias_influxdb_manifest.js
|
|
38
|
+
- app/assets/stylesheets/latias/influxdb/application.css
|
|
39
|
+
- app/controllers/latias/influxdb/application_controller.rb
|
|
40
|
+
- app/helpers/latias/influxdb/application_helper.rb
|
|
41
|
+
- app/jobs/latias/influxdb/application_job.rb
|
|
42
|
+
- app/mailers/latias/influxdb/application_mailer.rb
|
|
43
|
+
- app/models/latias/influxdb/application_record.rb
|
|
44
|
+
- app/views/layouts/latias/influxdb/application.html.erb
|
|
45
|
+
- config/routes.rb
|
|
46
|
+
- lib/latias/influxdb.rb
|
|
47
|
+
- lib/latias/influxdb/bucket.rb
|
|
48
|
+
- lib/latias/influxdb/configuration.rb
|
|
49
|
+
- lib/latias/influxdb/engine.rb
|
|
50
|
+
- lib/latias/influxdb/version.rb
|
|
51
|
+
- lib/tasks/latias/influxdb_tasks.rake
|
|
52
|
+
homepage: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
|
|
53
|
+
licenses:
|
|
54
|
+
- MIT
|
|
55
|
+
metadata:
|
|
56
|
+
homepage_uri: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
|
|
57
|
+
source_code_uri: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubygems_version: 3.2.6
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: Ruby library for InfluxDB 2. to use in rails.
|
|
77
|
+
test_files: []
|