Report abuse

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
    # Create a new graph object.
    @received_packets_graph = RRDGraph.new("received_packages_total")

    # Generate a new RRD. (This will just be skipped if there is already a RRD with that name)
    @received_packets_graph.create_rrd "--start NOW DS:packets:COUNTER:600:U:U RRA:AVERAGE:0.5:1:288"

    @packets = Packetstatistic.find :all,
                            :conditions => [ "timestamp > ?", @received_packets_graph.get_last_rrd_update ],
                            :order => "timestamp ASC"

    @packets.each do |p|
      @received_packets_graph.insert "#{p.timestamp}:#{p.packets}"
    end

    @graph_name = @received_packets_graph.get_name_of_graph

    # Build some options for the graph image.
    yesterday = (Time.now - 86400).to_i
    lines = [ "DEF:packets=" + @received_packets_graph.get_path_of_rrd + ":packets:AVERAGE CDEF:real=packets,10,\* AREA:real#eb7f00:'Received packets'" ]
    title = "Receiver Hamburg: AIS Pakete/Minute - " + Time.now.to_s
    width = "725"
    height = "100"
    options = "-Y -X 1"
    colors = {  "SHADEA" => "#555555",
                "SHADEB" => "#555555",
                "FONT" => "#FFFFFF",
                "BACK" => "#555555",
                "CANVAS" => "#555555",
                "GRID" => "#FFFFFF",
                "MGRID" => "#FFFFFF",
                "AXIS" => "#FFFFFF",
                "ARROW" => "#CCCCCC" }

    @received_packets_graph.update_image yesterday, Time.now.to_i, lines, title, width, height, colors, options

    # We can now display the graph's image with the show_graph helper.