Permalink
Browse files

- change to 3 part version number

- rename in the ddl
- add a readme and copying file
  • Loading branch information...
1 parent 0f29722 commit 645f8c15c360dc8799fe89b144a45d3c981e6b3e @ripienaar committed Feb 23, 2013
Showing with 91 additions and 64 deletions.
  1. +14 −0 agent/urltest/COPYING
  2. +39 −0 agent/urltest/README.md
  3. +2 −2 agent/urltest/agent/urltest.ddl
  4. +36 −62 agent/urltest/agent/urltest.rb
View
@@ -0,0 +1,14 @@
+ Copyright 2012 R.I.Pienaar
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
View
@@ -0,0 +1,39 @@
+What?
+=====
+
+A simple MCollective agent to do a banchmark of a specied URL.
+
+Usage?
+------
+
+<pre>
+% mco urltest http://www.devco.net/
+
+ * [ ============================================================> ] 11 / 11
+
+ Tester Location DNS Connect Pre-xfer Start-xfer Total Bytes Fetched
+ node3: 5.0086 0.0066 0.7277 0.7272 6.9230 101859
+ node8: 5.0127 0.0054 0.8764 0.8761 7.1109 101859
+ middleware: 5.0063 0.0044 0.8985 0.8982 7.1212 101859
+ node7: 5.0097 0.0082 0.9753 0.9749 7.1797 101859
+ node4: 5.0070 0.0069 0.8708 0.8702 7.2758 101859
+ node1: 5.0083 0.0077 1.0395 1.0386 7.2877 101859
+ node9: 5.0127 0.0061 1.1421 1.1419 7.3066 101859
+ node5: 5.0041 0.0052 0.9964 0.9959 7.3191 101859
+ node0: 5.0433 0.0051 0.9715 0.9712 7.3205 101859
+ node6: 5.0084 0.0050 0.9896 0.9892 7.3213 101859
+ node2: 5.0126 0.0063 0.9806 0.9799 7.3277 101859
+
+Summary:
+
+ DNS lookup time: min: 5.0041 max: 5.0433 avg: 5.0122 sdev: 0.0107
+ TCP connect time: min: 0.0044 max: 0.0082 avg: 0.0061 sdev: 0.0012
+ Time to first byte: min: 0.7277 max: 1.1421 avg: 0.9517 sdev: 0.1070
+ HTTP Responce time: min: 0.7272 max: 1.1419 avg: 0.9512 sdev: 0.1070
+ Total time taken: min: 6.9230 max: 7.3277 avg: 7.2267 sdev: 0.1296
+</pre>
+
+Contact?
+--------
+
+R.I.Pienaar / rip@devco.net / @ripienaar / http://devco.net/
@@ -1,8 +1,8 @@
-metadata :name => "urltester",
+metadata :name => "urltest",
:description => "Agent that connects to a URL and returns some statistics",
:author => "R.I.Pienaar <rip@devco.net>",
:license => "ASL 2.0",
- :version => "2.0.0",
+ :version => "2.0.1",
:url => "https://github.com/ripienaar/mc-plugins",
:timeout => 60
@@ -1,80 +1,54 @@
require 'net/http'
require 'socket'
-require 'ostruct'
module MCollective
- module Agent
- # An agent that performs a web get and report stats back to the client
- #
- # See http://code.google.com/p/mcollective-plugins/wiki/AgentUrltest
- #
- # Released under the terms of the GPLv2
- class Urltest<RPC::Agent
- attr_reader :timeout, :meta
+ module Agent
+ class Urltest<RPC::Agent
+ action "perftest" do
+ url = URI.parse(request[:url])
- metadata :name => "SimpleRPC URL Testing Agent",
- :description => "Agent that connects to a URL and returns some statistics",
- :author => "R.I.Pienaar",
- :license => "GPLv2",
- :version => "1.2",
- :url => "http://mcollective-plugins.googlecode.com/",
- :timeout => 60
+ times = {}
- action "perftest" do
- validate :url, :shellsafe
+ if url.scheme == "http"
+ times["beforedns"] = Time.now
+ name = TCPSocket.gethostbyname(url.host)
+ times["afterdns"] = Time.now
- begin
- url = URI.parse(request[:url])
+ times["beforeopen"] = Time.now
+ socket = TCPSocket.open(url.host, url.port)
+ times["afteropen"] = Time.now
- times = {}
+ socket.print("GET #{url.request_uri} HTTP/1.1\r\nHost: #{url.host}\r\nUser-Agent: Webtester\r\nAccept: */*\r\nConnection: close\r\n\r\n")
+ times["afterrequest"] = Time.now
- if url.scheme == "http"
- times["beforedns"] = Time.now
- name = TCPSocket.gethostbyname(url.host)
- times["afterdns"] = Time.now
+ response = Array.new
- times["beforeopen"] = Time.now
- socket = TCPSocket.open(url.host, url.port)
- times["afteropen"] = Time.now
+ while line = socket.gets
+ times["firstline"] = Time.now unless times.include?("firstline")
- socket.print("GET #{url.request_uri} HTTP/1.1\r\nHost: #{url.host}\r\nUser-Agent: Webtester\r\nAccept: */*\r\nConnection: close\r\n\r\n")
- times["afterrequest"] = Time.now
+ response << line
+ end
- response = Array.new
+ socket.close
- while line = socket.gets
- times["firstline"] = Time.now unless times.include?("firstline")
+ times["end"] = Time.now
- response << line
- end
+ reply[:lookuptime] = times["afterdns"] - times["beforedns"]
+ reply[:connectime] = times["afteropen"] - times["beforeopen"]
+ reply[:prexfertime] = times["firstline"] - times["afteropen"]
+ reply[:startxfer] = times["firstline"] - times["afterrequest"]
+ reply[:bytesfetched] = response.join.length
+ reply[:totaltime] = times["end"] - times["beforedns"]
- socket.close
-
- times["end"] = Time.now
-
- reply[:lookuptime] = times["afterdns"] - times["beforedns"]
- reply[:connectime] = times["afteropen"] - times["beforeopen"]
- reply[:prexfertime] = times["firstline"] - times["afteropen"]
- reply[:startxfer] = times["firstline"] - times["afterrequest"]
- reply[:bytesfetched] = response.join.length
- reply[:totaltime] = times["end"] - times["beforedns"]
-
- if Config.instance.pluginconf.include?("urltest.syslocation")
- reply[:testerlocation] = Config.instance.pluginconf["urltest.syslocation"]
- else
- reply[:testerlocation] = "Please set plugin.urltest.syslocation"
- end
- else
- reply.fail "Unsupported url scheme: #{url.scheme}"
- return
- end
- rescue Exception => e
- reply.fail e.to_s
- return
- end
- end
+ if Config.instance.pluginconf.include?("urltest.syslocation")
+ reply[:testerlocation] = Config.instance.pluginconf["urltest.syslocation"]
+ else
+ reply[:testerlocation] = "Please set plugin.urltest.syslocation"
+ end
+ else
+ reply.fail "Unsupported url scheme: %s" % url.scheme
end
+ end
end
+ end
end
-
-# vi:tabstop=4:expandtab:ai

0 comments on commit 645f8c1

Please sign in to comment.