Skip to content

Commit

Permalink
Merge pull request #1 from ilons/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ilons committed Mar 16, 2015
2 parents 4e62a8b + 75c392c commit d55dd56
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 18 deletions.
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
# Deprecated
## New Relic Varnish Extension

This is a fork of [the original](https://github.com/varnish/newrelic_varnish_plugin) which no longer seems to be maintained

This runs on the Varnish server and reports the values from
varnishstat back into New Relic.

## Instructions for running the Varnish extension agent

1. Go to [the tags list](https://github.com/varnish/newrelic_varnish_plugin/tags) and find the latest tar.gz
2. Download and extract the source
3. run `bundle install` to install required gems
4. Copy `config/template_newrelic_plugin.yml` to `config/newrelic_plugin.yml`
5. Edit `config/newrelic_plugin.yml` and replace "YOUR_LICENSE_KEY_HERE" with your New Relic license key
6. Edit the `config/newrelic_plugin.yml` if you are running Varnish
with an -n argument
7. Execute `./newrelic_varnish_plugin`
8. Go back to the Extensions list and after a brief period you will see an entry for your extension

## Feedback, discussions and problems

The plugin can be discussed in the [Google group][group]. Bugs can be
reported on the [Github tracker][ghbugs] and pull requests are welcome.

[group]: https://groups.google.com/a/varnish-software.com/forum/#!forum/newrelic
[ghbugs]: https://github.com/varnish/newrelic_varnish_plugin/issues
1. Check out the latest source from develop
2. run `bundle install` to install required gems
3. Copy `config/template_newrelic_plugin.yml` to path of your choise, ex `/etc/newrelic/newrelic_varnish_plugin.yml`
4. Edit the `newrelic_plugin.yml` copy you just made and replace "YOUR_LICENSE_KEY_HERE" with your New Relic license key
5. Edit the configuration further if you are running Varnish with an -n argument
6. Execute `./newrelic_varnish_plugin -h` for usage instructions
7. Go back to the Extensions list and after a brief period you will see an entry for your extension
75 changes: 75 additions & 0 deletions newrelic_varnish_plugin
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,78 @@
# SUCH DAMAGE.

require 'rubygems'
require 'optparse'
require "bundler/setup"
require 'rexml/document'
require "newrelic_plugin"

module VarnishAgent
@options = OpenStruct.new
@options.config_file = "config/newrelic_plugin.yml"
@options.pid_file = "newrelic_plugin.pid"

def VarnishAgent.parse_args(args)
opt_parser = OptionParser.new do |opts|
opts.banner = "Example usage: " \
"./newrelic_varnish_plugin -c /etc/newrelic/newrelic_varnish.yml -p /var/run/newrelic_varnish.pid" \
"\n\n" \
"Usage options:\n"

opts.on("-c CONFIG_FILE",
"--config=CONFIG_FILE",
"Description: Config file, this must be readable by the user",
"Example: /etc/newrelic/newrelic_varnish_plugin.yml",
"Default: config/newrelic_plugin.yml\n\n") do |config|
@options.config_file = config
end

opts.on("-p PIDFILE",
"--pidfile=PIDFILE",
"Description: Pid file, this must be writable by the user",
"Example: /var/run/newrelic_varnish_plugin.pid",
"Default: newrelic_plugin.pid\n\n") do |pidfile|
@options.pid_file = pidfile
end

opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end

begin
opt_parser.parse(args)
rescue OptionParser::MissingArgument
puts "Error: You must provide a value with this argument\n\n"
opt_parser.parse("-h")
exit
end
return @options
end

def VarnishAgent.write_pid_file()
file_path = @options.pid_file
pid = Process.pid

begin
pid_file = File.open(file_path, 'w')
pid_file.write(pid)
pid_file.write("\n")
pid_file.close()
rescue
unless File.writable?(file_path)
puts "Error: Could not write to pid file!\n"
end
end
end

def VarnishAgent.clear_pid_file()
file_path = @options.pid_file
if File.file?(file_path) && File.writable?(file_path)
File.delete(file_path)
end
end

def VarnishAgent.groups()
return {
'Request rates' => {
Expand Down Expand Up @@ -184,10 +251,18 @@ module VarnishAgent
end
end

options = VarnishAgent.parse_args(ARGV)
NewRelic::Plugin::Config.config_file = options.config_file
NewRelic::Plugin::Setup.install_agent :varnish,VarnishAgent
VarnishAgent.write_pid_file()

#
# Launch the agent (never returns)
#
NewRelic::Plugin::Run.setup_and_run

#
# If process are being shut down gracefully, clear pid file
#
VarnishAgent.clear_pid_file()
end

0 comments on commit d55dd56

Please sign in to comment.