Browse Source

add peer.timeOnline registration

yggdrasil-0.4.7
ghost 1 year ago
parent
commit
8ecabdb3d3
  1. BIN
      database/yggstate.mwb
  2. 6
      src/crontab/crawler.php
  3. 72
      src/library/mysql.php

BIN
database/yggstate.mwb

Binary file not shown.

6
src/crontab/crawler.php

@ -121,6 +121,9 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) { @@ -121,6 +121,9 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
$db->updatePeerRemoteUptime($dbPeerRemote->peerRemoteId, $connectedPeerInfo->uptime, time());
}
$debug['yggdrasil']['peer']['remote']['total']['update'] +=
$db->updatePeerRemoteTimeOnline($dbPeerRemote->peerRemoteId, time());
} else {
if ($peerRemoteId = $db->addPeerRemote($dbPeerId,
@ -133,6 +136,9 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) { @@ -133,6 +136,9 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
time())) {
$debug['yggdrasil']['peer']['remote']['total']['insert']++;
$debug['yggdrasil']['peer']['remote']['total']['update'] +=
$db->updatePeerRemoteTimeOnline($peerRemoteId, time());
}
}

72
src/library/mysql.php

@ -104,9 +104,10 @@ class MySQL { @@ -104,9 +104,10 @@ class MySQL {
`received` = ?,
`sent` = ?,
`uptime` = ?,
`timeAdded` = ?');
`timeAdded` = ?,
`timeUpdated` = ?');
$query->execute([$peerId, $scheme, $host, $port, $received, $sent, $uptime, $timeAdded]);
$query->execute([$peerId, $scheme, $host, $port, $received, $sent, $uptime, $timeAdded, $timeAdded]);
return $this->_db->lastInsertId();
}
@ -144,6 +145,17 @@ class MySQL { @@ -144,6 +145,17 @@ class MySQL {
return $query->rowCount();
}
public function updatePeerRemoteTimeOnline(int $peerRemoteId, $time) {
$this->_debug->query->update->total++;
$query = $this->_db->prepare('UPDATE `peerRemote` SET `timeOnline` = ?, `timeUpdated` = ? WHERE `peerRemoteId` = ? LIMIT 1');
$query->execute([$time, $time, $peerRemoteId]);
return $query->rowCount();
}
public function findPeerRemote(int $peerId, string $scheme, string $host, int $port) {
$this->_debug->query->select->total++;
@ -217,6 +229,62 @@ class MySQL { @@ -217,6 +229,62 @@ class MySQL {
return $query->fetchAll();
}
// Analytics
public function getPeerFirst() {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT * FROM `peer` ORDER BY `peerId` ASC LIMIT 1');
$query->execute();
return $query->fetch();
}
public function getPeerTotal() {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `peer`');
$query->execute();
return $query->fetch()->total;
}
public function findPeerTotalByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `peerId`) AS `total` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query->execute([$timeUpdatedFrom, $timeUpdatedTo, $timeUpdatedFrom, $timeUpdatedTo]);
return (int) $query->fetch()->total;
}
public function findPeerRemoteReceivedSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT SUM(`received`) AS `result` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query->execute([$timeUpdatedFrom, $timeUpdatedTo, $timeUpdatedFrom, $timeUpdatedTo]);
return (int) $query->fetch()->result;
}
public function findPeerRemoteSentSumByTime(int $timeUpdatedFrom, int $timeUpdatedTo) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT SUM(`sent`) AS `result` FROM `peerRemote` WHERE (`timeAdded` > ? AND `timeAdded` < ?) OR (`timeUpdated` > ? AND `timeUpdated` < ?)');
$query->execute([$timeUpdatedFrom, $timeUpdatedTo, $timeUpdatedFrom, $timeUpdatedTo]);
return (int) $query->fetch()->result;
}
// Other
public function optimize() {

Loading…
Cancel
Save