Skip to content
Snippets Groups Projects
Commit f271d6cd authored by root's avatar root
Browse files

pridani statistiky unikatnich sources do megavyhledavace

parent 7cbbbc6e
Branches
Tags
No related merge requests found
<?
include("db.php");
if(!isset($_GET['per'])){$_GET['per']="hour";}
switch( $_GET['per']) {
case "hour":
$agg = 1;
break;
case "day":
$agg = 24;
break;
case "month":
$agg = 24*30; // -30.5 ?
break;
}
#sqli todo
#selector
if(!IsSet($_GET['where'])) {
$where="detected>from_unixtime(0)";
} else {
$where = base64_decode($_GET['where']);
}
#seznam sloupcu ve vysledku, todo dyn, coz je ovsem seznam sledovanych velicin
$cols=array();
$i=0;
$cols["count"]=$i++;
$count_cols=count($cols);
#select data
$data=array();
#casova posloupnost
# premapuju podle staticky alokovanych sloupcu, posilam to rovnou do grafu
$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, count(distinct source) as count FROM events WHERE $where GROUP BY t;";
#var_dump($q);
$res = mysql_query($q, $db);
while ($tmp = mysql_fetch_assoc($res)) {
#var_dump($tmp);
$d=array_fill(0, $count_cols, 0);
$d[ $cols[ "count" ] ] = (int)$tmp["count"];
array_unshift($d, (int)$tmp["t"]);
array_push($data, $d);
}
#print json_encode($d);
print json_encode(array("cols"=>array_keys($cols), "data"=>$data));
?>
<? if(!isset($_GET['per'])){$_GET['per']="day";} ?>
<html>
<head>
<script type="text/javascript" language="javascript" src="datatables/media/js/jquery.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(fetchData);
function fetchData() {
<? #TODO: fuj
if(!isSet($_GET['where'])) { ?>
$.getJSON('graph_HostnameServiceTypeActivityUniqSource.php?per=<? print $_GET['per'];?>', drawChart);
<? } else { ?>
$.getJSON('graph_HostnameServiceTypeActivityUniqSource.php?per=<? print $_GET['per'];?>&where=<?print $_GET['where'];?>', drawChart);
<? } ?>
}
function drawChart(sdata) {
//console.log(sdata);
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Date');
//console.log(sdata.cols);
for (var i = 0; i < sdata.cols.length; i++) {
data.addColumn('number', sdata.cols[i]);
}
sdatalen=sdata.data.length;
if(sdatalen > 1000) {
alert("Too many rows:"+sdatalen);
sdatalen=1000;
}
for (var i = 0; i < sdatalen; i++) {
//for (var i = 0; i < 10; i++) {
sdata.data[i][0] = new Date(sdata.data[i][0]*1000);
//console.log(sdata.data[i]);
data.addRow(sdata.data[i]);
}
var options = {
vAxis: { logScale: true, title: "count distinct source" },
interpolateNulls: true,
___colors:['#008000','#ff0000','#FFA500','#FA8072','#AFEEEE','#00A5C6','#DEBDDE','#000000'],
chartArea: {'width': '80%', 'height': '85%'},
pointSize: 5
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 100%; height: 100%;"></div>
</body>
</html>
......@@ -153,6 +153,18 @@ if( IsSet($_POST["btnSubmit"]) and !empty($where)) {
?>
</td>
</tr><tr>
<td></td>
<td width=50%>
<?
if( IsSet($_POST["btnSubmit"]) and !empty($where)) {
print("<iframe src=\"graph_HostnameServiceTypeActivityUniqSource_html.php?per=day&where=".base64_encode($where)."\" style=\"width:100%; height:500\"></iframe>");
}
?>
</td>
</tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment