summaryrefslogtreecommitdiff
path: root/index.html
blob: c191051d59f29f8b87d1637a96f00e38b1a25e5d (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>RRD Charts</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />

        <link rel="stylesheet" type="text/css" href="http://flowplayer.org/tools/demos/dateinput/css/skin1.css" />
        <style type="text/css">
        body {
            font-family: sans;
            width: 800px;
            margin: 20px auto 0 auto;
        }

        form div {
            text-align: center;
        }

        h2 {
            padding: 0 0 0 55px;
            margin: 20px auto 5px auto;
            font-size: 14px;
            text-align: left;
        }

        .loading {
            background-repeat: no-repeat;
            background-position: 0 50%;
            background-image: url(/assets/icons/loading.gif);
        }

        .range-preview {
            height:50px;
            margin: 0 auto 0 auto;
            position: relative;
        }

        .chart {
            height:200px;
            margin: 0 auto 0 auto;
        }

        .chart canvas {
        }

        .tickLabel {
            width:50px;
            overflow:hidden;
        }

        .legendLabel {
            cursor: pointer;
        }

        .legend .disabled {
            text-decoration: line-through;
        }

        input[type=checkbox] {
            margin: 0;
            padding: 0;
            border: none;
        }

        .notice {
            border: 1px solid Green;
            background: #FFDDFF;
            margin-bottom: 20px;
            padding: 5px;
        }

        #calroot {
            z-index: 2;
        }
        </style>

        <script type="text/javascript" src="http://svn.mochikit.com/mochikit/trunk/MochiKit/Base.js"></script>
        <script type="text/javascript" src="http://svn.mochikit.com/mochikit/trunk/MochiKit/Async.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://flot.googlecode.com/svn/trunk/excanvas.min.js"></script>
        <script type="text/javascript" src="http://flot.googlecode.com/svn/trunk/jquery.flot.js"></script>
        <script type="text/javascript" src="http://flot.googlecode.com/svn/trunk/jquery.flot.stack.js"></script>
        <script type="text/javascript" src="http://flot.googlecode.com/svn/trunk/jquery.flot.selection.js"></script>

        <script type="text/javascript" src="http://javascriptrrd.cvs.sourceforge.net/viewvc/*checkout*/javascriptrrd/v0/src/lib/binaryXHR.js?revision=1.5&content-type=text%2Fplain"></script>
        <script type="text/javascript" src="http://javascriptrrd.cvs.sourceforge.net/viewvc/*checkout*/javascriptrrd/v0/src/lib/rrdFile.js?revision=1.8&content-type=text%2Fplain"></script>

        <script type="text/javascript" src="http://cdn.jquerytools.org/1.2.2/all/jquery.tools.min.js"></script>

        <script type="text/javascript" src="jrrd.js"></script>
        <script type="text/javascript">
        // Options common to all the chart on this page
        var baseOptions = {
            grid: {
                clickable: false,
                borderWidth: 1,
                borderColor: "#000",
                color: "#000",
                backgroundColor: "#fff",
                tickColor: "#eee"
            },
            legend: {
                position: 'nw',
                noColumns: 2
            },
            selection: {
                mode: 'x'
            },
            series: {
                points: { show: false },
                lines: {
                    show: true,
                    steps: false,
                    shadowSize: 0,
                    lineWidth: 1
                },
                shadowSize: 0
            },
            xaxis: {
                mode: "time"
            }
        };

        // Extra options to generate a stacked chart
        var stacked = {
            series: {
                stack: true,
                lines: {
                    fill: 0.5
                }
            }
        };

        // Recipes for the charts on this page
        var recipes = [
            {
                title: 'CPU Usage',
                data: [
                    ['data/cpu-0/cpu-wait.rrd', 0, 'CPU-0 Wait', 'Jiffies'],
                    ['data/cpu-1/cpu-wait.rrd', 0, 'CPU-1 Wait', 'Jiffies'],
                    ['data/cpu-0/cpu-system.rrd', 0, 'CPU-0 System', 'Jiffies'],
                    ['data/cpu-1/cpu-system.rrd', 0, 'CPU-1 System', 'Jiffies'],
                    ['data/cpu-0/cpu-user.rrd', 0, 'CPU-0 User', 'Jiffies'],
                    ['data/cpu-1/cpu-user.rrd', 0, 'CPU-1 User', 'Jiffies']
                ],
                options: jQuery.extend(true, {}, baseOptions, stacked)
            },

            {
                title: 'Memory',
                data: [
                    ['data/memory/memory-buffered.rrd', 0, 'Buffered', 'B'],
                    ['data/memory/memory-used.rrd', 0, 'Used', 'B'],
                    ['data/memory/memory-cached.rrd', 0, 'Cached', 'B'],
                    ['data/memory/memory-free.rrd', 0, 'Free', 'B']
                ],
                options: jQuery.extend(true, {}, baseOptions, stacked)
            },

            {
                title: 'DNS Query Types',
                data: [
                    ['data/dns/dns_qtype-A.rrd', 0, 'A', 'Q/sec'],
                    ['data/dns/dns_qtype-PTR.rrd', 0, 'PTR', 'Q/sec'],
                    ['data/dns/dns_qtype-SOA.rrd', 0, 'SOA', 'Q/sec'],
                    ['data/dns/dns_qtype-SRV.rrd', 0, 'SRV', 'Q/sec']
                ],
                options: jQuery.extend(true, {}, baseOptions)
            },

            {
                title: 'DNS Return Codes',
                data: [
                    ['data/dns/dns_rcode-NOERROR.rrd', 0, 'NOERROR', 'Q/sec'],
                    ['data/dns/dns_rcode-NXDOMAIN.rrd', 0, 'NXDOMAIN', 'Q/sec'],
                    ['data/dns/dns_rcode-SERVFAIL.rrd', 0, 'SERVFAIL', 'Q/sec']
                ],
                options: jQuery.extend(true, {}, baseOptions)
            },

            {
                title: 'Load Average',
                data: [
                    ['data/load/load.rrd', 'shortterm', 'Short Term', ''],
                    ['data/load/load.rrd', 'midterm', 'Medium Term', ''],
                    ['data/load/load.rrd', 'longterm', 'Long Term', '']
                ],
                options: jQuery.extend(true, {}, baseOptions)
            },

            {
                title: 'Wlan0 Throughput',
                data: [
                    ['data/interface/if_octets-wlan0.rrd', 'tx', 'Transmit', 'b/sec'],
                    ['data/interface/if_octets-wlan0.rrd', 'rx', 'Receive', 'b/sec']
                ],
                options: jQuery.extend(true, {}, baseOptions)
            },
        ];

        $(function() {
            $(":date").dateinput({format: 'mmm dd yyyy', max: new Date()});
            // when first date input is changed
            $(":date[name=startTime]").data("dateinput").change(function() {
                $(":date[name=endTime]").data("dateinput").setMin(this.getValue(), true);
            });
            $(":date[name=endTime]").data("dateinput").change(function() {
                $(":date[name=startTime]").data("dateinput").setMax(this.getValue(), true);
            });
            var chartTemplate = $('.chart-container').remove();

            var cc = new jrrd.ChartCoordinator($('.chartRangeControl'));
            cc.charts = jQuery.map(recipes, function(recipe, i) {
                return jrrd.Chart.fromRecipe(
                    chartTemplate.clone().appendTo('.charts'), recipe);
            });

            // Update all charts when a selection is made on one of them
            $('.charts').bind("plotselected", function(event, ranges) {
                cc.setTimeRange(new Date(ranges.xaxis.from),
                                new Date(ranges.xaxis.to));
            });

            // Show a loading icon when a chart is being redrawn
            $('.chart-container').live('chart_loading', function(e) {
                $(this).find('.title').addClass('loading');
            });

            $('.chart-container').live('chart_loaded', function(e) {
                $(this).find('.title').removeClass('loading');
            });

            // Initialise all the charts
            cc.reset();
        });
        </script>
    </head>

    <body>
        <div class="notice">
            <p>To get this demo working, you will need to serve this page from a
            local webserver and serve the folder that contains your RRD files.</p>
        </div>

        <form method="GET" class="chartRangeControl">
            <div>
                <label>Start: <input type="date" name="startTime" /></label>
                <label>End: <input type="date" name="endTime" /></label>
                <input type="submit" value="Update" />
                <input type="reset" value="Reset" />
            </div>
            <div class="range-preview"></div>
        </form>
        <div class="charts">
            <div class="chart-container">
                <h2 class="title"></h2>
                <div class="chart"></div>
            </div>
        </div>
    </body>
</html>