fflux 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/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fflux.gemspec +26 -0
- data/lib/fflux.rb +81 -0
- data/lib/fflux/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43540794aa83e3ba9edc3fc83d96767a5ae17d6e
|
4
|
+
data.tar.gz: 711bc2f2ae911d1f26d06331543f9d6057c4beb3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58b686be1afc5742b5333803a96afd9edf4b40f6060db64950663502b207f02077e1cf799d7fd5cc3db8d06d16e0c406e7e8ecc8dded474a3663161928b09040
|
7
|
+
data.tar.gz: 9effc850fc6ab3480a69733310ce59de4efaaac0356ac8bcead83a29e6d8d9181efdb5b0833066e6362b9aaf2a7fe6d4fd064d66160f2f8aced2a406a0fda239
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ville Hellman
|
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,52 @@
|
|
1
|
+
# Fflux
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Fflux is a dead simple and super fast InfluxDB UDP writer
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
**Install the Gem**
|
10
|
+
|
11
|
+
Add to your `Gemfile`
|
12
|
+
|
13
|
+
```
|
14
|
+
gem "fflux"
|
15
|
+
```
|
16
|
+
|
17
|
+
**Configure**
|
18
|
+
|
19
|
+
```
|
20
|
+
Fflux.setup do |config|
|
21
|
+
config.host = '127.0.0.1'
|
22
|
+
config.port = 4444
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
There is a single class method `write` that does everything supported right now
|
29
|
+
|
30
|
+
```
|
31
|
+
# Write a simple measurement
|
32
|
+
|
33
|
+
Fflux.write("cpu", { value: 100 })
|
34
|
+
|
35
|
+
# Write multiple values
|
36
|
+
|
37
|
+
Fflux.write("memory", { free: 100, allocated: 800 })
|
38
|
+
|
39
|
+
# Measurements with values
|
40
|
+
|
41
|
+
Fflux.write("event", { message: "Something happened" }, { environment: "test" })
|
42
|
+
```
|
43
|
+
|
44
|
+
__Do note that this implements the post 0.9.3 Line Protocol so integers are followed by `i`__
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fflux"
|
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
data/fflux.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fflux/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fflux"
|
8
|
+
spec.version = Fflux::VERSION
|
9
|
+
spec.authors = ["Ville Hellman"]
|
10
|
+
spec.email = ["fxn@fxndev.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Dead simple & fast influxDB UDP measurement writer'
|
13
|
+
spec.homepage = "https://github.com/fitzdares/fflux"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
data/lib/fflux.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "fflux/version"
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module Fflux
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
@@port = 4444
|
9
|
+
@@host = '127.0.0.1'
|
10
|
+
|
11
|
+
def write(measurement, values = {}, tags = {})
|
12
|
+
Thread.new do
|
13
|
+
socket = UDPSocket.new
|
14
|
+
socket.send(
|
15
|
+
payload(measurement, values, tags),
|
16
|
+
0,
|
17
|
+
@@host,
|
18
|
+
@@port
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
|
27
|
+
def port=(port)
|
28
|
+
@@port = port
|
29
|
+
end
|
30
|
+
|
31
|
+
def host=(host)
|
32
|
+
@@host = host
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def payload(measurement, values, tags)
|
38
|
+
[
|
39
|
+
key(measurement, tags),
|
40
|
+
fields(values),
|
41
|
+
].compact.join(" ") + "\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def fields(values)
|
45
|
+
format(values, :format_value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_value(value)
|
49
|
+
case value
|
50
|
+
when String
|
51
|
+
"\"#{value}\""
|
52
|
+
when Fixnum
|
53
|
+
"#{value}i"
|
54
|
+
else
|
55
|
+
value.to_s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def key(measurement, tags)
|
60
|
+
[
|
61
|
+
escape(measurement),
|
62
|
+
format(tags)
|
63
|
+
].compact.join(",")
|
64
|
+
end
|
65
|
+
|
66
|
+
def escape(value)
|
67
|
+
value
|
68
|
+
.to_s
|
69
|
+
.gsub(",", "\,")
|
70
|
+
.gsub(" ", "\ ")
|
71
|
+
.gsub(/(.)"(.)/, '\1\"\2')
|
72
|
+
end
|
73
|
+
|
74
|
+
def format(tags, processor = :escape)
|
75
|
+
return unless tags.any?
|
76
|
+
tags.map { |k,v| "#{escape(k)}=#{send(processor, v)}" }.join(",")
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fflux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ville Hellman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-05 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- fxn@fxndev.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- fflux.gemspec
|
72
|
+
- lib/fflux.rb
|
73
|
+
- lib/fflux/version.rb
|
74
|
+
homepage: https://github.com/fitzdares/fflux
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.5.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Dead simple & fast influxDB UDP measurement writer
|
98
|
+
test_files: []
|