debug) echo "init\n"; $this->db = $db; $this->limitTop = $limitTop; } // 사용자 수 public function GetCountUser($sdate, $edate) { //$sql = "select count(c.client_ip) as cnt from (select client_ip from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by client_ip) as c"; //$sql = "select count(DISTINCT client_ip) as cnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; $sql = "select count(DISTINCT client_ip) as cnt from stats_user where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } // 서버별 사용자 수 구하기 public function GetCountUserPerServer($sdate, $edate) { //$sql = "select c.server_ip, count(c.client_ip) as cnt from (select server_ip, client_ip from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip, client_ip) as c group by c.server_ip"; //$sql = "select c.server_ip, count(client_ip) as cnt from (select distinct server_ip, client_ip from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 00:59:59' ) as c group by c.server_ip"; $sql = "select c.server_ip, count(client_ip) as cnt from (select distinct server_ip, client_ip from stats_user where stats_time between '".$sdate." 00:00:00' and '".$edate." 00:59:59' ) as c group by c.server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } /* // Session public function GetCountSessions($sdate, $edate) { //$sql = "select count(*) as cnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; $sql = "select sum(server_sessions) as cnt from stats_server where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } // 서버별 Sessions 구하기 public function GetCountSessionsPerServer($sdate, $edate) { //$sql = "select server_ip, count(id) as cnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip"; $sql = "select server_ip, sum(server_sessions) as cnt from stats_server where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // 서비스/Tran 지연 수 public function GetCountWaitAndTrans($sdate, $edate) { $sql = "select sum(wait) as wcnt, sum(transaction_number) as tcnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } // 서버별 서비스 지연 수/Trans 구하기 public function GetCountWaitAndTransPerServer($sdate, $edate) { $sql = "select server_ip, sum(wait) as wcnt, sum(transaction_number) as tcnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } */ public function GetCountStatsServer($sdate, $edate) { $sql = "select sum(server_sessions) as csession, sum(server_transactions) as ctrns, avg(server_rtt) as server_rtt, avg(server_wait) as cwait, sum(rsp_400) as rsp_400, sum(rsp_500) as rsp_500, sum(rsp_304) as rsp_304, sum(rsp_200) as rsp_200, avg(latency) as latency from stats_server where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } public function GetCountStatsServerPerServer($sdate, $edate) { $sql = "select server_ip, sum(server_sessions) as csession, sum(server_transactions) as ctrns, avg(server_rtt) as server_rtt, avg(server_wait) as cwait, sum(rsp_400) as rsp_400, sum(rsp_500) as rsp_500, sum(rsp_304) as rsp_304, sum(rsp_200) as rsp_200, avg(latency) as latency from stats_server where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // 알람 수 public function GetCountAlarm($sdate, $edate) { $sql = "select count(alert_count) as cnt from detail_alert where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } // 서버별 알람 수 구하기 public function GetCountAlarmPerServer($sdate, $edate) { $sql = "select server_ip, count(alert_count) as cnt from detail_alert where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } /* // 40X, 50X 에러수 public function GetCount40X50X($sdate, $edate, $opt) { if ($opt == "40x") $str_between = " between 400 and 499 "; else if ($opt == "50x") $str_between = " between 500 and 599 "; else $str_between = " between 400 and 599 "; $sql = "select count(response_code_number) as cnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and response_code_number ".$str_between; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } // 서버별 40X, 50X 에러수 구하기 public function GetCount40X50XPerServer($sdate, $edate, $opt) { if ($opt == "40x") $str_between = " between 400 and 499 "; else if ($opt == "50x") $str_between = " between 500 and 599 "; else $str_between = " between 400 and 599 "; $sql = "select server_ip, count(response_code_number) as cnt from detail_session where start_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and response_code_number ".$str_between." group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } */ // 서버별 어플리케이션 TOP public function GetAppTopPerServer($sdate, $edate) { // 서버 개수를 구한 후 해당 서버에 대한 정보를 구하는 것으로 변경 $sql = "select server_ip from stats_url_total where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip order by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_server = array(); while($data = mysql_fetch_assoc($result)) { $rec_server[] = $data; } unset($result); if ($this->debug) print_r($rec_server); $rec_ret = array(); for ($i = 0 ; $i < sizeof($rec_server) ; $i ++ ) { $sql = "select server_ip, url, sum(url_user) as cuser ,sum(url_sessions) as csession, sum(url_transactions) as ctrns, sum(rsp_400) as rsp_400, sum(rsp_500) as rsp_500, avg(latency) as latency, avg(url_wait) as cwait from stats_url_total where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and server_ip='".$rec_server[$i]['server_ip']."' group by url order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); while($data = mysql_fetch_assoc($result)) { if ($data['url'] == "") continue; $rec_ret[] = $data; } unset($result); } unset($rec_server); return $rec_ret; } // 서버별 유입 TOP public function GetRefererTopPerServer($sdate, $edate) { $sql = "select server_ip from stats_referer where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by server_ip order by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_server = array(); while($data = mysql_fetch_assoc($result)) { $rec_server[] = $data; } unset($result); $rec_ret = array(); for ($i = 0 ; $i < sizeof($rec_server) ; $i ++ ) { $sql = "select server_ip, referer, sum(transactions) as ctrns, sum(rsp_400) as rsp_400, sum(rsp_500) as rsp_500, avg(latency) as latency, avg(url_wait) as cwait from stats_referer where stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and server_ip='".$rec_server[$i]['server_ip']."' and referer != 'N/A' and referer != '' group by referer order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); while($data = mysql_fetch_assoc($result)) { if ($data['referer'] == "") continue; $rec_ret[] = $data; } unset($result); } unset($rec_server); return $rec_ret; } // 국가 TOP public function GetCountryTop($sdate, $edate) { $sql = "select cl.country, cc.country_name, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from (select c.city_id as city_id, sum(c.transactions) as transactions, avg(c.client_rtt) as client_rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_city as c where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by c.city_id) as c, ip_city_location as cl, ip_country as cc where cl.locId=c.city_id and cl.country=cc.country_code group by cc.country_name order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // 지역 TOP public function GetRegionTop($sdate, $edate) { $sql = "select r.region_name, cl.region, cl.country, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from (select c.city_id as city_id, sum(c.transactions) as transactions, avg(c.client_rtt) as client_rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_city as c where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by c.city_id) as c, ip_city_location as cl, ip_region as r where r.country_code=cl.country and r.region_code=cl.region and cl.region != '' and cl.locId=c.city_id group by cl.region,cl.country order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // ISP TOP public function GetISPTop($sdate, $edate) { $sql = "select c.isp_id as isp_id, isp.isp, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_isp as c, ip_isp as isp where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and isp.id=c.isp_id group by c.isp_id order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // OS TOP public function GetOSTop($sdate, $edate) { $sql = "select c.os_id as os_id, os.cd_nm as os_name, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_os as c, code as os where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and os.cd=CAST(c.os_id AS CHAR) and os.CD_TYPE_ID='OS' group by c.os_id order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // Browser TOP public function GetBrowserTop($sdate, $edate) { $sql = "select c.browser_id as br_id, br.cd_nm as br_name, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_browser as c, code as br where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and br.cd=CAST(c.browser_id AS CHAR) and br.CD_TYPE_ID='BRWS' group by c.browser_id order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // Mobile Top public function GetMobileTop($sdate, $edate) { $sql = "select c.mobile_id as m_id, mo.cd_nm as m_name, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_mobile as c, code as mo where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' and mo.cd=CAST(c.mobile_id AS CHAR) and mo.CD_TYPE_ID='MOBILE' group by c.mobile_id order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } // User Top public function GetUserTop($sdate, $edate) { $sql = "select c.client_ip as client_ip, sum(c.transactions) as ctrns, avg(c.client_rtt) as rtt, sum(c.rsp_400) as rsp_400, sum(c.rsp_500) as rsp_500, avg(c.latency) as latency from stats_user as c where c.stats_time between '".$sdate." 00:00:00' and '".$edate." 23:59:59' group by c.client_ip order by ctrns desc limit ".$this->limitTop; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } public function InsertDBTotalInfoHour($date) { $do_date = $date; // 그냥 그대로 this->dateO->GetDatePrevDay($date); if ($this->debug) echo "process Date : $date -> ".$do_date."\n"; $sql = "select hour, sum(server_transactions) as ctrns from stats_server where stats_time between '".$do_date." 00:00:00' and '".$do_date." 23:59:59' group by hour order by hour asc"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); for ($i = 0 ; $i < sizeof($rec_ret) ; $i ++ ) { $cinfo = $rec_ret[$i]; $sql = "select id from report_total where sdate='".$do_date."' and hour=".$cinfo['hour']." and what='h'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { // 없다. $sql = "update report_total set ctrns=".$cinfo['ctrns']." where id=".$data['id']; unset($result); } else { $sql = "insert into report_total(sdate, edate, hour, cuser, ctrns, csession, cwait, calarm, c40x, c50x, latency, what) values('".$do_date."', '".$do_date."', ".$cinfo['hour'].", 0, ".$cinfo['ctrns'].", 0, 0, 0, 0, 0, 0, 'h')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($rec_ret); return true; } // insert 작업 // 입력한 날짜을 처리한다. public function InsertDBTotalInfoDay($date) { $do_date = $date; // 그냥 그대로 this->dateO->GetDatePrevDay($date); if ($this->debug) echo "process Date : $date -> ".$do_date."\n"; $cuser = $this->GetCountUser($do_date, $do_date); $calarm = $this->GetCountAlarm($do_date, $do_date); $cinfo = $this->GetCountStatsServer($do_date, $do_date); if (!isset($cuser['cnt']) || $cuser['cnt'] == "") $cuser['cnt'] = 0; if (!isset($calarm['cnt']) || $calarm['cnt'] == "") $calarm['cnt'] = 0; if (!isset($cinfo['csession']) || $cinfo['csession'] == "") $cinfo['csession'] = 0; if (!isset($cinfo['ctrns']) || $cinfo['ctrns'] == "") $cinfo['ctrns'] = 0; if (!isset($cinfo['server_rtt']) || $cinfo['server_rtt'] == "") $cinfo['server_rtt'] = 0; if (!isset($cinfo['cwait']) || $cinfo['cwait'] == "") $cinfo['cwait'] = 0; if (!isset($cinfo['rsp_400']) || $cinfo['rsp_400'] == "") $cinfo['rsp_400'] = 0; if (!isset($cinfo['rsp_500']) || $cinfo['rsp_500'] == "") $cinfo['rsp_500'] = 0; if (!isset($cinfo['latency']) || $cinfo['latency'] == "") $cinfo['latency'] = 0; $sql = "select id from report_total where sdate='".$do_date."' and what='d'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { // 없다. $sql = "update report_total set cuser=".$cuser['cnt'].", ctrns=".$cinfo['ctrns'].", csession=".$cinfo['csession'].", cwait=".$cinfo['cwait'].", calarm=".$calarm['cnt'].", c40x=".$cinfo['rsp_400'].", c50x=".$cinfo['rsp_500'].", latency=".$cinfo['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into report_total(sdate, edate, hour, cuser, ctrns, csession, cwait, calarm, c40x, c50x, latency, what) values('".$do_date."', '".$do_date."', 99,".$cuser['cnt'].", ".$cinfo['ctrns'].", ".$cinfo['csession'].", ".$cinfo['cwait'].", ".$calarm['cnt'].", ".$cinfo['rsp_400'].", ".$cinfo['rsp_500'].", ".$cinfo['latency'].", 'd')"; } if ($this->debug) echo $sql."\n"; unset($result); $result = @mysql_query($sql, $this->db) or die (mysql_error()); if ($this->debug) echo "ok\n"; return true; } public function InsertDBTotalInfoWM($date, $opt) { if ($opt != "w" && $opt != "m") return false; $sql = "select sum(cuser) as cuser, sum(ctrns) as ctrns, sum(csession) as csession, avg(cwait) as cwait, sum(calarm) as calarm, sum(c40x) as c40x, sum(c50x) as c50x, avg(latency) as latency from report_total where sdate between '".$date['sdate']."' and '".$date['edate']."' and what='d'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($item = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); if ($item['cuser'] == "") { echo "data not found \n"; return false; } $sql = "select id from report_total where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { // $sql = "update report_total set cuser=".$item['cuser'].", ctrns=".$item['ctrns'].", csession=".$item['csession'].", cwait=".$item['cwait'].", calarm=".$item['calarm'].", c40x=".$item['c40x'].", c50x=".$item['c50x'].", latency=".$item['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into report_total(sdate, edate, hour, cuser, ctrns, csession, cwait, calarm, c40x, c50x, latency, what) values('".$date['sdate']."', '".$date['edate']."', 99, ".$item['cuser'].", ".$item['ctrns'].", ".$item['csession'].", ".$item['cwait'].", ".$item['calarm'].", ".$item['c40x'].", ".$item['c50x'].", ".$item['latency'].", '".$opt."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if ($this->debug) echo "ok\n"; return true; } // 입력한 날짜을 처리한다. public function InsertDBTotalInfoDayServer($date) { $do_date = $date; // 그대로 this->dateO->GetDatePrevDay($date); if ($this->debug) echo "processing date : ".$do_date."\n"; $cuser = $this->GetCountUserPerServer($do_date, $do_date); $calarm = $this->GetCountAlarmPerServer($do_date, $do_date); $cinfo = $this->GetCountStatsServerPerServer($do_date, $do_date); if ($this->debug) { echo $do_date."\n";; print_r($cuser); print_r($calarm); print_r($cinfo); } $data_rec = $this->MergeTotalData($cuser, $calarm, $cinfo); if ($this->debug) print_r($data_rec); unset($cuser); unset($calarm); unset($cinfo); foreach ($data_rec as $key => $item) { if ($key == "") continue; // exception $server_ip = $key; if (!isset($item['cuser']) || $item['cuser'] == "") $item['cuser'] = 0; if (!isset($item['csession']) || $item['csession'] == "") $item['csession'] = 0; if (!isset($item['cwait']) || $item['cwait'] == "") $item['cwait'] = 0; if (!isset($item['calarm']) || $item['calarm'] == "") $item['calarm'] = 0; if (!isset($item['c40x']) || $item['c40x'] == "") $item['c40x'] = 0; if (!isset($item['c50x']) || $item['c50x'] == "") $item['c50x'] = 0; if (!isset($item['ctrns']) || $item['ctrns'] == "") $item['ctrns'] = 0; if (!isset($item['latency']) || $item['latency'] == "") $item['latency'] = 0; $sql = "select id from report_total_srv where sdate='".$do_date."' and server_ip='".$server_ip."' and what='d'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { // $sql = "update report_total_srv set cuser=".$item['cuser'].", ctrns=".$item['ctrns'].", csession=".$item['csession'].", cwait=".$item['cwait'].", calarm=".$item['calarm'].", c40x=".$item['c40x'].", c50x=".$item['c50x'].", latency=".$item['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into report_total_srv(sdate, edate, server_ip, cuser, ctrns, csession, cwait, calarm, c40x, c50x, latency, what) values('".$do_date."', '".$do_date."', '".$server_ip."', ".$item['cuser'].", ".$item['ctrns'].", ".$item['csession'].", ".$item['cwait'].", ".$item['calarm'].", ".$item['c40x'].", ".$item['c50x'].", ".$item['latency'].", 'd')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($data_rec); if ($this->debug) echo "ok\n"; return true; } public function InsertDBTotalInfoServerWM($date, $opt) { if ($opt != "w" && $opt != "m") return false; $sql = "select server_ip, sum(cuser) as cuser, sum(ctrns) as ctrns, sum(csession) as csession, avg(cwait) as cwait, sum(calarm) as calarm, sum(c40x) as c40x, sum(c50x) as c50x, avg(latency) as latency from report_total_srv where sdate between '".$date['sdate']."' and '".$date['edate']."' and what='d' group by server_ip"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); for ($i = 0 ; $i < sizeof($rec_ret) ; $i ++ ) { $item = $rec_ret[$i]; $sql = "select id from report_total_srv where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."' and server_ip='".$item['server_ip']."'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { // $sql = "update report_total_srv set cuser=".$item['cuser'].", ctrns=".$item['ctrns'].", csession=".$item['csession'].", cwait=".$item['cwait'].", calarm=".$item['calarm'].", c40x=".$item['c40x'].", c50x=".$item['c50x'].", latency=".$item['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into report_total_srv(sdate, edate, server_ip, cuser, ctrns, csession, cwait, calarm, c40x, c50x, latency, what) values('".$date['sdate']."', '".$date['edate']."', '".$item['server_ip']."', ".$item['cuser'].", ".$item['ctrns'].", ".$item['csession'].", ".$item['cwait'].", ".$item['calarm'].", ".$item['c40x'].", ".$item['c50x'].", ".$item['latency'].", '".$opt."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if ($this->debug) echo "ok\n"; unset($result); } return true; } private function ExistItemRec($totalRec, $name, $value) { for ($i = 0 ; $i < sizeof($totalRec) ; $i ++ ) { if ($totalRec[$i][$name] == $value) return true; } return false; } public function GetItemRec($totalRec, $name, $value) { for ($i = 0 ; $i < sizeof($totalRec) ; $i ++ ) { if ($totalRec[$i][$name] == $value) return ($totalRec[$i]); } return ""; } public function GetItemRecArray($totalRec, $name, $value) { $ret_rec = array(); $retVal = false; for ($i = 0 ; $i < sizeof($totalRec) ; $i ++ ) { if ($totalRec[$i][$name] == $value) { $ret_rec[] = $totalRec[$i]; $retVal = true; } } if ($retVal) { return $ret_rec; } return ""; } private function MergeTotalData($cuser, $calarm, $cinfo) { $ret_arr = array(); for ($i = 0 ; $i < sizeof($cuser) ; $i ++ ) { $ret_arr[$cuser[$i]['server_ip']]['server_ip'] = $cuser[$i]['server_ip']; $ret_arr[$cuser[$i]['server_ip']]['cuser'] = $cuser[$i]['cnt']; } for ($i = 0 ; $i < sizeof($calarm) ; $i ++ ) { $ret_arr[$calarm[$i]['server_ip']]['server_ip'] = $calarm[$i]['server_ip']; $ret_arr[$calarm[$i]['server_ip']]['calarm'] = $calarm[$i]['cnt']; } for ($i = 0 ; $i < sizeof($cinfo) ; $i ++ ) { $ret_arr[$cinfo[$i]['server_ip']]['server_ip'] = $cinfo[$i]['server_ip']; $ret_arr[$cinfo[$i]['server_ip']]['csession'] = $cinfo[$i]['csession']; $ret_arr[$cinfo[$i]['server_ip']]['ctrns'] = $cinfo[$i]['ctrns']; $ret_arr[$cinfo[$i]['server_ip']]['server_rtt'] = $cinfo[$i]['server_rtt']; $ret_arr[$cinfo[$i]['server_ip']]['cwait'] = $cinfo[$i]['cwait']; $ret_arr[$cinfo[$i]['server_ip']]['c40x'] = $cinfo[$i]['rsp_400']; $ret_arr[$cinfo[$i]['server_ip']]['c50x'] = $cinfo[$i]['rsp_500']; $ret_arr[$cinfo[$i]['server_ip']]['latency'] = $cinfo[$i]['latency']; } return $ret_arr; } // 서버별 APP Top 20 public function InsertDBAppInfoServer($date, $opt="d") { $tname = "report_app_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* if ($opt == "w") { $do_date = $this->dateO->GetDatePrevWeek($date); $what="w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what="m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetAppTopPerServer($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['server_ip'] == "") continue; // exception $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and server_ip='".$cinfo[$i]['server_ip']."' and url='".mysql_escape_string($cinfo[$i]['url'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set cuser=".$cinfo[$i]['cuser'].", ctrns=".$cinfo[$i]['ctrns'].", csession=".$cinfo[$i]['csession'].", cwait=".$cinfo[$i]['cwait'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, server_ip, url, cuser, ctrns, csession, cwait, c40x, c50x, latency, what) values('".$do_date['sdate']."', '".$do_date['edate']."', '".$cinfo[$i]['server_ip']."', '".mysql_escape_string($cinfo[$i]['url'])."', ".$cinfo[$i]['cuser'].", ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['csession'].", ".$cinfo[$i]['cwait'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // Referer Top 20 public function InsertDBRefererInfoServer($date, $opt="d") { $tname = "report_referer_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetRefererTopPerServer($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['server_ip'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['csession']) || $cinfo[$i]['csession'] == "") $cinfo[$i]['csession'] = 0; if (!isset($cinfo[$i]['cwait']) || $cinfo[$i]['cwait'] == "") $cinfo[$i]['cwait'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and server_ip='".$cinfo[$i]['server_ip']."' and referer='".mysql_escape_string($cinfo[$i]['referer'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", csession=".$cinfo[$i]['csession'].", cwait=".$cinfo[$i]['cwait'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, server_ip, referer, ctrns, csession, cwait, c40x, c50x, latency, what) values('".$do_date['sdate']."', '".$do_date['edate']."', '".$cinfo[$i]['server_ip']."', '".mysql_escape_string($cinfo[$i]['referer'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['csession'].", ".$cinfo[$i]['cwait'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // 국가 Top 20 전체 public function InsertDBCountryInfo($date, $opt="d") { $tname = "report_country_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetCountryTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['country'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and country_code='".$cinfo[$i]['country']."' and country_name='".mysql_escape_string($cinfo[$i]['country_name'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, country_code, country_name, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', '".$cinfo[$i]['country']."', '".mysql_escape_string($cinfo[$i]['country_name'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // Region Top 20 전체 public function InsertDBRegionInfo($date, $opt="d") { $tname = "report_region_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetRegionTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['country'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and region_code='".$cinfo[$i]['region']."' and region_name='".mysql_escape_string($cinfo[$i]['region_name'])."' and country_code='".$cinfo[$i]['country']."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, region_code, region_name, country_code, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', '".$cinfo[$i]['region']."', '".mysql_escape_string($cinfo[$i]['region_name'])."', '".$cinfo[$i]['country']."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // ISP Top 20 전체 public function InsertDBISPInfo($date, $opt="d") { $tname = "report_isp_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetISPTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['isp'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and isp_code=".$cinfo[$i]['isp_id']." and isp_name='".mysql_escape_string($cinfo[$i]['isp'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, isp_code, isp_name, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', ".$cinfo[$i]['isp_id'].", '".mysql_escape_string($cinfo[$i]['isp'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // OS Top 20 전체 public function InsertDBOSInfo($date, $opt="d") { $tname = "report_os_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetOSTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['os_name'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and os_code=".$cinfo[$i]['os_id']." and os_name='".mysql_escape_string($cinfo[$i]['os_name'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, os_code, os_name, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', ".$cinfo[$i]['os_id'].", '".mysql_escape_string($cinfo[$i]['os_name'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // Browser Top 20 전체 public function InsertDBBrowserInfo($date, $opt="d") { $tname = "report_browser_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetBrowserTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['br_name'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and br_code=".$cinfo[$i]['br_id']." and br_name='".mysql_escape_string($cinfo[$i]['br_name'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, br_code, br_name, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', ".$cinfo[$i]['br_id'].", '".mysql_escape_string($cinfo[$i]['br_name'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // mobile Top 20 전체 public function InsertDBMobileInfo($date, $opt="d") { $tname = "report_mobile_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetMobileTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['m_name'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and m_code=".$cinfo[$i]['m_id']." and m_name='".mysql_escape_string($cinfo[$i]['m_name'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, m_code, m_name, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', ".$cinfo[$i]['m_id'].", '".mysql_escape_string($cinfo[$i]['m_name'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } // Client ip Top 20 전체 public function InsertDBUserInfo($date, $opt="d") { $tname = "report_user_top"; $do_date = $date; $what = $opt; if ($opt != "w" && $opt != "d" && $opt != "m") return false; /* $what = "d"; if ($opt == "week") { $do_date = $this->dateO->GetDatePrevWeek($date); $what = "w"; } else if ($opt == "month") { $do_date = $this->dateO->GetDatePrevMonth($date); $what = "m"; } else { $do_date['sdate'] = $this->dateO->GetDatePrevDay($date); $do_date['edate'] = $do_date['sdate']; $what="d"; } */ if ($this->debug) echo "processing date : ".$do_date['sdate']."-".$do_date['edate']."\n"; $cinfo = $this->GetUserTop($do_date['sdate'], $do_date['edate']); for ($i=0 ; $i < sizeof($cinfo) ; $i ++) { if ($cinfo[$i]['client_ip'] == "") continue; // exception if (!isset($cinfo[$i]['ctrns']) || $cinfo[$i]['ctrns'] == "") $cinfo[$i]['ctrns'] = 0; if (!isset($cinfo[$i]['rtt']) || $cinfo[$i]['rtt'] == "") $cinfo[$i]['rtt'] = 0; if (!isset($cinfo[$i]['rsp_400']) || $cinfo[$i]['rsp_400'] == "") $cinfo[$i]['rsp_400'] = 0; if (!isset($cinfo[$i]['rsp_500']) || $cinfo[$i]['rsp_500'] == "") $cinfo[$i]['rsp_500'] = 0; if (!isset($cinfo[$i]['latency']) || $cinfo[$i]['latency'] == "") $cinfo[$i]['latency'] = 0; $sql = "select id from ".$tname." where sdate='".$do_date['sdate']."' and client_ip='".mysql_escape_string($cinfo[$i]['client_ip'])."' and what='".$what."'"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) !== false) { $sql = "update ".$tname." set ctrns=".$cinfo[$i]['ctrns'].", c40x=".$cinfo[$i]['rsp_400'].", c50x=".$cinfo[$i]['rsp_500'].", latency=".$cinfo[$i]['latency'].", crtt=".$cinfo[$i]['rtt']." where id=".$data['id']; unset($result); } else { $sql = "insert into ".$tname."(sdate, edate, client_ip, ctrns, c40x, c50x, latency, crtt, what) values('".$do_date['sdate']."', '".$do_date['edate']."', '".mysql_escape_string($cinfo[$i]['client_ip'])."', ".$cinfo[$i]['ctrns'].", ".$cinfo[$i]['rsp_400'].", ".$cinfo[$i]['rsp_500'].", ".$cinfo[$i]['latency'].", ".$cinfo[$i]['rtt'].", '".$what."')"; } if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); } unset($cinfo); if ($this->debug) echo "ok\n"; return true; } public function GetMagReportTotal($date, $opt) { $sql = "select sum(cuser) as cuser, sum(ctrns) as ctrns, sum(csession) as csession, sum(calarm) as calarm, sum(c40x) as c40x, sum(c50x) as c50x, sum(latency) as latency from report_total where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."'"; if ($this->debug) echo $sql."
\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } public function GetMagReportTotalAVG($opt) { $sql = "select avg(cuser) as cuser, avg(ctrns) as ctrns, avg(csession) as csession, avg(calarm) as calarm, avg(c40x+c50x) as c40x50x, avg(c40x) as c40x, avg(c50x) as c50x, avg(latency) as latency from report_total where what='".$opt."'"; if ($this->debug) echo $sql."
\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { return(null); } unset($result); return $data; } public function GetMagServerList() { $sql = "select server_ip from conf_server order by server_ip asc"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } public function GetMagReportTotalServer_old($date, $opt) { $server_list = $this->GetMagServerList(); $where_str = " and server_ip in ("; for ($i = 0 ; $i < count($server_list) ; $i ++ ) { $where_str .= "'".$server_list[$i]['server_ip']."'"; if ($i < count($server_list) - 1) $where_str .= ","; } $where_str .= ") "; $sql = "select server_ip, sum(cuser) as cuser, sum(ctrns) as ctrns, sum(csession) as csession, sum(calarm) as calarm, sum(c40x) as c40x, sum(c50x) as c50x, sum(latency) as latency from report_total_srv where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."' ".$where_str." group by server_ip order by server_ip asc"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $data['exist'] = true; $rec_ret[] = $data; } unset($result); return $rec_ret; } public function GetMagReportTotalServer($date, $opt) { $server_list = $this->GetMagServerList(); $rec_ret = array(); for ($i = 0 ; $i < count($server_list) ; $i ++ ) { $sql = "select server_ip, sum(cuser) as cuser, sum(ctrns) as ctrns, sum(csession) as csession, sum(calarm) as calarm, sum(c40x) as c40x, sum(c50x) as c50x, sum(latency) as latency from report_total_srv where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."' and server_ip='".$server_list[$i]['server_ip']."'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); if(($data = mysql_fetch_assoc($result)) == false) { $data = array(); $data['exist'] = false; $rec_ret[] = $data; } else { $data['exist'] = true; $rec_ret[] = $data; } unset($result); } return $rec_ret; } public function GetMagReportTotalServerAVG($opt) { $sql = "select server_ip, avg(cuser) as cuser, avg(ctrns) as ctrns, avg(csession) as csession, avg(calarm) as calarm, avg(c40x) as c40x, avg(c50x) as c50x, avg(latency) as latency from report_total_srv where what='".$opt."' group by server_ip order by server_ip asc"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } public function GetMagReportAppServer($date, $opt) { $tname = "report_app_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportRefererServer($date, $opt) { $tname = "report_referer_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportCountryTop($date, $opt) { $tname = "report_country_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportRegionTop($date, $opt) { $tname = "report_region_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportISPTop($date, $opt) { $tname = "report_isp_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportOSTop($date, $opt) { $tname = "report_os_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportBrowserTop($date, $opt) { $tname = "report_browser_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportMobileTop($date, $opt) { $tname = "report_mobile_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportUserTop($date, $opt) { $tname = "report_user_top"; return ($this->GetItemDB($tname, $date, $opt)); } public function GetMagReportDayHourForTT($date, $opt) { $tname = "report_total"; $where = "sdate between '".$date['sdate']."' and '".$date['edate']."' and what='".$opt."'"; $ret_rec = $this->GetItemDBWhere($tname, $where); $top_item = ""; $top_i = 0; for ($i = 0 ; $i < sizeof($ret_rec) ; $i ++ ) { if ($i == 0) { $top_item = $ret_rec[$i]; $top_i = 0; } else if ($top_item['ctrns'] < $ret_rec[$i]['ctrns']) { $top_item = $ret_rec[$i]; $top_i = i; } } $ret['top'] = $top_item; $ret['top_i'] = $top_i; $ret['data'] = $ret_rec; return ($ret); } public function GetItemDBWhere($tname, $where) { $sql = "select * from ".$tname." where ".$where; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } public function GetItemDB($tname, $date, $opt) { $sql = "select * from ".$tname." where sdate='".$date['sdate']."' and edate='".$date['edate']."' and what='".$opt."'"; if ($this->debug) echo $sql."\n"; $result = @mysql_query($sql, $this->db) or die (mysql_error()); $rec_ret = array(); while($data = mysql_fetch_assoc($result)) { $rec_ret[] = $data; } unset($result); return $rec_ret; } } ?>