influxparser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/influxparser.rb +56 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 300f243df83f6c65d0f5206e32623be63fe60d3e
4
+ data.tar.gz: 51a7aa6aec089ed64d1b721431ab2dbfdbc3ad06
5
+ SHA512:
6
+ metadata.gz: 6edc1719f7f50394732b52257adacb96fd12445dd94d3124bb58a8bf919d7d179aca26ba2c179e5c71709144eceaa01da61eeea3eb5c60d5693ea06043f8d63c
7
+ data.tar.gz: fe002ca912eb0783ca328786744672eb525096ec503dd509cb00d21ceb777f545bccb2925698b7dc0b4e1ae2cd49ef89ec3bab5b29dbf8a8294d5657cd84e38b
@@ -0,0 +1,56 @@
1
+ class InfluxParser
2
+ class << self
3
+ def parse_point(s)
4
+ point = {}
5
+ point['_raw'] = s
6
+ s = s.strip # trim whitespace
7
+
8
+ parts = s.split(/(?<!\\) /) # split on unescaped spaces for the initial sections
9
+ return false if parts.length < 2 # at bare minimum there needs to be a measurement and some fields
10
+
11
+ mparts = parts[0].split(/(?<!\\),/) # split on unescaped commas for the measurement name and tags
12
+ point['measurement'] = unescape_measurement mparts[0]
13
+
14
+ # if any tags were attached to the measurement iterate over them now
15
+ point['tags'] = {}
16
+ mparts.drop(1).each do |t|
17
+ tag = t.split(/(?<!\\)=/)
18
+ point['tags'][unescape_tag tag[0]] = unescape_tag tag[1]
19
+ end
20
+
21
+ # now iterate over the values
22
+ point['values'] = {}
23
+ vparts = parts[1].split(/(?<!\\),/)
24
+ vparts.each do |v|
25
+ value = v.split(/(?<!\\)=/)
26
+ point['values'][unescape_tag value[0]] = unescape_point value[1]
27
+ end
28
+
29
+ if parts.length == 3 # handle the timestamp
30
+ point['time'] = parts[2]
31
+ else
32
+ # no time left for you, on my way to better things
33
+ point['time'] = nil
34
+ end
35
+ point
36
+ end
37
+ def unescape_measurement(s)
38
+ s.gsub(/\\ /,' ').gsub(/\\,/,',')
39
+ end
40
+ def unescape_tag(s)
41
+ t = unescape_measurement s
42
+ t.gsub(/\\=/,'=')
43
+ end
44
+ def unescape_point(s)
45
+ if s[-1,1] == '"'
46
+
47
+ # it's a quoted string and should be unescaped
48
+ s = s[1..-2] # take the wrapping quotes off
49
+ return s.gsub(/\\\\/,',').gsub(/\\"/,',')
50
+ else
51
+ # it's a number and if it's trailing an i we need to strip it because we're not handling precision here
52
+ return s.chomp('i')
53
+ end
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: influxparser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Labrie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Unofficial influx line protocol parser
14
+ email: robert.labrie@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/influxparser.rb
20
+ homepage:
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.5.2.1
40
+ signing_key:
41
+ specification_version: 3
42
+ summary: InfluxDB line protocol parser
43
+ test_files: []