This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp__superhub
executable file
·165 lines (140 loc) · 3.53 KB
/
http__superhub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env ruby
if $0 =~ /^(?:|.*\/)http_([^_]+)_/
host = $1
end
abort "# Error: couldn't understand what I'm supposed to monitor." unless host
require 'net/http'
require 'nokogiri'
class SuperhubStats
def initialize(host)
@host = host
end
def downstream_channel_details
cells = get_table_data(downstream_stats_page, 'Downstream')
rows = cells.each_with_object({}) do |row, result|
result[row[0]] = row[1..-1]
end
8.times.map do |n|
{
:lock_status => rows["Lock Status(QAM Lock/FEC Sync/MPEG Lock)"][n],
:rx_power => rows["Power Level (dBmV)"][n],
:snr => rows["RxMER (dB)"][n],
}
end
end
def upstream_channel_details
cells = get_table_data(upstream_stats_page, 'Upstream')
rows = cells.each_with_object({}) do |row, result|
result[row[0]] = row[1..-1]
end
4.times.map do |n|
{
:lock_status => rows["Ranging Status"][n],
:tx_power => rows["Power Level (dBmV)"][n],
}
end
end
private
def downstream_stats_page
@downstream_stats_page ||= Nokogiri::HTML(get_downstream_stats_page)
end
def upstream_stats_page
@upstream_stats_page ||= Nokogiri::HTML(get_upstream_stats_page)
end
def get_table(doc, caption)
doc.at_xpath("//table[.//caption[contains(., '#{caption}')]]")
end
def get_table_data(doc, caption)
table = get_table(doc, caption)
table.css('tr').map do |row|
row.css('th, td').map do |cell|
cell.text
end
end
end
def get_downstream_stats_page
get_page('/VmRouterStatus_downstream.asp')
end
def get_upstream_stats_page
get_page('/VmRouterStatus_upstream.asp')
end
def get_page(path)
Net::HTTP.get(@host, path)
end
end
if (ARGV[0] == 'config')
puts "host_name #{host}" unless host == 'localhost'
puts <<-EOT
multigraph locked_channels
graph_title Locked channels
graph_category network
graph_args -l 0
downstream.label Downstream
downstream.draw LINE1
upstream.label Upstream
upstream.draw LINE1
EOT
puts <<-EOT
multigraph downstream_snr
graph_title Downstream SNR
graph_category network
graph_vlabel dB
EOT
8.times do |i|
i += 1
puts "ch#{i}.label Channel #{i}"
puts "ch#{i}.draw LINE1"
end
puts <<-EOT
multigraph power_levels
graph_title Power Levels
graph_category network
graph_vlabel dBmV
EOT
8.times do |i|
i += 1
puts "rx#{i}.label RX Ch #{i}"
puts "rx#{i}.draw LINE1"
end
4.times do |i|
i += 1
puts "tx#{i}.label TX Ch #{i}"
puts "tx#{i}.draw LINE1"
end
exit 0
end
def strip_units(value)
value.gsub(/[^0-9.-]/, '')
end
stats = SuperhubStats.new(host)
downstream_details = stats.downstream_channel_details
upstream_details = stats.upstream_channel_details
puts "multigraph locked_channels"
puts "downstream.value #{downstream_details.select {|ch| ch[:lock_status] == "Locked"}.size}"
puts "upstream.value #{upstream_details.select {|ch| ch[:lock_status] == "Success"}.size}"
puts "multigraph downstream_snr"
downstream_details.each_with_index do |ch, i|
i += 1
if ch[:lock_status] == "Locked"
puts "ch#{i}.value #{strip_units(ch[:snr])}"
else
puts "ch#{i}.value U"
end
end
puts "multigraph power_levels"
downstream_details.each_with_index do |ch, i|
i += 1
if ch[:lock_status] == "Locked"
puts "rx#{i}.value #{strip_units(ch[:rx_power])}"
else
puts "rx#{i}.value U"
end
end
upstream_details.each_with_index do |ch, i|
i += 1
if ch[:lock_status] == "Success"
puts "tx#{i}.value #{strip_units(ch[:tx_power])}"
else
puts "tx#{i}.value U"
end
end