hq-grapher-web 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hq/grapher-web/handler.rb +54 -2
- metadata +1 -1
@@ -68,7 +68,7 @@ class Handler
|
|
68
68
|
scale_steps = scale_elem.attributes["steps"].to_i
|
69
69
|
scale_rows = scale_elem.attributes["rows"].to_i
|
70
70
|
|
71
|
-
|
71
|
+
graph_spec = {
|
72
72
|
:start => Time.now.to_i - scale_steps * scale_rows,
|
73
73
|
:end => Time.now.to_i,
|
74
74
|
:width => scale_rows,
|
@@ -96,7 +96,9 @@ class Handler
|
|
96
96
|
:stack => output_elem.attributes["stack"] == "yes",
|
97
97
|
}
|
98
98
|
},
|
99
|
-
}
|
99
|
+
}
|
100
|
+
|
101
|
+
data = do_graph graph_spec
|
100
102
|
|
101
103
|
headers = {
|
102
104
|
"Content-Type" => "image/png"
|
@@ -110,6 +112,56 @@ class Handler
|
|
110
112
|
|
111
113
|
end
|
112
114
|
|
115
|
+
def self.do_graph graph_spec
|
116
|
+
|
117
|
+
Tempfile.open "mandar-rrd-" do
|
118
|
+
|tmp|
|
119
|
+
|
120
|
+
args = [
|
121
|
+
tmp.path,
|
122
|
+
"--start", graph_spec[:start],
|
123
|
+
"--end", graph_spec[:end],
|
124
|
+
"--width", graph_spec[:width],
|
125
|
+
"--height", graph_spec[:height],
|
126
|
+
"--slope-mode",
|
127
|
+
"--rigid",
|
128
|
+
]
|
129
|
+
|
130
|
+
args += graph_spec[:data].map {
|
131
|
+
|data|
|
132
|
+
[
|
133
|
+
"DEF",
|
134
|
+
"#{data[:name]}=#{data[:source_file]}",
|
135
|
+
data[:source_name],
|
136
|
+
data[:source_function].upcase,
|
137
|
+
].join(":")
|
138
|
+
}
|
139
|
+
|
140
|
+
args += graph_spec[:calc].map {
|
141
|
+
|calc|
|
142
|
+
"CDEF:#{calc[:name]}=#{calc[:rpn]}"
|
143
|
+
}
|
144
|
+
|
145
|
+
args += graph_spec[:outputs].map {
|
146
|
+
|output|
|
147
|
+
(
|
148
|
+
[
|
149
|
+
output[:type].upcase,
|
150
|
+
"#{output[:data]}\##{output[:colour]}",
|
151
|
+
output[:label],
|
152
|
+
] + (output[:stack] ? [ "STACK" ] : [])
|
153
|
+
).join(":")
|
154
|
+
}
|
155
|
+
|
156
|
+
RRD.graph *args
|
157
|
+
|
158
|
+
return File.read tmp.path
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
|
113
165
|
end
|
114
166
|
end
|
115
167
|
end
|