web metrics dashboard 数据分析工具 看板 从可视化发现问题 避免sql重复写 调高效率
<?php
$todo = array();
$done = array();
$h = array();
$v = $all['v'];
$l = count($v);
#19700101 08
for ($x = 1; $x < $l; $x++) {
$i = $v[$x];
#$todo[] = $i['tab_create_c'];
$todo[] = is_null($i['tab_create_c']) ? 0 : intval($i['tab_create_c']);
$done[] = is_null($i['tab_update_c']) ? 0 : intval($i['tab_update_c']);
$h[] = str_replace(" ", "-", $i['h']);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= $title; ?></title>
<style type="text/css">
#container {
/*min-width: 310px;*/
/*max-width: 800px;*/
/*height: 400px;*/
margin: 0 auto
}
</style>
</head>
<body>
<div id="container"></div>
<pre>
<?= $all['sql']; ?>
</pre>
</body>
</html>
<script src="../Highcharts-6.0.4/code/highcharts.js"></script>
<script src="../Highcharts-6.0.4/code/modules/series-label.js"></script>
<script src="../Highcharts-6.0.4/code/modules/exporting.js"></script>
<script type="text/javascript">
Highcharts.chart('container', {
title: {
text: '异常url数目检测效率监控'
},
subtitle: {
text: '单表查询:ad_direct_error_temp'
},
yAxis: {
title: {
text: '数据条数'
}
},
xAxis: {
title: {
text: '日期-时钟'
},
categories: [<?='"'.implode('","',$h).'"' ;?>]
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
series: {
label: {
connectorAllowed: false
},
// pointStart: <?//=strtotime($h[0].":00:00");?>
}
},
series: [{
name:<?="'".$all['todo']."'";?>,
data: [<?=implode(',',$todo) ;?>]
}
, {
name:<?="'".$all['done']."'";?>,
data: [<?=implode(',',$done) ;?>]
},
],
responsive: {
rules: [{
condition: {
// maxWidth: <?//=strtotime(end($h).":00:00")-strtotime($h[0].":00:00");?>
},
chartOptions: {
legend: {
layout: 'horizontal',
align: 'center',
verticalAlign: 'bottom'
}
}
}]
}
});
</script>
单条sql走天下
入库时间 更新时间 累计检测次数 时间全集 子集
SELECT h,tab_create_c,tab_update_c FROM ( SELECT DISTINCT h FROM ( SELECT FROM_UNIXTIME(create_time, '%Y%m%d %H') AS h FROM ad_direct_error_temp UNION ALL SELECT FROM_UNIXTIME(update_time, '%Y%m%d %H') AS h FROM ad_direct_error_temp ) AS tab_alltime ) AS tab_alltime_b LEFT JOIN ( SELECT FROM_UNIXTIME(create_time, '%Y%m%d %H') AS tab_create_h,COUNT(1) AS tab_create_c FROM ad_direct_error_temp GROUP BY tab_create_h ) AS tab_create ON tab_alltime_b.h=tab_create.tab_create_h LEFT JOIN ( SELECT FROM_UNIXTIME(update_time, '%Y%m%d %H') AS tab_update_h,COUNT(1) AS tab_update_c FROM ad_direct_error_temp WHERE no_ad_times+no_open_times>=script_need_run_times GROUP BY tab_update_h ) AS tab_update ON tab_alltime_b.h=tab_update.tab_update_h ORDER BY h ASC ;
问题时间段 定时任务调度异常
SELECT h,tab_create_c,tab_update_c FROM ( SELECT DISTINCT h FROM ( SELECT FROM_UNIXTIME(create_time, '%Y%m%d %H') AS h FROM ad_direct_error_temp UNION ALL SELECT FROM_UNIXTIME(update_time, '%Y%m%d %H') AS h FROM ad_direct_error_temp ) AS tab_alltime ) AS tab_alltime_b LEFT JOIN ( SELECT FROM_UNIXTIME(create_time, '%Y%m%d %H') AS tab_create_h,COUNT(1) AS tab_create_c FROM ad_direct_error_temp GROUP BY tab_create_h ) AS tab_create ON tab_alltime_b.h=tab_create.tab_create_h LEFT JOIN ( SELECT FROM_UNIXTIME(update_time, '%Y%m%d %H') AS tab_update_h,COUNT(1) AS tab_update_c FROM ad_direct_error_temp WHERE no_ad_times+no_open_times>=script_need_run_times GROUP BY tab_update_h ) AS tab_update ON tab_alltime_b.h=tab_update.tab_update_h ORDER BY h ASC ; ;