summaryrefslogtreecommitdiff
path: root/index.html
blob: 550e4d33fd1e86608ec7be8acff229629df2aa9b (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
<!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>untitled</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <script type="text/javascript" src="assets/javascript/jquery-1.4.2.min.js"></script>
        <script type="text/javascript" src="assets/javascript/flot/excanvas.min.js"></script>
        <script type="text/javascript" src="assets/javascript/flot/jquery.flot.js"></script>
        <script type="text/javascript" src="assets/javascript/flot/jquery.flot.stack.js"></script>
        <script type="text/javascript" src="assets/javascript/flot/jquery.flot.selection.js"></script>
        <script type="text/javascript" src="assets/javascript/javascriptrrd/binaryXHR.js"></script>
        <script type="text/javascript" src="assets/javascript/javascriptrrd/rrdFile.js"></script>
        <script type="text/javascript" src="assets/javascript/MochiKit/Base.js"></script>
        <script type="text/javascript" src="assets/javascript/MochiKit/Async.js"></script>
        <script type="text/javascript" src="jrrd.js"></script>
        <script type="text/javascript">

        var baseOptions = {
            grid: {
                clickable: true
            },
            selection: {
                mode: 'x'
            },
            series: {
                points: { show: false },
                lines: {
                    show: true,
                    steps: false,
                    shadowSize: 0,
                    lineWidth: 1
                },
                shadowSize: 0
            },
            xaxis: {
                mode: "time"
            }
        };

        var fillOptions = jQuery.extend(true, {
            series: {
                stack: true,
                lines: {
                    fill: 0.5
                }
            }
        }, baseOptions);

        function cpuChartFactory(template) {
            var c = new jrrd.Chart(template, fillOptions);
            data = 'cpu-user.rrd  cpu-system.rrd  cpu-wait.rrd'.split('  ').reverse();

            jQuery.each(data, function(i, el) {
                var url = 'data/localhost/cpu-0/' + el;
                var label = el.split('.')[0].split('-')[1];
                c.addData(label, new jrrd.RrdQueryRemote(url));
            });
            return c;
        }

        function memoryChartFactory(template) {
            var c = new jrrd.Chart(template, fillOptions);
            data = 'memory-free.rrd memory-cached.rrd memory-used.rrd memory-buffered.rrd'.split(' ').reverse();

            jQuery.each(data, function(i, el) {
                var url = 'data/localhost/memory/' + el;
                var label = el.split('.')[0].split('-')[1];
                c.addData(label, new jrrd.RrdQueryRemote(url));
            });
            return c;
        }

        var RrdQueryDsProxy = function(rrdQuery, dsId) {
            this.rrdQuery = rrdQuery;
            this.dsId = dsId;
        };

        RrdQueryDsProxy.prototype.getData = function(startTime, endTime) {
            return this.rrdQuery.getData(startTime, endTime, this.dsId);
        };

        function loadChartFactory(template) {
            var c = new jrrd.Chart(template, baseOptions);
            var data = new jrrd.RrdQueryRemote('data/localhost/load/load.rrd');
            var rrdDSs = ['shortterm', 'midterm', 'longterm'];
            jQuery.each(rrdDSs, function(i, rrdDS) {
                c.addData(rrdDS, new RrdQueryDsProxy(data, rrdDS));
            });
            return c;
        }

        $(function() {
            var chartTemplate = $('.chart').remove();
            var charts = [
                loadChartFactory(
                    chartTemplate.clone().appendTo('.charts')),

                cpuChartFactory(
                    chartTemplate.clone().appendTo('.charts')),

                memoryChartFactory(
                    chartTemplate.clone().appendTo('.charts'))
            ];

            jQuery.each(charts, function(i, chart) {
                chart.draw(new Date('7 April 2010 09:30:00'),
                           new Date('7 April 2010 15:00:00'));
            });

            $('.chart').bind("plotselected", function(event, ranges) {
                var startTime = new Date(ranges.xaxis.from);
                var endTime = new Date(ranges.xaxis.to);
                jQuery.each(charts, function(i, chart) {
                    chart.draw(startTime, endTime);
                });
            });
        });
        </script>
    </head>

    <body>
        <div class="charts">
            <div class="chart" style="width:800px; height:200px; float: right; clear: right;"></div>
        </div>
    </body>
</html>