telegraf_agent 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 061ddb1dfcb41363cdac70f1c05550397f165a43a1740f32be1c62256616c51d
4
+ data.tar.gz: 852a6602c75ee398631bdfd4299583e55bbf9a9c133eb0f18e01c6663a2c23f3
5
+ SHA512:
6
+ metadata.gz: 78bd61f1a6d8cc4904fbdc69edafabb4be5de5267408ba55092e893c63ebf00911e677fed9d05849988b8ad280457b749cc24bd3a0990012d2277c196af29f4e
7
+ data.tar.gz: fb45061d19ffb65027b18eeb47802c0350aba5b96ad8bcdc53a62d6edc81a7f0b9d6467bdb0c73fb124e8742ec07999a79c2664ca01697e3817cf8bbd127a22b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.3
data/.travis.yml ADDED
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+
3
+ sudo: false
4
+
5
+ rvm:
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - ruby-head
10
+
11
+ before_install: gem install bundler
12
+ script:
13
+ - COVER=1 bundle exec rspec
14
+ - bundle exec rubocop
15
+
16
+ matrix:
17
+ fast_finish: true
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+
21
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ group :development, :test do
6
+ gem "rubocop-config-umbrellio", git: "https://github.com/umbrellio/code-style.git"
7
+ end
8
+
9
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ GIT
2
+ remote: https://github.com/umbrellio/code-style.git
3
+ revision: 271d7001fe5e0f9649a69781890ab27c7c40813f
4
+ specs:
5
+ rubocop-config-umbrellio (0.60.0)
6
+ rubocop (= 0.60.0)
7
+ rubocop-rspec (= 1.30.1)
8
+
9
+ PATH
10
+ remote: .
11
+ specs:
12
+ telegraf_agent (0.1.0)
13
+ influxdb (~> 0.6)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ ast (2.4.0)
19
+ coveralls (0.8.22)
20
+ json (>= 1.8, < 3)
21
+ simplecov (~> 0.16.1)
22
+ term-ansicolor (~> 1.3)
23
+ thor (~> 0.19.4)
24
+ tins (~> 1.6)
25
+ diff-lcs (1.3)
26
+ docile (1.3.1)
27
+ influxdb (0.7.0)
28
+ jaro_winkler (1.5.2)
29
+ json (2.1.0)
30
+ parallel (1.13.0)
31
+ parser (2.6.0.0)
32
+ ast (~> 2.4.0)
33
+ powerpack (0.1.2)
34
+ rainbow (3.0.0)
35
+ rake (11.3.0)
36
+ rspec (3.8.0)
37
+ rspec-core (~> 3.8.0)
38
+ rspec-expectations (~> 3.8.0)
39
+ rspec-mocks (~> 3.8.0)
40
+ rspec-core (3.8.0)
41
+ rspec-support (~> 3.8.0)
42
+ rspec-expectations (3.8.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.8.0)
45
+ rspec-mocks (3.8.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.8.0)
48
+ rspec-support (3.8.0)
49
+ rubocop (0.60.0)
50
+ jaro_winkler (~> 1.5.1)
51
+ parallel (~> 1.10)
52
+ parser (>= 2.5, != 2.5.1.1)
53
+ powerpack (~> 0.1)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (~> 1.4.0)
57
+ rubocop-rspec (1.30.1)
58
+ rubocop (>= 0.60.0)
59
+ ruby-progressbar (1.10.0)
60
+ simplecov (0.16.1)
61
+ docile (~> 1.1)
62
+ json (>= 1.8, < 3)
63
+ simplecov-html (~> 0.10.0)
64
+ simplecov-html (0.10.2)
65
+ term-ansicolor (1.7.0)
66
+ tins (~> 1.0)
67
+ thor (0.19.4)
68
+ tins (1.20.2)
69
+ unicode-display_width (1.4.1)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 2.0)
76
+ coveralls (~> 0.8)
77
+ rake (~> 11.2)
78
+ rspec (~> 3.8)
79
+ rubocop-config-umbrellio!
80
+ simplecov (~> 0.16)
81
+ telegraf_agent!
82
+
83
+ BUNDLED WITH
84
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # TelegrafAgent
2
+
3
+ [![Build Status](https://travis-ci.org/umbrellio/telegraf_agent.svg?branch=master)](https://travis-ci.org/umbrellio/telegraf_agent)
4
+ [![Coverage Status](https://coveralls.io/repos/github/umbrellio/telegraf_agent/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/telegraf_agent?branch=master)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'telegraf_agent'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install telegraf_agent
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ logger = Logger.new(STDOUT)
26
+ agent = TelegrafAgent.new(url: "udp://localhost:3030", logger: logger)
27
+ agent.write("SuperProject", keys: { env: Rails.env }, values: { action: "index", duration: 0.2 })
28
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "telegraf_agent"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "socket"
4
+ require "influxdb"
5
+
6
+ class TelegrafAgent
7
+ ConnectionError = Class.new(StandardError)
8
+
9
+ attr_reader :uri, :logger
10
+
11
+ # Initialize an agent
12
+ #
13
+ # @param [Hash] opts
14
+ # @option opts [String] :url URL
15
+ # @option opts [#debug] :logger Logger
16
+ def initialize(url:, logger: nil)
17
+ @uri = URI.parse(url)
18
+ @logger = logger
19
+ end
20
+
21
+ # Send data to telegraf
22
+ #
23
+ # @param [String] series Series name
24
+ # @param [Hash] opts
25
+ # @option opts [Hash] :tags Tags
26
+ # @option opts [Hash] :values Values
27
+ def write(series, tags:, values:)
28
+ data = ::InfluxDB::PointValue.new(series: series, tags: tags, values: values).dump
29
+ logger&.debug("Sending data to #{uri}: #{data}")
30
+ connection.write(data)
31
+ rescue
32
+ disconnect!
33
+ end
34
+
35
+ private
36
+
37
+ def disconnect!
38
+ connection&.close
39
+ @connection = nil
40
+ end
41
+
42
+ def connection
43
+ @connection ||= create_connection!
44
+ end
45
+
46
+ def create_connection!
47
+ case uri.scheme.downcase
48
+ when "unix"
49
+ Socket.new(:UNIX, :STREAM).tap { |socket| socket.connect(Socket.pack_sockaddr_un(uri.path)) }
50
+ when "unixgram"
51
+ Socket.new(:UNIX, :DGRAM).tap { |socket| socket.connect(Socket.pack_sockaddr_un(uri.path)) }
52
+ when /^tcp/
53
+ TCPSocket.new(uri.host, uri.port)
54
+ when /^udp/
55
+ UDPSocket.new.tap { |socket| socket.connect(uri.host, uri.port) }
56
+ else
57
+ raise ConnectionError, "Unsupported connection type: #{uri.scheme}"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "telegraf_agent"
8
+ spec.version = "0.1.0"
9
+ spec.authors = ["nulldef"]
10
+ spec.email = ["nulldefiner@gmail.com"]
11
+
12
+ spec.summary = "Telegraf agent"
13
+ spec.description = "Telegraf agent"
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_dependency "influxdb", "~> 0.6"
18
+ spec.add_development_dependency "bundler", "~> 2.0"
19
+ spec.add_development_dependency "coveralls", "~> 0.8"
20
+ spec.add_development_dependency "rake", "~> 11.2"
21
+ spec.add_development_dependency "rspec", "~> 3.8"
22
+ spec.add_development_dependency "simplecov", "~> 0.16"
23
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telegraf_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nulldef
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: influxdb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.16'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.16'
97
+ description: Telegraf agent
98
+ email:
99
+ - nulldefiner@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/telegraf_agent.rb
115
+ - telegraf_agent.gemspec
116
+ homepage:
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.7.6
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Telegraf agent
139
+ test_files: []