Class: Lita::Handlers::Trisul

Inherits:
Handler
  • Object
show all
Extended by:
Lita::Handler::HTTPRouter
Defined in:
lib/lita/handlers/trisul.rb

Instance Method Summary collapse

Instance Method Details

#chart_generate(data) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/lita/handlers/trisul.rb', line 28

def chart_generate(data)
 mod1 = GerbilCharts::Models::TimeSeriesGraphModel.new("External Gateway")
 mod1.add_tuples data
 modgroup = GerbilCharts::Models::GraphModelGroup.new("Hosts")
 modgroup.add(mod1)
 mychart = GerbilCharts::Charts::AreaChart.new( :width => 750, :height => 250, :squarize => true,
                        :auto_tooltips => false,:style => 'inline:brushmetal.css' )
 mychart.setmodelgroup(modgroup)
 mychart.render('/tmp/chart.svg')
end

#example(request, response2) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/lita/handlers/trisul.rb', line 19

def example(request,response2)
 `rsvg-convert /tmp/chart.svg -o /tmp/chart.png`
 file=File.read("/tmp/chart.png")
 response2["Content-Type"] = "image/png"
 response2.write(file)
 response2.finish
end

#trpchart(response) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/lita/handlers/trisul.rb', line 43

def trpchart(response)
 if response.matches[0]=="hey" and ! response.matches[0].is_a?Array
  response.reply("Please enter hey <counter_group_id>")
 end
 tint = TRP::TimeInterval.new()
 tint.to=  TRP::Timestamp.new({:tv_sec=>Time.now.tv_sec})
 tint.from= TRP::Timestamp.new()
 tint.from.tv_sec = tint.to.tv_sec - 3600
 keyt = TRP::KeyT.new({:key=>"TOTALBW"})
 req = TrisulRP::Protocol.mk_request(TRP::Message::Command::COUNTER_ITEM_REQUEST,{:counter_group=>response.matches[0][0].strip,:key=>keyt,time_interval:tint})
 data = []
 TrisulRP::Protocol.get_response_zmq(config.trisul.trp_server_endpoint,req) do |resp|
  resp.stats.each do |stat|
    data << [ stat.ts_tv_sec,stat.values[0]*8]
  end#stats
 end#trp
 chart_generate(data)
 response.reply("http://#{config.trisul.local_http_server}/ers#{$id}.png")
 $id=rand(100)
end