summaryrefslogtreecommitdiff
path: root/src/examples/rrdHeaderInfo.html
blob: 3a772d7c2f78e4eb058349405899266c4909bf4a (plain)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
 Example HTML/javascript file that display the
 header of a RRD archive files
 Part of the javascriptRRD package
 Copyright (c) 2009 Frank Wuerthwein, fkw@ucsd.edu

 Original repository: http://javascriptrrd.sourceforge.net/
 
 MIT License [http://www.opensource.org/licenses/mit-license.php]

-->

<html>
  
    <script type="text/javascript" src="../lib/binaryXHR.js"></script>
    <script type="text/javascript" src="../lib/rrdFile.js"></script>
  <head>
    <title>RRD Header Info</title>
  </head>

  <body>
    <h1 id="title">RRD Header Info</h1>

    RRD URL:
    <input type="text" id="input_fname" value="example1.rrd"
           onchange="input_update()">
     <button onclick="input_update()">Update</button>
    <hr>

    <table id="infotable" border=1>
        <tr><td colspan="5"><b>Javascript needed for this page to work</b></td></tr>
	<tr><td><b>RRD file</b></td><td id="fname" colspan="4">None</td></tr>
	<tr><td><b>Min Step</b></td><td id="step" align="right">N/A</td><td><b>Last update</b></td><td id="last_update" colspan="2">N/A</td></tr>
    </table>

    <script type="text/javascript">
      // Remove the Javascript warning
      document.getElementById("infotable").deleteRow(0);

      // fname is the global variable used by all the functions below
      fname=document.getElementById("input_fname").value;

      // This function updates the Web Page with the data from the RRD archive
      function update_info(fname,rrd_data) {
        // cleanup
        // rows may have been added during previous updates
        var oTable=document.getElementById("infotable");
        while (oTable.rows.length>=3) {
          oTable.deleteRow(2);
        } 

        // Generic header info
        document.getElementById("fname").firstChild.data=fname;
        document.getElementById("step").firstChild.data=rrd_data.getMinStep();
        document.getElementById("last_update").firstChild.data=rrd_data.getLastUpdate();

        // DS info
        var nrDSs=rrd_data.getNrDSs()
        var oRow=oTable.insertRow(-1);
        var oCell=oRow.insertCell(0);
        oCell.innerHTML="<b>DS list</b>";
        oCell.colSpan=5;
        for (var i=0; i<nrDSs; i++) {
          var oDS=rrd_data.getDS(i);
          oRow=oTable.insertRow(-1);
          oCell=oRow.insertCell(0)
          oCell.innerHTML="<b>"+oDS.getName()+"</b>";
          oCell=oRow.insertCell(1)
          oCell.innerHTML=oDS.getType();
          oCell.colSpan=4;
        }

        // RRA Info
        var nrRRAs=rrd_data.getNrRRAs()
        oRow=oTable.insertRow(-1);
        oCell=oRow.insertCell(0);
        oCell.innerHTML="<b>RRA list</b>";
        oCell.colSpan=5;
        for (var i=0; i<nrRRAs; i++) {
          var oRRA=rrd_data.getRRAInfo(i);
          oRow=oTable.insertRow(-1);
          oCell=oRow.insertCell(0)
          oCell.innerHTML=i;
          oCell.align="center";
          oCell=oRow.insertCell(1)
          oCell.innerHTML="<b>Rows</b>";
          oCell=oRow.insertCell(2)
          oCell.innerHTML=oRRA.getNrRows();
          oCell.align="right";
          oCell=oRow.insertCell(3)
          oCell.innerHTML="<b>Step</b>";
          oCell=oRow.insertCell(4)
          oCell.innerHTML=oRRA.getStep();
          oCell.align="right";
        }
      }      

      // This is the callback function that,
      // given a binary file object,
      // verifies that it is a valid RRD archive
      // and performs the update of the Web page
      function update_info_handler(bf) {
          var rrd_data=undefined;
          try {
            var rrd_data=new RRDFile(bf);            
          } catch(err) {
            alert("File "+fname+" is not a valid RRD archive!\n"+err);
          }
          if (rrd_data!=undefined) {
            update_info(fname,rrd_data)
          }
      }

      // this function is invoked when the RRD file name changes
      function input_update() {
        fname=document.getElementById("input_fname").value;
        try {
          FetchBinaryURLAsync(fname,update_info_handler);
        } catch (err) {
           alert("Failed loading "+fname+"\n"+err);
        }
      }

      // Uncomment this part if you want the Web page to load the
      // default RRD file at load time
      //
      //try {
      //  FetchBinaryURLAsync(fname,update_info_handler);
      //} catch (err) {
      //  alert("Failed loading "+fname+"\n"+err);
      //}
      
    </script>
  </body>
</html>