apc-report-parser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/LICENSE +14 -0
- data/README +9 -0
- data/bin/parse-apc-report +20 -0
- data/lib/apc-report-parser.rb +57 -0
- metadata +98 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (C) 2010 3Crowd Technologies, Inc.
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'choice'
|
4
|
+
require 'apc-report-parser'
|
5
|
+
|
6
|
+
Choice.options do
|
7
|
+
option :uri do
|
8
|
+
short '-u'
|
9
|
+
long '--uri=URI'
|
10
|
+
desc 'The uri from which to retrieve content to parse'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
opts = Choice.choices
|
15
|
+
|
16
|
+
apc_stats_report = APCStatsReport.new(opts[:uri])
|
17
|
+
|
18
|
+
require 'pp'
|
19
|
+
pp apc_stats_report.report
|
20
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class ReportNotInitializedError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
# The loader and parser should be factored out, but this is good enough for now
|
11
|
+
class APCStatsReport
|
12
|
+
|
13
|
+
def initialize(uri="http://localhost:80/apc.php", lazy_load=true)
|
14
|
+
@uri = URI.parse(uri)
|
15
|
+
@lazy_load = lazy_load
|
16
|
+
end
|
17
|
+
|
18
|
+
def retrieve_report!
|
19
|
+
resource = Net::HTTP.start(@uri.host, @uri.port) do |http|
|
20
|
+
http.get(@uri.path)
|
21
|
+
end
|
22
|
+
@report = parse_resource_into_report(resource)
|
23
|
+
end
|
24
|
+
|
25
|
+
def report
|
26
|
+
if @report.nil?
|
27
|
+
raise ReportNotInitializedError unless @lazy_load
|
28
|
+
retrieve_report!
|
29
|
+
end
|
30
|
+
@report
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def parse_resource_into_report(resource)
|
36
|
+
document = Nokogiri::HTML(resource.body)
|
37
|
+
headers = extract_headers(document)
|
38
|
+
report = headers.inject(Hash.new) do |results, header|
|
39
|
+
results[header.text] = extract_substats(header)
|
40
|
+
results
|
41
|
+
end
|
42
|
+
return report
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_headers(document)
|
46
|
+
document.css('body div.content div.info h2')
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_substats(header)
|
50
|
+
header.parent.children.css('tr').inject(Hash.new) do |substats, row|
|
51
|
+
label = row.children[0]
|
52
|
+
data = row.children[1]
|
53
|
+
substats[label.text] = data.text
|
54
|
+
substats
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apc-report-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- 3Crowd Technologies, Inc.
|
13
|
+
- Justin Lynn
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-28 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: choice
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
version: 0.1.4
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: nokogiri
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 4
|
45
|
+
- 3
|
46
|
+
- 1
|
47
|
+
version: 1.4.3.1
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Parses APC (Advanced PHP Cache) HTML status output from apc.php, included in a recent versions of PHP, into a data structure that is usable by ruby.
|
51
|
+
email:
|
52
|
+
- eng@3crowd.com
|
53
|
+
executables:
|
54
|
+
- parse-apc-report
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- bin/parse-apc-report
|
61
|
+
- lib/apc-report-parser.rb
|
62
|
+
- LICENSE
|
63
|
+
- README
|
64
|
+
- CHANGELOG
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/3Crowd/apc-report-parser
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 3
|
88
|
+
- 6
|
89
|
+
version: 1.3.6
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Parses APC HTML status output from apc.php
|
97
|
+
test_files: []
|
98
|
+
|