├── DESCRIPTION.txt ├── INSTALL.txt ├── LICENSE.txt ├── README.txt ├── doc └── lib │ ├── binaryXHR_js.html │ ├── index.html │ ├── rrdFile_js.html │ ├── rrdFlotMatrix_js.html │ ├── rrdFlotSupport_js.html │ ├── rrdFlot_js.html │ └── rrdMultiFile_js.html ├── examples ├── example1.rrd ├── example2.rrd ├── example3.rrd ├── example4.rrd ├── example4_s1.rrd ├── example4_s2.rrd ├── example4_s3.rrd ├── index.html ├── rrdContent.js ├── rrdHeaderInfo.js ├── rrdJFlot.html ├── rrdJFlotTwo.html └── rrdMatrixFlot.html └── lib ├── binaryFile.js ├── rrdFile.js ├── rrdFilter.js ├── rrdFlot.js ├── rrdFlotMatrix.js ├── rrdFlotSupport.js └── rrdMultiFile.js /DESCRIPTION.txt: -------------------------------------------------------------------------------- 1 | javascriptRRD 2 | ============= 3 | 4 | javascriptRRD is Javascript implementation of a client side RRD tool. 5 | 6 | -------------------------------------------------------------------------------- /INSTALL.txt: -------------------------------------------------------------------------------- 1 | javascriptRRD installation 2 | ========================== 3 | 4 | Being Javascript an interpreted language, no compilation is needed. 5 | Just copy the files in the files located in the 6 | src/lib 7 | directory into a Web accessible location and use them. 8 | 9 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | javascriptRRD is licensed under the MIT License 2 | [http://www.opensource.org/licenses/mit-license.php] 3 | 4 | Copyright (c) 2010 Frank Wuerthwein, fkw@ucsd.edu 5 | Igor Sfiligoi, isfiligoi@ucsd.edu 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | 25 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | javascriptRRD 2 | ============= 3 | 4 | javascriptRRD package contains a set of Javascript libraries 5 | that can be used for reading RRD archives from any Web browser. 6 | Mozilla, Internet Explorer and Safari havae been tested. 7 | 8 | Being Javascript an interpreted language, no compilation is needed. 9 | Just copy the files in the files located in the 10 | src/lib 11 | directory into a Web accessible location and use them. 12 | 13 | The 14 | src/examples/ 15 | directory contain example Web pages that you can use as a template 16 | for writing your own Web Browser applications for accessing the 17 | RRD archives on your Web server. 18 | 19 | While the code itself tries to be self documenting, the 20 | doc/lib/ 21 | directory contains more detailed information about the libraries. 22 | 23 | -------------------------------------------------------------------------------- /doc/lib/binaryXHR_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | binaryXHR module 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 25 | 26 | 27 |

binaryXHR module

28 | 29 | 30 | 38 | 39 |
31 |
32 |

The binaryXHR Javascript 33 | module implements a set of functions and classes that can be 34 | used to retrieve binary files using the XMLHttpRequest 35 | API.

36 |
37 |
40 |

Overview

41 |

This module provides two functions, 42 | FetchBinaryURL and 43 | FetchBinaryURLAsync, 44 | that are wrappers around the 45 | XMLHttpRequest API 46 | and return an object of type 47 | BinaryFile. 48 | The first one implements a 49 | straight load, while the second one initiates an asynchronous 50 | operation handled by a callback function.

51 |

The BinaryFile class implements the methods needed to access the 52 | elements of the binary files, such as strings, integers and real 53 | numbers. 54 |

55 |

Both the functions and the class internally handle the differences 56 | between different Web Browsers, so the user of this module does not 57 | need to worry about them.

58 | 59 |

Function FetchBinaryURL

60 |
61 |

Load a binary file.

62 |

Arguments:

63 | 66 |

Output:

67 | 70 | 71 |

Function FetchBinaryURLAsync

72 |
73 |

Initiate an asynchronous binary load.

74 |

Arguments:

75 | 84 |

Output:

85 | 90 | 91 |

Class BinaryFile

92 |
93 |

This class implements the methods needed to access the content of 94 | the binary file.

95 |
96 | 97 | 98 | 99 | 100 | 101 | 104 | 107 | 108 | 109 | 110 | 111 | 114 | 117 | 118 | 119 | 122 | 125 | 126 | 127 | 130 | 135 | 136 | 137 | 140 | 144 | 145 | 146 | 149 | 152 | 153 | 154 | 157 | 162 | 163 | 164 | 167 | 171 | 172 | 173 | 176 | 180 | 181 | 182 | 185 | 191 | 192 | 193 | 196 | 199 | 200 | 201 | 204 | 209 | 210 | 211 | 214 | 217 | 218 | 219 |
102 |

Method

103 |
105 |

Description

106 |
112 |

getLength()

113 |
115 |

Return the number of bytes held by the object.

116 |
120 |

getByteAt(idx)

121 |
123 |

Return an 8 bit unsigned integer from offset idx.

124 |
128 |

getShortAt(idx)

129 |
131 |

Return a 16 bit little endian unsigned integer from offset 132 | idx. 133 |

134 |
138 |

getLongAt(idx)

139 |
141 |

Return a 32 bit little endian unsigned integer from offset 142 | idx.

143 |
147 |

getSByteAt(idx)

148 |
150 |

Return an 8 bit signed integer from offset idx.

151 |
155 |

getSShortAt(idx)

156 |
158 |

Return a 16 bit little endian signed integer from offset 159 | idx. 160 |

161 |
165 |

getSLongAt(idx)

166 |
168 |

Return a 32 bit little endian signed integer from offset 169 | idx.

170 |
174 |

getDoubleAt(idx)

175 |
177 |

Return a double float (64 bit little endian) from offset idx.

178 |

Return undefined if the value is not a float or is infinity.

179 |
183 |

getFastDoubleAt(idx)

184 |
186 |

Return a low resolution (20 bit mantissa) double flat 187 | obtained from the high 32 bits of the original little endian 188 | double float from offset idx.

189 |

Return undefined if the value is not a float or is infinity.

190 |
194 |

getCharAt(idx)

195 |
197 |

Get a character from offset idx.

198 |
202 |

getCStringAt(idx,maxlen)

203 |
205 |

Get a zero terminated string of limited size from offset idx. 206 | 207 |

208 |
212 |

getStringAt(idx,len)

213 |
215 |

Get a fixed length string from offset idx.

216 |
220 |
221 | 222 |

Exception class InvalidBinaryFile

223 |
224 |

This is a helper exception class that can be thrown while loading the binary file.

225 |


226 | 227 | 228 | 237 | 238 |
229 |
230 |

This module is part of the javascriptRRD 231 | package hosted at http://javascript.sourceforge.net. 232 |
It is licensed under the MIT 233 | license. 234 |

235 |
236 |
239 | 240 | 241 | -------------------------------------------------------------------------------- /doc/lib/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | javascriptRRD libraries 6 | 7 | 8 | 9 | 18 | 19 | 20 |

javascriptRRD libraries

21 |

The javascriptRRD package contains base three javascript modules:

22 | 32 |

Together they can be used to implement AJAX style applications.

33 |

The package also provides two classes, based on 34 | JFlot, 35 | that automate most of the graphing needs:

36 | 45 | 46 | 47 | 48 | 57 | 58 |
49 |
50 |

The javascriptRRD package 51 | is hosted at http://javascript.sourceforge.net. 52 |
It is licensed under the MIT 53 | license. 54 |

55 |
56 |
59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /doc/lib/rrdFile_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rrdFile module 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 25 | 26 | 27 |

rrdFile module

28 | 29 | 30 | 38 | 39 |
31 |
32 |

The rrdFile Javascript 33 | module implements a set of classes that can be used to extract 34 | information from RRD 35 | archives loaded as binary file objects.

36 |
37 |
40 |

Overview

41 |

The main class in this module is RRDFile. 42 | It interprets the given the binary file object and provides methods 43 | to decode the RRD 44 | information.

45 |

Class RRDFile

46 |

This is the main class of the package. It is also the only class 47 | the user ever needs to explicitly instantiate.

48 |

The RRDFile constructor has a single argument:

49 | 68 |

If the binary file is not a proper RRD 69 | file, an InvalidRRD exception will be 70 | thrown.

71 |

This class also implements the following methods:

72 |
73 | 74 | 75 | 76 | 77 | 78 | 81 | 84 | 85 | 86 | 87 | 88 | 91 | 95 | 96 | 97 | 100 | 104 | 105 | 106 | 109 | 114 | 115 | 116 | 119 | 124 | 125 | 126 | 129 | 137 | 138 | 139 | 142 | 146 | 147 | 148 | 151 | 156 | 157 | 158 | 161 | 166 | 167 | 168 |
79 |

Method

80 |
82 |

Description

83 |
89 |

getMinStep()

90 |
92 |

Return the base interval 93 | in seconds that was used to feed the RRD file.

94 |
98 |

getLastUpdate()

99 |
101 |

Return the timestamp of the last 102 | update.

103 |
107 |

getNrDSs()

108 |
110 |

Return the number of Data 111 | Sources present in the RRD file. 112 |

113 |
117 |

getDSNames()

118 |
120 |

Return the names of the Data 121 | Sources present in the RRD file. 122 |

123 |
127 |

getDS(id)

128 |
130 |

If id is a number, return an object of type RRDDS holding 131 | the information about the id-th Data 132 | Source.

133 |

If id is a string, return an object of type RRDDS holding 134 | the information about the Data 135 | Source with the requested name.

136 |
140 |

getNrRRAs()

141 |
143 |

Return the number of Round 144 | Robin Archives present in the RRD file.

145 |
149 |

getRRAInfo(n)

150 |
152 |

Return an object of type RRDRRAInfo 153 | holding the information about the n-th Round 154 | Robin Archive.

155 |
159 |

getRRA(n)

160 |
162 |

Return an object of type RRDRRA that 163 | can be used to access the values stored in the n-th Round 164 | Robin Archive.

165 |
169 |
170 |

Class RRDDS

171 |

This class implements the methods needed to access the information 172 | about a RRD 173 | Data Source.

174 |
175 | 176 | 177 | 178 | 179 | 180 | 183 | 186 | 187 | 188 | 189 | 190 | 193 | 196 | 197 | 198 | 201 | 204 | 205 | 206 | 209 | 213 | 214 | 215 | 218 | 224 | 225 | 226 | 229 | 230 | 231 |
181 |

Method

182 |
184 |

Description

185 |
191 |

getIdx()

192 |
194 |

Return which DS it is in the RRD file.

195 |
199 |

getName()

200 |
202 |

Return the name of the data source.

203 |
207 |

getType()

208 |
210 |

Return the type 211 | of the data source.

212 |
216 |

getMin()

217 |
219 |

Return the minimum and maximum value the data source can 220 | contain. 221 |

222 |

If either is not defined, undefined is returned.

223 |
227 |

getMax()

228 |
232 |
233 |

Class 234 | RRDRRAInfo

235 |

This class implements the methods needed to access the information 236 | about a Round 237 | Robin Archive.

238 |
239 | 240 | 241 | 242 | 243 | 244 | 247 | 250 | 251 | 252 | 253 | 254 | 257 | 260 | 261 | 262 | 265 | 268 | 269 | 270 | 273 | 276 | 277 | 278 | 281 | 285 | 286 | 287 | 290 | 293 | 294 | 295 |
245 |

Method

246 |
248 |

Description

249 |
255 |

getIdx()

256 |
258 |

Return which RRA it is in the RRD file.

259 |
263 |

getNrRows()

264 |
266 |

Return the number of rows in the RRA.

267 |
271 |

getStep()

272 |
274 |

Return the number of seconds between rows.

275 |
279 |

getCFName()

280 |
282 |

Return the Consolidation 283 | Function used by the RRA.

284 |
288 |

getPdpPerRow()

289 |
291 |

Return number of slots used for consolidation.

292 |
296 |
297 |

Class RRDRRA

298 |

This class implements the methods needed to access the content of 299 | a Round 300 | Robin Archive.

301 |
302 | 303 | 304 | 305 | 306 | 307 | 310 | 313 | 314 | 315 | 316 | 317 | 320 | 323 | 324 | 325 | 328 | 336 | 337 | 338 | 341 | 344 | 345 | 346 | 349 | 353 | 354 | 355 | 358 | 361 | 362 | 363 | 366 | 369 | 370 | 371 | 374 | 378 | 379 | 380 |
308 |

Method

309 |
311 |

Description

312 |
318 |

getIdx()

319 |
321 |

Return which RRA it is in the RRD file.

322 |
326 |

getCFName()

327 |
329 |

Return the Consolidation 330 | Function used by the RRA.

331 |

The current implementation only supports 332 | AVERAGE,MAXIMUM,MINIMUM and LAST.
Access to elements of any 333 | other CF is currently undefined. 334 |

335 |
339 |

getNrRows()

340 |
342 |

Return the number of rows in the RRA.

343 |
347 |

getNrDSs()

348 |
350 |

Return the number of Data 351 | Sources present in the RRA.

352 |
356 |

getStep()

357 |
359 |

Return the number of seconds between rows.

360 |
364 |

getEl(r,d)

365 |
367 |

Return the value for the d-th DS in the r-th row.

368 |
372 |

getElFast(row,ds)

373 |
375 |

Return the low-precision value for the d-th DS in the r-th 376 | row.

377 |
381 |
382 |

Exception 383 | class InvalidRRD

384 |

This is a helper exception class that can be thrown while 385 | interpreting the binary file object.

386 |



387 |

388 | 389 | 390 | 399 | 400 |
391 |
392 |

This module is part of the javascriptRRD 393 | package hosted at http://javascript.sourceforge.net. 394 |
It is licensed under the MIT 395 | license. 396 |

397 |
398 |
401 | 402 | 403 | -------------------------------------------------------------------------------- /doc/lib/rrdFlotMatrix_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rrdFlotMatrix module 6 | 7 | 8 | 9 | 10 | 11 | 23 | 24 | 25 |

rrdFlotMatrix module

26 | 27 | 28 | 37 | 38 |
29 |
30 |

The rrdFlotMatrix Javascript 31 | module implements a class used to represents a DS from a list of similar 32 | RDD archives 33 | as a Flot plot.

34 |

All RRDs must have the same step, the same DS names and the same number of RRAs.

35 |
36 |
39 |

Overview

40 |

This module provide a single class: rrdFlotMatrix.

41 |

Given a 42 | RRDFile object, this class 43 | creates an interactive 44 | Flot plot.

45 | 46 |

In order to use this module, you also need to include: 47 |

52 | 53 |

Class rrdFlotMatrix

54 |

The rrdFlotMatrix constructor has two to five arguments:

55 |
56 | 57 | 58 | 59 | 60 | 61 | 64 | 67 | 68 | 69 | 70 | 71 | 74 | 77 | 78 | 79 | 82 | 90 | 91 | 92 | 95 | 105 | 106 | 107 | 110 | 123 | 124 | 125 | 128 | 144 | 145 |
62 |

Argument

63 |
65 |

Description

66 |
72 |

html_id

73 |
75 |

ID of a HTML element, possibly a DIV.

76 |
80 |

rrd_files

81 |
83 |

A list of RRDs. Each element of the list contains a [rrd_id,rrd_file] pair. 84 |

    85 |
  • rrd_id - Logical name for the RRD. 86 |
  • rrd_file -An object of type RRDFile or equivalent. 87 |
88 |

89 |
93 |

ds_list (optional)

94 |
96 |

A list of DSes. Each element of the list contains a [ds_id,ds_title] pair. 97 |

    98 |
  • ds_id - Logical name for the DS (as accepted by 99 | RRDFile.getDS()). 100 |
  • ds_title - Name to display to the user. 101 |
102 |

103 |

If undefined, all the DS's of the RRD will be used.

104 |
108 |

graph_options (optional)

109 |
111 |

Global graphing options. See 112 | Flot documentation 113 | for more details.

114 |

The recognized elements and the default values are: 115 |

116 |   graph_options = {
117 |     legend: {position:"nw",noColumns:3},
118 |     lines: { show:true },
119 |     yaxis: { autoscaleMargin: 0.20},
120 |   };
121 | 

122 |
126 |

rrd_graph_options (optional)

127 |
129 |

Dictionary of graphing options. This must be a dictionary of rrd_id. 130 | Each element of the dictionary contains graphing options. See 131 | Flot documentation 132 | for more details.

133 |

The recognized elements and the default values are: 134 |

135 |    {
136 |      title: label  or rrd_name                          // this is what is displayed in the checkboxes
137 |      checked: true                                      // boolean
138 |      label: title or rrd_name                           // this is what is displayed in the legend
139 |      color: rrd_index                                   // see Flot docs for details
140 |      lines: { show:true, fill: true, fillColor:color }  // see Flot docs for details
141 |    }
142 | 

143 |
146 |
147 |

Once instatiated, the object will automatically draw the plot and handle user interaction.

148 | 149 | 150 | -------------------------------------------------------------------------------- /doc/lib/rrdFlotSupport_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rrdFlotSupport module 6 | 7 | 8 | 9 | 10 | 11 | 23 | 24 | 25 |

rrdFlotSupport module

26 | 27 | 28 | 36 | 37 |
29 |
30 |

The rrdFlotSupport Javascript module 31 | implements a set of commonly used functions an classes that may be used while plotting 32 | RRD files with 33 | Flot.

34 |
35 |
38 |

Overview

39 |

This module provides two types of support: 40 |

49 |

50 |

Function rrdDS2FlotSeries

51 |

This function extracts a specific DS from a specific RRA and returns an object that 52 | contains the data in format flot expects.

53 |

54 | Input parameters: 55 |

56 |
57 | 58 | 59 | 60 | 61 | 62 | 65 | 68 | 69 | 70 | 71 | 72 | 75 | 78 | 79 | 80 | 83 | 87 | 88 | 89 | 92 | 95 | 96 | 97 | 100 | 103 | 104 | 105 |
63 |

Parameter

64 |
66 |

Description

67 |
73 |

rrd_file

74 |
76 |

An object of type RRDFile or equivalent.

77 |
81 |

ds_id

82 |
84 |

Identifier of the desired DS (as accepted by 85 | RRDFile.getDS()).

86 |
90 |

rra_idx

91 |
93 |

Index of the desired RRA.

94 |
98 |

want_rounding

99 |
101 |

If not false, all timestamps will be truncated to the RRA step.

102 |
106 |
107 |

108 | The output is an object containing: 109 |

110 |
111 | 112 | 113 | 114 | 115 | 116 | 119 | 122 | 123 | 124 | 125 | 126 | 129 | 138 | 139 | 140 | 143 | 146 | 147 | 148 | 151 | 154 | 155 | 156 | 159 | 160 | 161 |
117 |

Attribute

118 |
120 |

Description

121 |
127 |

data

128 |
130 |

A list of datapoints suitable to be fed to Flot. Each element is a (Timestamp in ms, value) pair.

131 |

An example of use with Flot:
132 |

133 | var fd=rrdDS2FlotSeries(...);
134 | var plot = $.plot("#myplot", [{data:fd.data}], options);
135 | 
136 |

137 |
141 |

label

142 |
144 |

The DS name.

145 |
149 |

min

150 |
152 |

Min and max timestamp in ms.

153 |
157 |

max

158 |
162 |
163 |

Function rrdRRA2FlotObj

164 |

This function extracts a list of DSs from a specific RRA and returns an object that 165 | contains the data in format flot expects.

166 |

167 | Input parameters: 168 |

169 |
170 | 171 | 172 | 173 | 174 | 175 | 178 | 181 | 182 | 183 | 184 | 185 | 188 | 191 | 192 | 193 | 196 | 199 | 200 | 201 | 204 | 208 | 209 | 210 | 213 | 217 | 218 | 219 | 222 | 225 | 226 | 227 |
176 |

Parameter

177 |
179 |

Description

180 |
186 |

rrd_file

187 |
189 |

An object of type RRDFile or equivalent.

190 |
194 |

rra_idx

195 |
197 |

Index of the desired RRA.

198 |
202 |

ds_list

203 |
205 |

List of DS identifiers (as accepted by 206 | RRDFile.getDS()).

207 |
211 |

want_ds_labels

212 |
214 |

Should the DS names be included as labels in the output? 215 | (If false, only the order distinguishes the requested DSs)

216 |
220 |

want_rounding

221 |
223 |

If not false, all timestamps will be truncated to the RRA step.

224 |
228 |
229 |

230 | The output is an object containing: 231 |

232 |
233 | 234 | 235 | 236 | 237 | 238 | 241 | 244 | 245 | 246 | 247 | 248 | 251 | 262 | 263 | 264 | 267 | 270 | 271 | 272 | 275 | 276 | 277 |
239 |

Attribute

240 |
242 |

Description

243 |
249 |

data

250 |
252 |

A list of objects suitable to be fed to Flot. Each element is an object composed of two attributes:

    253 |
  • data - A list of (Timestamp in ms, value) pairs.
  • 254 |
  • label - The (optional) DS name.

255 |

An example of use with Flot:
256 |

257 | var fd=rrdDS2FlotObj(...);
258 | var plot = $.plot("#myplot", fd.data, options);
259 | 
260 |

261 |
265 |

min

266 |
268 |

Min and max timestamp in ms.

269 |
273 |

max

274 |
278 |
279 |

Function rrdRRAStackFlotObj

280 |

This function extracts a list of DSs from a specific RRA, stacks them as requested and 281 | returns an object that contains the data in format flot expects.

282 |

283 | Input parameters: 284 |

285 |
286 | 287 | 288 | 289 | 290 | 291 | 294 | 297 | 298 | 299 | 300 | 301 | 304 | 307 | 308 | 309 | 312 | 315 | 316 | 317 | 320 | 326 | 327 | 328 | 331 | 337 | 338 | 339 | 342 | 347 | 348 | 349 | 352 | 356 | 357 | 358 | 361 | 364 | 365 | 366 | 369 | 373 | 374 | 375 |
292 |

Parameter

293 |
295 |

Description

296 |
302 |

rrd_file

303 |
305 |

An object of type RRDFile or equivalent.

306 |
310 |

rra_idx

311 |
313 |

Index of the desired RRA.

314 |
318 |

ds_positive_stack_list

319 |
321 |

List of DS identifiers (as accepted by 322 | RRDFile.getDS()) 323 | to be stacked. All values must be positive if 324 | ds_negative_stack_list is not empty.

325 |
329 |

ds_negative_stack_list

330 |
332 |

List of DS identifiers (as accepted by 333 | RRDFile.getDS()) 334 | to be stacked. All values must be negative if 335 | ds_positive_stack_list is not empty.

336 |
340 |

ds_single_list

341 |
343 |

List of DS identifiers (as accepted by 344 | RRDFile.getDS()). 345 | No stacking for these ones.

346 |
350 |

want_ds_labels

351 |
353 |

Should the DS names be included as labels in the output? 354 | (If false, only the order distinguishes the requested DSs)

355 |
359 |

want_rounding

360 |
362 |

If not false, all timestamps will be truncated to the RRA step.

363 |
367 |

one_undefined_enough

368 |
370 |

If true, a whole stack is invalidated if a 371 | single element of the stack is invalid.

372 |
376 |
377 |

378 | The output is an object containing: 379 |

380 |
381 | 382 | 383 | 384 | 385 | 386 | 389 | 392 | 393 | 394 | 395 | 396 | 399 | 410 | 411 | 412 | 415 | 418 | 419 | 420 | 423 | 424 | 425 |
387 |

Attribute

388 |
390 |

Description

391 |
397 |

data

398 |
400 |

A list of objects suitable to be fed to Flot. Each element is an object composed of two attributes:

    401 |
  • data - A list of (Timestamp in ms, value) pairs.
  • 402 |
  • label - The (optional) DS name.

403 |

An example of use with Flot:
404 |

405 | var fd=rrdDS2FlotObj(...);
406 | var plot = $.plot("#myplot", fd.data, options);
407 | 
408 |

409 |
413 |

min

414 |
416 |

Min and max timestamp in ms.

417 |
421 |

max

422 |
426 |
427 |

Function rrdRRAMultiStackFlotObj

428 |

This function extracts a DS from a list of RRDs, using a specific RRA index, then stacks them and 429 | returns an object that contains the data in format flot expects.

430 |

431 | Input parameters: 432 |

433 |
434 | 435 | 436 | 437 | 438 | 439 | 442 | 445 | 446 | 447 | 448 | 449 | 452 | 460 | 461 | 462 | 465 | 468 | 469 | 470 | 473 | 477 | 478 | 479 | 482 | 486 | 487 | 488 | 491 | 494 | 495 | 496 | 499 | 503 | 504 | 505 |
440 |

Parameter

441 |
443 |

Description

444 |
450 |

rrd_files

451 |
453 |

A list of RRDs. Each element of the list contains a [rrd_id,rrd_file] pair. 454 |

    455 |
  • rrd_id - Logical name for the RRD. 456 |
  • rrd_file -An object of type RRDFile or equivalent. 457 |
458 |

459 |
463 |

rra_idx

464 |
466 |

Index of the desired RRA.

467 |
471 |

ds_id

472 |
474 |

DS indentifier (as accepted by 475 | RRDFile.getDS())

476 |
480 |

want_rrd_labels

481 |
483 |

Should the RRD names be included as labels in the output? 484 | (If false, only the order distinguishes the requested RRDs)

485 |
489 |

want_rounding

490 |
492 |

If not false, all timestamps will be truncated to the RRA step.

493 |
497 |

one_undefined_enough

498 |
500 |

If true, a whole stack is invalidated if a 501 | single element of the stack is invalid.

502 |
506 |
507 |

508 | The output is an object containing: 509 |

510 |
511 | 512 | 513 | 514 | 515 | 516 | 519 | 522 | 523 | 524 | 525 | 526 | 529 | 540 | 541 | 542 | 545 | 548 | 549 | 550 | 553 | 554 | 555 |
517 |

Attribute

518 |
520 |

Description

521 |
527 |

data

528 |
530 |

A list of objects suitable to be fed to Flot. Each element is an object composed of two attributes:

    531 |
  • data - A list of (Timestamp in ms, value) pairs.
  • 532 |
  • label - The (optional) DS name.

533 |

An example of use with Flot:
534 |

535 | var fd=rrdDS2FlotObj(...);
536 | var plot = $.plot("#myplot", fd.data, options);
537 | 
538 |

539 |
543 |

min

544 |
546 |

Min and max timestamp in ms.

547 |
551 |

max

552 |
556 |
557 |

Class rrdFlotSelection

558 |

Helper class to handle Flot selections. 559 |

560 |
561 | 562 | 563 | 564 | 565 | 566 | 569 | 572 | 573 | 574 | 575 | 576 | 579 | 582 | 583 | 584 | 587 | 590 | 591 | 592 | 595 | 600 | 601 | 602 | 605 | 610 | 611 | 612 | 615 | 622 | 623 | 624 | 627 | 634 | 635 | 636 |
567 |

Method

568 |
570 |

Description

571 |
577 |

reset()

578 |
580 |

Clear the selection. (isSet() will return False)

581 |
585 |

isSet()

586 |
588 |

Was a selection set?

589 |
593 |

setFromFlotRanges(ranges)

594 |
596 |

Set the selection to ranges.xaxis. See plotselected 597 | Flot 598 | event for more info on ranges. (isSet() will return True, and getFlotRanges() can now be called.)

599 |
603 |

getFlotRanges()

604 |
606 |

Return a ranges object. See plotselected 607 | Flot 608 | event for more info on ranges.

609 |
613 |

trim_flot_data(flot_data)

614 |
616 |

Create a new Flot data object by selecting only the data points within the current selection.

617 |

An example Flot data object is 618 |

619 | rrdDS2FlotObj(...).data
620 | 

621 |
625 |

trim_data(data_list)

626 |
628 |

Create a new data list by selecting only the data points within the current selection.

629 |

An example data list is 630 |

631 | rrdDS2FlotSeries(...).data
632 | 

633 |
637 |
638 |

Pseudo-example of use: 639 |

640 |   myplotplot.bind("plotselected", function (event, ranges) {
641 |       // do the zooming
642 |       selection_range.setFromFlotRanges(ranges);
643 |       graph_options.xaxis.min=ranges.xaxis.from;
644 |       graph_options.xaxis.max=ranges.xaxis.to;
645 |       mygraph = $.plot("#mygraph", selection_range.trim_flot_data(flot_data), graph_options);
646 |   });
647 | 
648 |

649 | 650 | 651 | -------------------------------------------------------------------------------- /doc/lib/rrdFlot_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rrdFlot module 6 | 7 | 8 | 9 | 10 | 11 | 23 | 24 | 25 |

rrdFlot module

26 | 27 | 28 | 36 | 37 |
29 |
30 |

The rrdFlot Javascript 31 | module implements a class used to represents a 32 | RDD archive 33 | as a Flot plot.

34 |
35 |
38 |

Overview

39 |

This module provide a single class: rrdFlot.

40 |

Given a 41 | RRDFile object, this class 42 | creates an interactive 43 | Flot plot.

44 | 45 |

In order to use this module, you also need to include: 46 |

51 | 52 |

Class rrdFlot

53 |

The rrdFlot constructor has two to four arguments:

54 |
55 | 56 | 57 | 58 | 59 | 60 | 63 | 66 | 67 | 68 | 69 | 70 | 73 | 76 | 77 | 78 | 81 | 84 | 85 | 86 | 89 | 102 | 103 | 104 | 107 | 125 | 126 |
61 |

Argument

62 |
64 |

Description

65 |
71 |

html_id

72 |
74 |

ID of a HTML element, possibly a DIV.

75 |
79 |

rrd_file

80 |
82 |

An object of type RRDFile, or equivalent.

83 |
87 |

graph_options (optional)

88 |
90 |

Global graphing options. See 91 | Flot documentation 92 | for more details.

93 |

The recognized elements and the default values are: 94 |

 95 |   graph_options = {
 96 |     legend: {position:"nw",noColumns:3},
 97 |     lines: { show:true },
 98 |     yaxis: { autoscaleMargin: 0.20},
 99 |   };
100 | 

101 |
105 |

ds_graph_options (optional)

106 |
108 |

Dictionary of graphing options. This must be a dictionary of DS_id. 109 | Each element of the dictionary contains graphing options. See 110 | Flot documentation 111 | for more details.

112 |

The recognized elements and the default values are: 113 |

114 |    {
115 |      title: label  or ds_name     // this is what is displayed in the checkboxes
116 |      checked: first_ds_in_list?   // boolean
117 |      label: title or ds_name      // this is what is displayed in the legend
118 |      color: ds_index              // see Flot docs for details
119 |      lines: { show:true }         // see Flot docs for details
120 |      yaxis: 1                     // can be 1 or 2
121 |      stack: 'none'                // other options are 'positive' and 'negative'
122 |    }
123 | 

124 |
127 |
128 |

Once instatiated, the object will automatically draw the plot and handle user interaction.

129 | 130 | 131 | -------------------------------------------------------------------------------- /doc/lib/rrdMultiFile_js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | rrdFile module 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 25 | 26 | 27 |

rrdMultiFile module

28 | 29 | 30 | 39 | 40 |
31 |
32 |

The rrdMultiFile 33 | Javascript module implements a set of classes that can be used 34 | to combine several RRDFile 35 | objects into one. They all implement the same interface as 36 | RRDFile.

37 |
38 |
41 |

Overview

42 |

The main class in this module is RRDFileSum. 43 | Given a list of similar RRDFile 44 | objects, it creates a new object that behaves like a RRDFile 45 | object where the input shave been summed up.

46 |

Class RRDFileSum

47 |

This is the main class of the package. It is also the only class 48 | the user ever needs to explicitly instantiate.

49 |

The RRDFileSum constructor has two argument:

50 | 58 |

This class implements the same interface as RRDFile.

59 |

Class RRDRRASum

60 |

This class implements the same interface as RRDRRA.

61 | 62 | 63 | 72 | 73 |
64 |
65 |

This module is part of the javascriptRRD 66 | package hosted at http://javascript.sourceforge.net. 67 |
It is licensed under the MIT 68 | license. 69 |

70 |
71 |
74 |



75 |

76 | 77 | 78 | -------------------------------------------------------------------------------- /examples/example1.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example1.rrd -------------------------------------------------------------------------------- /examples/example2.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example2.rrd -------------------------------------------------------------------------------- /examples/example3.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example3.rrd -------------------------------------------------------------------------------- /examples/example4.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example4.rrd -------------------------------------------------------------------------------- /examples/example4_s1.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example4_s1.rrd -------------------------------------------------------------------------------- /examples/example4_s2.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example4_s2.rrd -------------------------------------------------------------------------------- /examples/example4_s3.rrd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tjfontaine/javascript-rrd/1e5c7955285bf9cc272ac4336b21769cbcb82271/examples/example4_s3.rrd -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | javascriptRRD examples 4 | 5 | 6 |

javascriptRRD examples

7 | 8 | Example Web pages: 9 | 16 | 17 | Details about the libraries can be found on the 18 | libraries web page. 19 | 20 | 21 | 22 | 32 | 33 |
23 |
24 |

The javascriptRRD package 25 | is hosted at http://javascript.sourceforge.net. 26 |
It is licensed under the MIT 27 | license. 28 |

29 | 30 |
31 |
34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/rrdContent.js: -------------------------------------------------------------------------------- 1 | /* 2 | Example HTML/javascript file that display the 3 | content of a RRD archive file 4 | Part of the javascriptRRD package 5 | Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu 6 | 7 | Original repository: http://javascriptrrd.sourceforge.net/ 8 | 9 | MIT License [http://www.opensource.org/licenses/mit-license.php] 10 | */ 11 | 12 | /* 13 | This example will print out RRD content in integer format. 14 | Make sure all RRD values can fit in an integer 15 | */ 16 | var bf = require('../lib/binaryFile.js') 17 | var rrf = require('../lib/rrdFile.js') 18 | 19 | console.log('RRD Raw Content') 20 | var fname = 'example1.rrd' 21 | 22 | bf.FetchBinaryURLAsync(fname, function(binfile){ 23 | var rrd_data = new rrf.RRDFile(binfile) 24 | var nrDSs=rrd_data.getNrDSs() 25 | 26 | for (var i=0; i 2 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | RRD Graphs with Flot 36 | 37 | 38 | 39 |

RRD Graphs with Flot

40 | 41 | RRD URL: 42 | 44 | 45 |
46 | 47 | 48 | 49 | 50 |
Javascript needed for this page to work
RRD fileNone
51 | 52 |
53 | 54 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /examples/rrdJFlotTwo.html: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | RRD Graphs with Flot 37 | 38 | 39 | 40 |

RRD Graphs with Flot

41 | 42 | RRD URL: 43 |
44 |
45 | 46 |
47 | 48 | 49 | 50 | 51 |
Javascript needed for this page to work
RRD fileNoneNone
52 | 53 |
54 | 55 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /examples/rrdMatrixFlot.html: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | Graph multiple RRDs with Flot 36 | 37 | 38 | 39 |

Graph multiple RRDs with Flot

40 | 41 | RRD group: 42 | 43 |
44 | 45 | 46 | 47 | 48 |
Javascript needed for this page to work
RRD fileNone
49 | 50 |
51 | 52 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /lib/binaryFile.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * BinaryFile over XMLHttpRequest 4 | * Part of the javascriptRRD package 5 | * Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu 6 | * MIT License [http://www.opensource.org/licenses/mit-license.php] 7 | * 8 | * Original repository: http://javascriptrrd.sourceforge.net/ 9 | * 10 | * Based on: 11 | * Binary Ajax 0.1.5 12 | * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/ 13 | * MIT License [http://www.opensource.org/licenses/mit-license.php] 14 | */ 15 | 16 | var fs = require('fs') 17 | 18 | // ============================================================ 19 | // Exception class 20 | function InvalidBinaryFile(msg) { 21 | this.message=msg; 22 | this.name="Invalid BinaryFile"; 23 | } 24 | 25 | // pretty print 26 | InvalidBinaryFile.prototype.toString = function() { 27 | return this.name + ': "' + this.message + '"'; 28 | } 29 | 30 | // ===================================================================== 31 | // BinaryFile class 32 | // Allows access to element inside a binary stream 33 | function BinaryFile(strData, iDataOffset, iDataLength) { 34 | var data = strData; 35 | var dataOffset = iDataOffset || 0; 36 | var dataLength = 0; 37 | // added 38 | var doubleMantExpHi=Math.pow(2,-28); 39 | var doubleMantExpLo=Math.pow(2,-52); 40 | var doubleMantExpFast=Math.pow(2,-20); 41 | 42 | var fsstats = fs.fstatSync(data) 43 | dataLength = fsstats.size 44 | 45 | var buff = new Buffer(512) 46 | 47 | /*this.getRawData = function() { 48 | var buff = new Buffer(dataLength); 49 | var bytes = fs.readSync(data, buff, 0, dataLength); 50 | return buff; 51 | }*/ 52 | 53 | this.getByteAt = function(iOffset) { 54 | var bytes = fs.readSync(data, buff, 0, 1, iOffset + dataOffset) 55 | return buff[0]; 56 | } 57 | 58 | this.getLength = function() { 59 | return dataLength; 60 | } 61 | 62 | this.getSByteAt = function(iOffset) { 63 | var iByte = this.getByteAt(iOffset); 64 | if (iByte > 127) 65 | return iByte - 256; 66 | else 67 | return iByte; 68 | } 69 | 70 | this.getShortAt = function(iOffset) { 71 | var iShort = (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset) 72 | if (iShort < 0) iShort += 65536; 73 | return iShort; 74 | } 75 | 76 | this.getSShortAt = function(iOffset) { 77 | var iUShort = this.getShortAt(iOffset); 78 | if (iUShort > 32767) 79 | return iUShort - 65536; 80 | else 81 | return iUShort; 82 | } 83 | 84 | this.getLongAt = function(iOffset) { 85 | var bytes = fs.readSync(data, buff, 0, 4, iOffset) 86 | 87 | var iLong = (((((buff[3] << 8) + buff[2]) << 8) + buff[1]) << 8) + buff[0]; 88 | if (iLong < 0) iLong += 4294967296; 89 | return iLong; 90 | } 91 | 92 | this.getSLongAt = function(iOffset) { 93 | var iULong = this.getLongAt(iOffset); 94 | if (iULong > 2147483647) 95 | return iULong - 4294967296; 96 | else 97 | return iULong; 98 | } 99 | 100 | this.getStringAt = function(iOffset, iLength) { 101 | var bytes = fs.readSync(data, buff, iOffset, iLength, 0) 102 | return buff.toString('ascii', 0, bytes) 103 | } 104 | 105 | // Added 106 | this.getCStringAt = function(iOffset, iMaxLength) { 107 | 108 | /*var aStr = []; 109 | for (var i=iOffset,j=0;(i0);i++,j++) { 110 | aStr[j] = String.fromCharCode(this.getByteAt(i)); 111 | } 112 | return aStr.join("");*/ 113 | 114 | var bytes = fs.readSync(data, buff, 0, iMaxLength, iOffset) 115 | 116 | for(var i=0; i < bytes; i++) { 117 | var b = buff.toString('ascii', i, i+1) 118 | if(b == '\0') { 119 | var ret = buff.toString('ascii', 0, i) 120 | return ret 121 | } 122 | } 123 | 124 | return buff.toString('ascii', 0, bytes) 125 | } 126 | 127 | // Added 128 | this.getDoubleAt = function(iOffset) { 129 | var bytes = fs.readSync(data, buff, 0, 8, iOffset) 130 | 131 | var iSign=buff[7] >> 7; 132 | var iExpRaw=((buff[7] & 0x7F)<< 4) + (buff[6] >> 4); 133 | var iMantHi=((((((buff[6] & 0x0F) << 8) + buff[5]) << 8) + buff[4]) << 8) + buff[3]; 134 | var iMantLo=((((buff[2]) << 8) + buff[1]) << 8) + buff[0]; 135 | 136 | if (iExpRaw==0) return 0.0; 137 | if (iExpRaw==0x7ff) return undefined; 138 | 139 | var iExp=(iExpRaw & 0x7FF)-1023; 140 | 141 | var dDouble = ((iSign==1)?-1:1)*Math.pow(2,iExp)*(1.0 + iMantLo*doubleMantExpLo + iMantHi*doubleMantExpHi); 142 | return dDouble; 143 | } 144 | // added 145 | // Extracts only 4 bytes out of 8, loosing in precision (20 bit mantissa) 146 | this.getFastDoubleAt = function(iOffset) { 147 | var iByte5 = this.getByteAt(iOffset + 4), 148 | iByte6 = this.getByteAt(iOffset + 5), 149 | iByte7 = this.getByteAt(iOffset + 6), 150 | iByte8 = this.getByteAt(iOffset + 7); 151 | var iSign=iByte8 >> 7; 152 | var iExpRaw=((iByte8 & 0x7F)<< 4) + (iByte7 >> 4); 153 | var iMant=((((iByte7 & 0x0F) << 8) + iByte6) << 8) + iByte5; 154 | 155 | if (iExpRaw==0) return 0.0; 156 | if (iExpRaw==0x7ff) return undefined; 157 | 158 | var iExp=(iExpRaw & 0x7FF)-1023; 159 | 160 | var dDouble = ((iSign==1)?-1:1)*Math.pow(2,iExp)*(1.0 + iMant*doubleMantExpFast); 161 | return dDouble; 162 | } 163 | 164 | this.getCharAt = function(iOffset) { 165 | return String.fromCharCode(this.getByteAt(iOffset)); 166 | } 167 | } 168 | 169 | 170 | // =============================================================== 171 | // Load a binary file from the specified URL 172 | // Will return an object of type BinaryFile 173 | function FetchBinaryURL(url) { 174 | return new BinaryFile(fs.openSync(url, 'r')); 175 | } 176 | 177 | 178 | // =============================================================== 179 | // Asyncronously load a binary file from the specified URL 180 | // 181 | // callback must be a function with one or two arguments: 182 | // - bf = an object of type BinaryFile 183 | // - optional argument object (used only if callback_arg not undefined) 184 | function FetchBinaryURLAsync(url, callback, callback_arg) { 185 | fs.open(url, 'r', function(err, fd) { 186 | callback(new BinaryFile(fd), callback_arg) 187 | }); 188 | } 189 | 190 | exports.BinaryFile = BinaryFile; 191 | exports.FetchBinaryURL = FetchBinaryURL; 192 | exports.FetchBinaryURLAsync = FetchBinaryURLAsync; -------------------------------------------------------------------------------- /lib/rrdFile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Client library for access to RRD archive files 3 | * Part of the javascriptRRD package 4 | * Copyright (c) 2009-2010 Frank Wuerthwein, fkw@ucsd.edu 5 | * Igor Sfiligoi, isfiligoi@ucsd.edu 6 | * 7 | * Original repository: http://javascriptrrd.sourceforge.net/ 8 | * 9 | * MIT License [http://www.opensource.org/licenses/mit-license.php] 10 | * 11 | */ 12 | 13 | /* 14 | * 15 | * RRDTool has been developed and is maintained by 16 | * Tobias Oether [http://oss.oetiker.ch/rrdtool/] 17 | * 18 | * This software can be used to read files produced by the RRDTool 19 | * but has been developed independently. 20 | * 21 | * Limitations: 22 | * 23 | * This version of the module assumes RRD files created on linux 24 | * with intel architecture and supports both 32 and 64 bit CPUs. 25 | * All integers in RRD files are suppoes to fit in 32bit values. 26 | * 27 | * Only versions 3 and 4 of the RRD archive are supported. 28 | * 29 | * Only AVERAGE,MAXIMUM,MINIMUM and LAST consolidation functions are 30 | * supported. For all others, the behaviour is at the moment undefined. 31 | * 32 | */ 33 | 34 | /* 35 | * Dependencies: 36 | * 37 | * The data provided to this module require an object of a class 38 | * that implements the following methods: 39 | * getByteAt(idx) - Return a 8 bit unsigned integer at offset idx 40 | * getLongAt(idx) - Return a 32 bit unsigned integer at offset idx 41 | * getDoubleAt(idx) - Return a double float at offset idx 42 | * getFastDoubleAt(idx) - Similar to getDoubleAt but with less precision 43 | * getCStringAt(idx,maxsize) - Return a string of at most maxsize characters 44 | * that was 0-terminated in the source 45 | * 46 | * The BinaryFile from binaryXHR.js implements this interface. 47 | * 48 | */ 49 | 50 | 51 | // ============================================================ 52 | // Exception class 53 | function InvalidRRD(msg) { 54 | this.message=msg; 55 | this.name="Invalid RRD"; 56 | } 57 | 58 | // pretty print 59 | InvalidRRD.prototype.toString = function() { 60 | return this.name + ': "' + this.message + '"'; 61 | } 62 | 63 | 64 | // ============================================================ 65 | // RRD DS Info class 66 | var RRDDS = exports.RRDDS = function (rrd_data,rrd_data_idx,my_idx) { 67 | this.rrd_data=rrd_data; 68 | this.rrd_data_idx=rrd_data_idx; 69 | this.my_idx=my_idx; 70 | } 71 | 72 | RRDDS.prototype.getIdx = function() { 73 | return this.my_idx; 74 | } 75 | RRDDS.prototype.getName = function() { 76 | return this.rrd_data.getCStringAt(this.rrd_data_idx,20); 77 | } 78 | RRDDS.prototype.getType = function() { 79 | return this.rrd_data.getCStringAt(this.rrd_data_idx+20,20); 80 | } 81 | RRDDS.prototype.getMin = function() { 82 | return this.rrd_data.getDoubleAt(this.rrd_data_idx+48); 83 | } 84 | RRDDS.prototype.getMax = function() { 85 | return this.rrd_data.getDoubleAt(this.rrd_data_idx+56); 86 | } 87 | 88 | 89 | // ============================================================ 90 | // RRD RRA Info class 91 | var RRDRRAInfo = exports.RRDRRAInfo = function (rrd_data,rra_def_idx, 92 | rrd_align,row_cnt,pdp_step,my_idx) { 93 | this.rrd_data=rrd_data; 94 | this.rra_def_idx=rra_def_idx; 95 | this.rrd_align=rrd_align; 96 | this.row_cnt=row_cnt; 97 | this.pdp_step=pdp_step; 98 | this.my_idx=my_idx; 99 | } 100 | 101 | RRDRRAInfo.prototype.getIdx = function() { 102 | return this.my_idx; 103 | } 104 | 105 | // Get number of rows 106 | RRDRRAInfo.prototype.getNrRows = function() { 107 | return this.row_cnt; 108 | } 109 | 110 | // Get number of slots used for consolidation 111 | // Mostly for internal use 112 | RRDRRAInfo.prototype.getPdpPerRow = function() { 113 | if (this.rrd_align==32) 114 | return this.rrd_data.getLongAt(this.rra_def_idx+24,20); 115 | else 116 | return this.rrd_data.getLongAt(this.rra_def_idx+32,20); 117 | } 118 | 119 | // Get RRA step (expressed in seconds) 120 | RRDRRAInfo.prototype.getStep = function() { 121 | return this.pdp_step*this.getPdpPerRow(); 122 | } 123 | 124 | // Get consolidation function name 125 | RRDRRAInfo.prototype.getCFName = function() { 126 | return this.rrd_data.getCStringAt(this.rra_def_idx,20); 127 | } 128 | 129 | 130 | // ============================================================ 131 | // RRD RRA handling class 132 | var RRDRRA = exports.RRDRRA = function (rrd_data,rra_ptr_idx, 133 | rra_info, 134 | header_size,prev_row_cnts,ds_cnt) { 135 | this.rrd_data=rrd_data; 136 | this.rra_info=rra_info; 137 | this.row_cnt=rra_info.row_cnt; 138 | this.ds_cnt=ds_cnt; 139 | 140 | var row_size=ds_cnt*8; 141 | 142 | this.base_rrd_db_idx=header_size+prev_row_cnts*row_size; 143 | 144 | // get imediately, since it will be needed often 145 | this.cur_row=rrd_data.getLongAt(rra_ptr_idx); 146 | 147 | // calculate idx relative to base_rrd_db_idx 148 | // mostly used internally 149 | this.calc_idx = function(row_idx,ds_idx) { 150 | if ((row_idx>=0) && (row_idx=0) && (ds_idx=this.row_cnt) real_row_idx-=this.row_cnt; 155 | return row_size*real_row_idx+ds_idx*8; 156 | } else { 157 | throw RangeError("DS idx ("+ row_idx +") out of range [0-" + ds_cnt +")."); 158 | } 159 | } else { 160 | throw RangeError("Row idx ("+ row_idx +") out of range [0-" + this.row_cnt +")."); 161 | } 162 | } 163 | } 164 | 165 | RRDRRA.prototype.getIdx = function() { 166 | return this.rra_info.getIdx(); 167 | } 168 | 169 | // Get number of rows/columns 170 | RRDRRA.prototype.getNrRows = function() { 171 | return this.row_cnt; 172 | } 173 | RRDRRA.prototype.getNrDSs = function() { 174 | return this.ds_cnt; 175 | } 176 | 177 | // Get RRA step (expressed in seconds) 178 | RRDRRA.prototype.getStep = function() { 179 | return this.rra_info.getStep(); 180 | } 181 | 182 | // Get consolidation function name 183 | RRDRRA.prototype.getCFName = function() { 184 | return this.rra_info.getCFName(); 185 | } 186 | 187 | RRDRRA.prototype.getEl = function(row_idx,ds_idx) { 188 | return this.rrd_data.getDoubleAt(this.base_rrd_db_idx+this.calc_idx(row_idx,ds_idx)); 189 | } 190 | 191 | // Low precision version of getEl 192 | // Uses getFastDoubleAt 193 | RRDRRA.prototype.getElFast = function(row_idx,ds_idx) { 194 | return this.rrd_data.getFastDoubleAt(this.base_rrd_db_idx+this.calc_idx(row_idx,ds_idx)); 195 | } 196 | 197 | // ============================================================ 198 | // RRD Header handling class 199 | var RRDHeader = exports.RRDHeader = function (rrd_data) { 200 | this.rrd_data=rrd_data; 201 | this.validate_rrd(); 202 | this.load_header(); 203 | this.calc_idxs(); 204 | } 205 | 206 | // Internal, used for initialization 207 | RRDHeader.prototype.validate_rrd = function() { 208 | if (this.rrd_data.getCStringAt(0,4)!=="RRD") throw new InvalidRRD("Wrong magic id."); 209 | 210 | this.rrd_version=this.rrd_data.getCStringAt(4,5); 211 | if ((this.rrd_version!=="0003")&&(this.rrd_version!=="0004")) { 212 | throw new InvalidRRD("Unsupported RRD version "+this.rrd_version+"."); 213 | } 214 | 215 | if (this.rrd_data.getDoubleAt(12)==8.642135e+130) { 216 | this.rrd_align=32; 217 | } else if (this.rrd_data.getDoubleAt(16)==8.642135e+130) { 218 | this.rrd_align=64; 219 | } else { 220 | throw new InvalidRRD("Unsupported platform."); 221 | } 222 | } 223 | 224 | // Internal, used for initialization 225 | RRDHeader.prototype.load_header = function() { 226 | if (this.rrd_align==32) { 227 | this.ds_cnt=this.rrd_data.getLongAt(20,false); 228 | this.rra_cnt=this.rrd_data.getLongAt(24,false); 229 | this.pdp_step=this.rrd_data.getLongAt(28,false); 230 | // 8*10 unused values follow 231 | this.top_header_size=112; 232 | } else { 233 | //get only the low 32 bits, the high 32 should always be 0 234 | this.ds_cnt=this.rrd_data.getLongAt(24,false); 235 | this.rra_cnt=this.rrd_data.getLongAt(32,false); 236 | this.pdp_step=this.rrd_data.getLongAt(40,false); 237 | // 8*10 unused values follow 238 | this.top_header_size=128; 239 | } 240 | } 241 | 242 | // Internal, used for initialization 243 | RRDHeader.prototype.calc_idxs = function() { 244 | this.ds_def_idx=this.top_header_size; 245 | // char ds_nam[20], char dst[20], unival par[10] 246 | this.ds_el_size=120; 247 | 248 | this.rra_def_idx=this.ds_def_idx+this.ds_el_size*this.ds_cnt; 249 | // char cf_nam[20], uint row_cnt, uint pdp_cnt, unival par[10] 250 | this.row_cnt_idx; 251 | if (this.rrd_align==32) { 252 | this.rra_def_el_size=108; 253 | this.row_cnt_idx=20; 254 | } else { 255 | this.rra_def_el_size=120; 256 | this.row_cnt_idx=24; 257 | } 258 | 259 | this.live_head_idx=this.rra_def_idx+this.rra_def_el_size*this.rra_cnt; 260 | // time_t last_up, int last_up_usec 261 | if (this.rrd_align==32) { 262 | this.live_head_size=8; 263 | } else { 264 | this.live_head_size=16; 265 | } 266 | 267 | this.pdp_prep_idx=this.live_head_idx+this.live_head_size; 268 | // char last_ds[30], unival scratch[10] 269 | this.pdp_prep_el_size=112; 270 | 271 | this.cdp_prep_idx=this.pdp_prep_idx+this.pdp_prep_el_size*this.ds_cnt; 272 | // unival scratch[10] 273 | this.cdp_prep_el_size=80; 274 | 275 | this.rra_ptr_idx=this.cdp_prep_idx+this.cdp_prep_el_size*this.ds_cnt*this.rra_cnt; 276 | // uint cur_row 277 | if (this.rrd_align==32) { 278 | this.rra_ptr_el_size=4; 279 | } else { 280 | this.rra_ptr_el_size=8; 281 | } 282 | 283 | this.header_size=this.rra_ptr_idx+this.rra_ptr_el_size*this.rra_cnt; 284 | } 285 | 286 | // Optional initialization 287 | // Read and calculate row counts 288 | RRDHeader.prototype.load_row_cnts = function() { 289 | this.rra_def_row_cnts=[]; 290 | this.rra_def_row_cnt_sums=[]; // how many rows before me 291 | for (var i=0; i=0) && (idx=0) && (idx=0) && (ds_idx=0) && (ds_idx=0) && (idx=0) && (ds_idx=0) && (ds_idx=0) && (idx0) { 232 | for (var i=0; i0) { 301 | for (var i=0; i=1) { 307 | // wraparound, change them a little 308 | idiv=Math.floor(i/std_colors.length); 309 | c1=parseInt(color[1]+color[2],16); 310 | c2=parseInt(color[3]+color[4],16); 311 | c3=parseInt(color[5]+color[6],16); 312 | m1=Math.floor((c1-128)/Math.sqrt(idiv+1))+128; 313 | m2=Math.floor((c2-128)/Math.sqrt(idiv+1))+128; 314 | m3=Math.floor((c3-128)/Math.sqrt(idiv+1))+128; 315 | if (m1>15) s1=(m1).toString(16); else s1="0"+(m1).toString(16); 316 | if (m2>15) s2=(m2).toString(16); else s2="0"+(m2).toString(16); 317 | if (m3>15) s3=(m3).toString(16); else s3="0"+(m3).toString(16); 318 | color="#"+s1+s2+s3; 319 | } 320 | rrd_colors.push(color); 321 | } 322 | } 323 | } else { // single element is not treated as an array 324 | if (oCB.rrd.checked==true) { 325 | // no sense trying to stack a single element 326 | rrd_list.push(this.rrd_files[0]); 327 | rrd_colors.push(std_colors[0]); 328 | } 329 | } 330 | 331 | // then extract RRA data about those DSs... to be finished 332 | var flot_obj=rrdRRAMultiStackFlotObj(rrd_list,rra_idx,ds_id); 333 | 334 | // fix the colors, based on the position in the RRD 335 | for (var i=0; imax_ts)) { 244 | max_ts=rrd_last_update; 245 | } 246 | if ((min_ts==null) || (rrd_min_ts=0) && (row_delta no filtering 349 | 350 | var out_data=[]; 351 | for (var i=0; i=this.selection_min) && (nr<=this.selection_max)) { 355 | out_data.push(data_list[i]); 356 | } 357 | } 358 | return out_data; 359 | }; 360 | 361 | // ====================================== 362 | // Miscelabeous helper functions 363 | // ====================================== 364 | 365 | function rfs_format_time(s) { 366 | if (s<120) { 367 | return s+"s"; 368 | } else { 369 | var s60=s%60; 370 | var m=(s-s60)/60; 371 | if ((m<10) && (s60>9)) { 372 | return m+":"+s60+"min"; 373 | } if (m<120) { 374 | return m+"min"; 375 | } else { 376 | var m60=m%60; 377 | var h=(m-m60)/60; 378 | if ((h<12) && (m60>9)) { 379 | return h+":"+m60+"h"; 380 | } if (h<48) { 381 | return h+"h"; 382 | } else { 383 | var h24=h%24; 384 | var d=(h-h24)/24; 385 | if ((d<7) && (h24>0)) { 386 | return d+" days "+h24+"h"; 387 | } if (d<60) { 388 | return d+" days"; 389 | } else { 390 | var d30=d%30; 391 | var mt=(d-d30)/30; 392 | return mt+" months"; 393 | } 394 | } 395 | } 396 | 397 | } 398 | } 399 | -------------------------------------------------------------------------------- /lib/rrdMultiFile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Combine multiple rrdFiles into one object 3 | * It implements the same interface, but changing the content 4 | * 5 | * Part of the javascriptRRD package 6 | * Copyright (c) 2010 Igor Sfiligoi, isfiligoi@ucsd.edu 7 | * 8 | * Original repository: http://javascriptrrd.sourceforge.net/ 9 | * 10 | * MIT License [http://www.opensource.org/licenses/mit-license.php] 11 | * 12 | */ 13 | 14 | // ============================================================ 15 | // RRD RRA handling class 16 | function RRDRRASum(rra_list,offset_list,treat_undefined_as_zero) { 17 | this.rra_list=rra_list; 18 | this.offset_list=offset_list; 19 | this.treat_undefined_as_zero=treat_undefined_as_zero; 20 | this.row_cnt= this.rra_list[0].getNrRows(); 21 | } 22 | 23 | RRDRRASum.prototype.getIdx = function() { 24 | return this.rra_list[0].getIdx(); 25 | } 26 | 27 | // Get number of rows/columns 28 | RRDRRASum.prototype.getNrRows = function() { 29 | return this.row_cnt; 30 | } 31 | RRDRRASum.prototype.getNrDSs = function() { 32 | return this.rra_list[0].getNrDSs(); 33 | } 34 | 35 | // Get RRA step (expressed in seconds) 36 | RRDRRASum.prototype.getStep = function() { 37 | return this.rra_list[0].getStep(); 38 | } 39 | 40 | // Get consolidation function name 41 | RRDRRASum.prototype.getCFName = function() { 42 | return this.rra_list[0].getCFName(); 43 | } 44 | 45 | RRDRRASum.prototype.getEl = function(row_idx,ds_idx) { 46 | var outSum=0.0; 47 | for (var i in this.rra_list) { 48 | var offset=this.offset_list[i]; 49 | if ((row_idx+offset) undefined*/ 54 | val=undefined; 55 | } 56 | /* treat all undefines as 0 for now */ 57 | if (val==undefined) { 58 | if (this.treat_undefined_as_zero) { 59 | val=0; 60 | } else { 61 | /* if even one element is undefined, the whole sum is undefined */ 62 | outSum=undefined; 63 | break; 64 | } 65 | } 66 | outSum+=val; 67 | } 68 | return outSum; 69 | } 70 | 71 | // Low precision version of getEl 72 | // Uses getFastDoubleAt 73 | RRDRRASum.prototype.getElFast = function(row_idx,ds_idx) { 74 | var outSum=0.0; 75 | for (var i in this.rra_list) { 76 | var offset=this.offset_list[i]; 77 | if ((row_id+offset) undefined*/ 82 | val=undefined; 83 | } 84 | /* treat all undefines as 0 for now */ 85 | if (val==undefined) { 86 | if (this.treat_undefined_as_zero) { 87 | val=0; 88 | } else { 89 | /* if even one element is undefined, the whole sum is undefined */ 90 | outSum=undefined; 91 | break; 92 | } 93 | } 94 | outSum+=val; 95 | } 96 | return outSum; 97 | } 98 | 99 | /*** INTERNAL ** sort by lastupdate, descending ***/ 100 | 101 | function rrdFileSort(f1, f2) { 102 | return f2.getLastUpdate()-f1.getLastUpdate(); 103 | } 104 | 105 | /* 106 | * Sum several RRDfiles together 107 | * They must all have the same DSes and the same RRAs 108 | */ 109 | 110 | function RRDFileSum(file_list,treat_undefined_as_zero) { 111 | if (treat_undefined_as_zero==undefined) { 112 | this.treat_undefined_as_zero=true; 113 | } else { 114 | this.treat_undefined_as_zero=treat_undefined_as_zero; 115 | } 116 | this.file_list=file_list; 117 | this.file_list.sort(); 118 | 119 | // =================================== 120 | // Start of user functions 121 | 122 | this.getMinStep = function() { 123 | return this.file_list[0].getMinStep(); 124 | } 125 | this.getLastUpdate = function() { 126 | return this.file_list[0].getLastUpdate(); 127 | } 128 | 129 | this.getNrDSs = function() { 130 | return this.file_list[0].getNrDSs(); 131 | } 132 | 133 | this.getDSNames = function() { 134 | return this.file_list[0].getDSNames(); 135 | } 136 | 137 | this.getDS = function(id) { 138 | return this.file_list[0].getDS(id); 139 | } 140 | 141 | this.getNrRRAs = function() { 142 | return this.file_list[0].getNrRRAs(); 143 | } 144 | 145 | this.getRRAInfo = function(idx) { 146 | return this.file_list[0].getRRAInfo(idx); 147 | } 148 | 149 | this.getRRA = function(idx) { 150 | var rra_info=this.getRRAInfo(idx); 151 | var rra_step=rra_info.getStep(); 152 | var realLastUpdate=undefined; 153 | 154 | var rra_list=new Array(); 155 | var offset_list=new Array(); 156 | for (var i in this.file_list) { 157 | file=file_list[i]; 158 | fileLastUpdate=file.getLastUpdate(); 159 | if (realLastUpdate!=undefined) { 160 | fileSkrew=Math.floor((realLastUpdate-fileLastUpdate)/rra_step); 161 | } else { 162 | fileSkrew=0; 163 | firstLastUpdate=fileLastUpdate; 164 | } 165 | offset_list.push(fileSkrew); 166 | fileRRA=file.getRRA(idx); 167 | rra_list.push(fileRRA); 168 | } 169 | 170 | return new RRDRRASum(rra_list,offset_list,this.treat_undefined_as_zero); 171 | } 172 | 173 | } 174 | --------------------------------------------------------------------------------