Initial import
This commit is contained in:
117
application/controllers/tools/monitoring/Queue.php
Normal file
117
application/controllers/tools/monitoring/Queue.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
class Queue extends MY_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database("onedev", true);
|
||||
}
|
||||
function index() {
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$branchName = "No Branch";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$branchName = $rows[0]["M_BranchName"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
$LIMIT_TIME = 600; // 200s
|
||||
$sql ="select count(*) tot from INFORMATION_SCHEMA.processlist
|
||||
where USER <> 'system user' and TIME >= $LIMIT_TIME and INFO is not null";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$tot_ovr = $rows[0]["tot"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
$sql ="select count(*) tot from INFORMATION_SCHEMA.processlist";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$tot= $rows[0]["tot"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
if ($tot_ovr > 0 ) {
|
||||
$msg = "* [$branchName] Mysql Long Process \\> $LIMIT_TIME s $tot_ovr, from $tot process *, Top 3 query :\n";
|
||||
$sql = "select substr(INFO,1,500) info from INFORMATION_SCHEMA.processlist
|
||||
where USER <> 'system user' and TIME >= $LIMIT_TIME order by TIME desc limit 0,3";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r ) {
|
||||
$query = $r["info"];
|
||||
$msg .= "\n```python
|
||||
$query
|
||||
```";
|
||||
}
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
$this->sasone($msg);
|
||||
}
|
||||
}
|
||||
|
||||
function cek() {
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
||||
$branchName = "No Branch";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$branchName = $rows[0]["M_BranchName"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
$LIMIT_TIME = 300; // 200s
|
||||
$sql ="select count(*) tot from INFORMATION_SCHEMA.processlist
|
||||
where USER <> 'system user' and TIME >= $LIMIT_TIME and INFO is not null";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$tot_ovr = $rows[0]["tot"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
$sql ="select count(*) tot from INFORMATION_SCHEMA.processlist";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
$tot= $rows[0]["tot"];
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
if ($tot_ovr > 0 ) {
|
||||
$msg = "* [$branchName] Mysql Long Process \\> $LIMIT_TIME s $tot_ovr, from $tot process *, Top 3 query :\n";
|
||||
$sql = "select substr(INFO,1,500) info from INFORMATION_SCHEMA.processlist
|
||||
where USER <> 'system user' and TIME >= $LIMIT_TIME order by TIME desc limit 0,3";
|
||||
$qry = $this->db->query($sql);
|
||||
if ($qry) {
|
||||
$rows = $qry->result_array();
|
||||
foreach($rows as $r ) {
|
||||
$query = $r["info"];
|
||||
$msg .= "\n```python
|
||||
$query
|
||||
```";
|
||||
}
|
||||
} else {
|
||||
print_r($this->db->error());
|
||||
}
|
||||
echo $msg . "\n";
|
||||
}
|
||||
}
|
||||
function sasone($msg) {
|
||||
$url = "http://bandungraya.aplikasi.web.id/one-api/tgram/xone/sasone";
|
||||
$data = json_encode( array("text" => $msg ));
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data))
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
echo $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user