newrelic_openvpn_agent 0.0.1

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: b2c6482cea6fb90d3d6344cdc37e2d9627e92a6e
4
+ data.tar.gz: 08605dcb51a8c0ba0cf4dbf5f943a8c2f512970e
5
+ SHA512:
6
+ metadata.gz: 555d328a02438f6dd3847c30dc85ff948a06a86f928fd285c7bfd3174ae45173aa354923a98655f4c0aae30b0bfcafa82269f006b0fb4ef07315f38170f08636
7
+ data.tar.gz: 9079a3733a09dd63c32b9b639e79ba3fd7bd5c09c4707dc030069dbb1f7d79d51d744ff7cc48f5d797b0f4069e3cd9b633ce23d4d1783f30181d6496936564d1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ## New Relic OpenVPN monitoring Plugin
2
+
3
+ The New Relic OpenVPN Plugin enables monitoring OpenVPN, and it reports the following data:
4
+
5
+ * Amount of active Users
6
+ * Amount of active Clients
7
+ * Amount of bytes sent
8
+ * Amount of bytes received
9
+ * Average of bytes sent
10
+ * Average of bytes received
11
+
12
+ ### Requirements
13
+
14
+ The OpenVPN monitoring Plugin for New Relic requires the following:
15
+
16
+ * A New Relic account. Signup for a free account at http://newrelic.com
17
+ * You need a host to install the plugin on the OpenVPN server. That host also needs Ruby (tested with 1.8.7, 1.9.3), and support for rubygems.
18
+
19
+ ### Instructions for running the OpenVPN agent
20
+
21
+ 1. Install this gem from RubyGems:
22
+
23
+ `sudo gem install newrelic_openvpn_agent`
24
+
25
+ 2. Install config, execute
26
+
27
+ `sudo newrelic_openvpn_agent install` - it will create `/etc/newrelic/newrelic_openvpn_agent.yml` file for you.
28
+
29
+ 3. Edit the `/etc/newrelic/newrelic_openvpn_agent.yml` file generated in step 2.
30
+
31
+ 3.1. replace `YOUR_LICENSE_KEY_HERE` with your New Relic license key. Your license key can be found under Account Settings at https://rpm.newrelic.com, see https://newrelic.com/docs/subscriptions/license-key for more help.
32
+
33
+ 3.2. replace the agent name 'openvpn' to any unique instance name of choice
34
+
35
+ 3.3. replace the path of the OpenVPN status binary if needed
36
+
37
+ 4. Execute
38
+
39
+ `newrelic_openvpn_agent run`
40
+
41
+ 5. Go back to the Plugins list and after a brief period you will see the OpenVPN Plugin listed in your New Relic account
42
+
43
+
44
+ ## Keep this process running
45
+
46
+ You can use services like these to manage this process and run it as a daemon.
47
+
48
+ - [Upstart](http://upstart.ubuntu.com/)
49
+ - [Systemd](http://www.freedesktop.org/wiki/Software/systemd/)
50
+ - [Runit](http://smarden.org/runit/)
51
+ - [Monit](http://mmonit.com/monit/)
52
+
53
+ ## Support
54
+
55
+ Please use Github issues for support.
data/Rakefile ADDED
@@ -0,0 +1,153 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Generate RCov test coverage and open in your browser"
56
+ task :coverage do
57
+ require 'rcov'
58
+ sh "rm -fr coverage"
59
+ sh "rcov test/test_*.rb"
60
+ sh "open coverage/index.html"
61
+ end
62
+
63
+ require 'rdoc/task'
64
+ Rake::RDocTask.new do |rdoc|
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "#{name} #{version}"
67
+ rdoc.rdoc_files.include('lib/**/*.rb')
68
+ rdoc.rdoc_files.include('README.rdoc')
69
+ rdoc.rdoc_files.include('LICENSE')
70
+ rdoc.rdoc_files.include('CHANGES')
71
+ rdoc.main = "README.rdoc"
72
+ end
73
+
74
+ desc "Open an irb session preloaded with this library"
75
+ task :console do
76
+ sh "irb -rubygems -r ./lib/#{name}.rb"
77
+ end
78
+
79
+ #############################################################################
80
+ #
81
+ # Custom tasks (add your own tasks here)
82
+ #
83
+ #############################################################################
84
+
85
+
86
+
87
+ #############################################################################
88
+ #
89
+ # Packaging tasks
90
+ #
91
+ #############################################################################
92
+
93
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
94
+ task :release => :build do
95
+ unless `git branch` =~ /^\* master$/
96
+ puts "You must be on the master branch to release!"
97
+ exit!
98
+ end
99
+ sh "git commit --allow-empty -a -m 'Release #{name} #{version}'"
100
+ #sh "git tag v#{version}"
101
+ sh "git push origin master"
102
+ #sh "git push origin v#{version}"
103
+ sh "gem push pkg/#{name}-#{version}.gem"
104
+ end
105
+
106
+ desc "Build #{gem_file} into the pkg directory"
107
+ task :build => :gemspec do
108
+ sh "mkdir -p pkg"
109
+ sh "gem build #{gemspec_file}"
110
+ sh "mv #{gem_file} pkg"
111
+ end
112
+
113
+ desc "Generate #{gemspec_file}"
114
+ task :gemspec => :validate do
115
+ # read spec file and split out manifest section
116
+ spec = File.read(gemspec_file)
117
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
118
+
119
+ # replace name version and date
120
+ replace_header(head, :name)
121
+ replace_header(head, :version)
122
+ replace_header(head, :date)
123
+ #comment this out if your rubyforge_project has a different name
124
+ #replace_header(head, :rubyforge_project)
125
+
126
+ # determine file list from git ls-files
127
+ files = `git ls-files`.
128
+ split("\n").
129
+ sort.
130
+ reject { |file| file =~ /^\./ }.
131
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
132
+ map { |file| " #{file}" }.
133
+ join("\n")
134
+
135
+ # piece file back together and write
136
+ manifest = " s.files = %w[\n#{files}\n ]\n"
137
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
138
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
139
+ puts "Updated #{gemspec_file}"
140
+ end
141
+
142
+ desc "Validate #{gemspec_file}"
143
+ task :validate do
144
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
145
+ unless libfiles.empty?
146
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
147
+ exit!
148
+ end
149
+ unless Dir['VERSION*'].empty?
150
+ puts "A `VERSION` file at root level violates Gem best practices."
151
+ exit!
152
+ end
153
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ $stdout.sync = true
3
+
4
+ $LOAD_PATH.unshift File.expand_path "../../lib", __FILE__
5
+ require "newrelic_openvpn_agent"
6
+ require 'optparse'
7
+
8
+ NewRelic::Plugin::Config.config_file = "/etc/newrelic/newrelic_openvpn_agent.yml"
9
+
10
+ options = OptionParser.new do |opts|
11
+ opts.banner = <<-EOF
12
+ Usage:
13
+ newrelic_openvpn_agent ( run | install ) [options]
14
+ EOF
15
+
16
+ opts.on("-v", "--verbose", "Run verbosely") do
17
+ NewRelic::Plugin::Config.config.newrelic['verbose'] = 1
18
+ end
19
+
20
+ opts.on("-c", "--config FILE", "Override the location of the newrelic_plugin.yml") do | filename |
21
+ if !File.exists? filename
22
+ puts "File not found: #{filename.inspect}"
23
+ exit 1
24
+ end
25
+ NewRelic::Plugin::Config.config_file = filename
26
+ end
27
+
28
+ opts.on("-h", "--help") do
29
+ puts opts
30
+ if File.basename($0) == File.basename(__FILE__)
31
+ exit 0
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ args = options.parse!(ARGV)
38
+
39
+ if args.first == "run"
40
+ if !File.exists? NewRelic::Plugin::Config.config_file
41
+ puts "Agent config file not found: #{NewRelic::Plugin::Config.config_file.inspect}"
42
+ puts "Run 'sudo newrelic_openvpn_agent install' for setup config"
43
+ exit 1
44
+ end
45
+ NewRelicOpenvpnAgent.run
46
+ elsif args.first == "install"
47
+ config_file = File.read(File.expand_path("../../config/template_newrelic_plugin.yml", __FILE__))
48
+
49
+ require 'fileutils'
50
+ FileUtils.mkdir_p "/etc/newrelic"
51
+ File.open("/etc/newrelic/newrelic_openvpn_agent.yml", "w") do | io |
52
+ io.write(config_file)
53
+ end
54
+ puts "Saved agent config file #{File.expand_path("/etc/newrelic/newrelic_openvpn_agent.yml")}"
55
+ else
56
+ puts options
57
+ end
@@ -0,0 +1,20 @@
1
+ # Please make sure to update the license_key information with the license key for your New Relic
2
+ # account.
3
+ #
4
+ #
5
+ newrelic:
6
+ #
7
+ # Update with your New Relic account license key:
8
+ #
9
+ license_key: 'YOUR_LICENSE_KEY_HERE'
10
+ #
11
+ # Set to '1' for verbose output, remove for normal output.
12
+ # All output goes to stdout/stderr.
13
+ #
14
+ # verbose: 1
15
+ #
16
+ # Agent Configuration:
17
+ #
18
+ agents:
19
+ openvpn:
20
+ openvpn_status_path : "/etc/openvpn/openvpn-status.log"
@@ -0,0 +1,61 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ #
4
+ # This is a NewRelic agent which pushes OpenVPN information.
5
+ #
6
+
7
+ require "rubygems"
8
+ require "bundler/setup"
9
+ require "newrelic_plugin"
10
+
11
+ module NewRelicOpenvpnAgent
12
+ class Agent < NewRelic::Plugin::Agent::Base
13
+ agent_guid "com.kangacoders.openvpn"
14
+ agent_version "0.0.1"
15
+ agent_config_options :openvpn_status_path
16
+ agent_human_labels("OpenVPN Agent") { ident }
17
+
18
+ attr_reader :ident
19
+
20
+ def poll_cycle
21
+ [:total_users, :total_clients, :total_bytes_received, :total_bytes_sent, :average_bytes_received, :average_bytes_sent].each do |_type|
22
+ name, unit, _output = metric(_type)
23
+ report_metric name, unit, _output.call
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def get_columns(_output, _c_index, _uniq = true, _total = true)
30
+ result = _output.scan(/^([^,]+),(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d+,(\d+),(\d+).+$/).map{|_x| _x[_c_index] }
31
+ result = result.uniq if _uniq
32
+ result = result.length if _total
33
+ result
34
+ end
35
+
36
+ def metric(_type)
37
+ metrics = {
38
+ :total_users => ["Total/Users", "Users", lambda{get_columns(ovpn_cmd, 0) }],
39
+ :total_clients => ["Total/Clients", "Clients", lambda{get_columns(ovpn_cmd, 1) }],
40
+ :total_bytes_received => ["Total/Bytes/Received", "bytes", lambda{ get_columns(ovpn_cmd, 2, false, false).inject(0){|_t, _b| (_t + _b.to_i) } }],
41
+ :total_bytes_sent => ["Total/Bytes/Sent", "bytes", lambda{ get_columns(ovpn_cmd, 3, false, false).inject(0){|_t, _b| (_t + _b.to_i) } }],
42
+ :average_bytes_received => ["Average/Bytes/Received", "bytes", lambda{ x = get_columns(ovpn_cmd, 2, false, false); x.inject(0){|_t, _b| (_t + _b.to_i) } / x.length }],
43
+ :average_bytes_sent => ["Average/Bytes/Sent", "bytes", lambda{ x = get_columns(ovpn_cmd, 3, false, false); x.inject(0){|_t, _b| (_t + _b.to_i) } / x.length }]
44
+ }
45
+ metrics[_type]
46
+ end
47
+
48
+ def ovpn_cmd
49
+ `cat #{openvpn_status_path}`
50
+ end
51
+
52
+ end
53
+
54
+ def self.run
55
+ NewRelic::Plugin::Config.config.agents.keys.each do |_agent|
56
+ NewRelic::Plugin::Setup.install_agent _agent, NewRelicOpenvpnAgent
57
+ end
58
+
59
+ NewRelic::Plugin::Run.setup_and_run
60
+ end
61
+ end
@@ -0,0 +1,81 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'newrelic_openvpn_agent'
16
+ s.version = '0.0.1'
17
+ s.date = '2013-12-12'
18
+ # s.rubyforge_project = 'newrelic_openvpn_agent'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "New Relic openvpn monitoring plugin"
23
+ s.description = <<-EOF
24
+ This is the New Relic plugin for monitoring OpenVPN developed by KangaCoders Ltd.
25
+ EOF
26
+
27
+ ## List the primary authors. If there are a bunch of authors, it's probably
28
+ ## better to set the email to an email list or something. If you don't have
29
+ ## a custom homepage, consider using your GitHub URL or the like.
30
+ s.authors = ["Kai De Sutter"]
31
+ s.email = 'kdesutter@kangacoders.com'
32
+ s.homepage = 'http://www.kangacoders.com/'
33
+
34
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
35
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
36
+ s.require_paths = %w[lib]
37
+
38
+ ## This sections is only necessary if you have C extensions.
39
+ #s.require_paths << 'ext'
40
+ #s.extensions = %w[ext/extconf.rb]
41
+
42
+ ## If your gem includes any executables, list them here.
43
+ s.executables = ["newrelic_openvpn_agent"]
44
+
45
+ ## Specify any RDoc options here. You'll want to add your README and
46
+ ## LICENSE files to the extra_rdoc_files list.
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.extra_rdoc_files = %w[README.md]
49
+
50
+ s.license = 'MIT'
51
+
52
+ ## List your runtime dependencies here. Runtime dependencies are those
53
+ ## that are needed for an end user to actually USE your code.
54
+ s.add_dependency('bundler')
55
+ s.add_dependency('newrelic_plugin', "1.0.3")
56
+
57
+ s.post_install_message = <<-EOF
58
+ To get started with this plugin, do
59
+ newrelic_openvpn_agent -h
60
+ to find out how to install and run the plugin agent.
61
+ EOF
62
+
63
+ ## Leave this section as-is. It will be automatically generated from the
64
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
65
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
66
+ # = MANIFEST =
67
+ s.files = %w[
68
+ Gemfile
69
+ README.md
70
+ Rakefile
71
+ bin/newrelic_openvpn_agent
72
+ config/template_newrelic_plugin.yml
73
+ lib/newrelic_openvpn_agent.rb
74
+ newrelic_openvpn_agent.gemspec
75
+ ]
76
+ # = MANIFEST =
77
+
78
+ ## Test files will be grabbed from the file list. Make sure the path glob
79
+ ## matches what you actually use.
80
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
81
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newrelic_openvpn_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kai De Sutter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-12 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: newrelic_plugin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.3
41
+ description: |
42
+ This is the New Relic plugin for monitoring OpenVPN developed by KangaCoders Ltd.
43
+ email: kdesutter@kangacoders.com
44
+ executables:
45
+ - newrelic_openvpn_agent
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - README.md
49
+ files:
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/newrelic_openvpn_agent
54
+ - config/template_newrelic_plugin.yml
55
+ - lib/newrelic_openvpn_agent.rb
56
+ - newrelic_openvpn_agent.gemspec
57
+ homepage: http://www.kangacoders.com/
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message: |2
62
+ To get started with this plugin, do
63
+ newrelic_openvpn_agent -h
64
+ to find out how to install and run the plugin agent.
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.1.11
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: New Relic openvpn monitoring plugin
85
+ test_files: []