--- /dev/null
+<?php
+try
+{
+ $db = new PDO("sqlite:/home/bdsm/etc/bdsm/bdsm.db");
+ $result = $db->query("SELECT DISTINCT host FROM MEASUREMENTS");
+}
+catch(PDOException $e)
+{
+ echo 'Connection failed: ' . $e->getMessage();
+}
+
+if( !$result )
+{
+ echo "Error: No data found in database file /home/bdsm/etc/bdsm/bdsm.db";
+ echo "Query: SELECT DISTINCT host FROM MEASUREMENTS";
+}
+
+$colors = Array("#55F", "#5C5", "#F55", "#5FF", "#F5F", "#FF5", "#555");
+
+$hosts = Array();
+while($host = $result->fetch())
+ if ( $host['host'] )
+ array_push($hosts, $host['host']);
+$host = urldecode($_GET['host']);
+
+if( !in_array($host, $hosts) )
+ die("Error: Host not found.");
+?>
+
+<HTML>
+ <HEAD>
+ <TITLE>bdsm at monitor.slightlycyberpunk.com | <?php echo $host; ?></TITLE>
+ </HEAD>
+ <BODY>
+ <canvas class="chart" id="chart-<?php echo $host; ?>" width="400px" height="450px"></canvas>
+ <script>
+ var canvas = document.getElementById("chart-<?php echo $host; ?>");
+ var context = canvas.getContext("2d");
+ context.lineWidth = 1;
+ context.strokeStyle = "#CCC";
+ for (var i = 50; i < 400; i+=50)
+ {
+ context.moveTo(i+.5, 0);
+ context.lineTo(i+.5, 400);
+ }
+ context.stroke();
+ context.beginPath();
+
+ context.strokeStyle = "#000";
+ for (var i = 50; i < 400; i+=50)
+ {
+ context.moveTo(0, i+.5);
+ context.lineTo(400, i+.5);
+ }
+
+ context.stroke();
+ context.beginPath();
+ context.lineWidth = 2;
+<?php
+ $result = $db->query("SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1;");
+ if( ! $result )
+ {
+ echo "</script><br/>";
+ echo "Error: No configuration found in database file /home/bdsm/etc/bdsm/bdsm.db for host $host<br/>";
+ echo "Query: SELECT attribute, name FROM bdsmweb WHERE host='$host' AND graph=1;";
+ die();
+ }
+
+ $attributes = Array();
+ while($attribute = $result->fetch())
+ {
+ if ( $attribute['attribute'] )
+ $attributes[$attribute['attribute']] = $attribute['name'];
+ }
+ $i = 0;
+
+ foreach (array_keys($attributes) as $attribute)
+ {
+ $query = "SELECT printf('%d', timestamp) AS timestamp,value ".
+ "FROM MEASUREMENTS ".
+ "WHERE host='$host' AND attribute='$attribute' ".
+ "ORDER BY timestamp DESC LIMIT 100";
+
+ $result = $db->query($query);
+ $record = $result->fetch();
+ $final = $record['timestamp'];
+ $timediff = time() - $final;
+
+ $timestamp = ($timediff % 60)."s";
+ if( $timediff > 60 )
+ $timestamp = (($timediff / 60) % 60)."m ".$timestamp;
+
+ echo " context.font = '12px monospace';";
+ echo " context.strokeStyle = '$colors[$i]';\n";
+ echo " context.strokeText('-$timestamp', 350.5, ".(10.5+10*$i).");\n";
+
+ //echo " context.strokeStyle = '$colors[$i]';\n";
+ echo " context.moveTo(0, ".sprintf("%d", $record['value']).");\n";
+ echo " context.beginPath();\n";
+ while( $record = $result->fetch() )
+ {
+ echo " context.lineTo(".sprintf("%d", $final - $record['timestamp']).", ".(400-$record['value']*4).");\n";
+ }
+ echo " context.stroke();\n";
+
+ $name = $attributes[$attribute];
+ echo " context.strokeText('$name', ".(100*($i%5)+.5).", ".(425+(10*floor($i/5))+.5).");";
+ $i+=1;
+ }
+?>
+
+ </script>
+ </BODY>
+</HTML>