Commit bdcab3de authored by dmorley's avatar dmorley

status of all the things in the db

parent 94ade49b
Pipeline #543 failed with stage
in 1 minute and 45 seconds
......@@ -9,6 +9,19 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
### Fixed
### Security
## [2.5.0]
:exclamation: DB migrations required! (see [SQL migration script][2.5.0-sql-migration])
### Added
- Status table, monitor status of events happening
### Changed
- Status page is now /status from /db/status.php
### Deprecated
### Removed
- db/last.data can be deleted from your system
### Fixed
- Moved status to a new table vs flat file as updates do not work right if not run every hour
### Security
## [2.4.2] - 2018-10-18
### Fixed
- Fixed db setup calls for cleaner links
......@@ -116,12 +129,14 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
### Fixed
- Fix ipv6
[2.5.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.4.1-2.5.0.sql
[2.4.1-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.4.0-2.4.1.sql
[2.4.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.3.0-2.4.0.sql
[2.3.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.2.0-2.3.0.sql
[2.2.0-sql-migration]: https://git.feneas.org/diasporg/Poduptime/blob/master/db/migrations/2.1.4-2.2.0.sql
[Unreleased]: https://git.feneas.org/diasporg/Poduptime/compare/master...develop
[2.5.0]: https://git.feneas.org/diasporg/Poduptime/compare/2.4.1...2.5.0
[2.4.1]: https://git.feneas.org/diasporg/Poduptime/compare/2.4.0...2.4.1
[2.4.0]: https://git.feneas.org/diasporg/Poduptime/compare/2.3.1...2.4.0
[2.3.1]: https://git.feneas.org/diasporg/Poduptime/compare/2.3.0...2.3.1
......
......@@ -66,7 +66,8 @@ psql -U podupuser podupdb < db/migrations/xxx.sql (see db/migrations/README.md f
# Status
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e4fdde7b4ec34c56a86938d3ba6e3983)](https://www.codacy.com/app/diasporg/Poduptime?utm_source=git.feneas.org&amp;utm_medium=referral&amp;utm_content=diasporg/Poduptime&amp;utm_campaign=Badge_Grade)
[![Build status](https://badge.buildkite.com/2a2d6f9ff932fc359416fff31ee72c3dce703569a801f83af6.svg)](https://buildkite.com/diasporg/poduptime)
[![pipeline status](https://git.feneas.org/diasporg/Poduptime/badges/develop/pipeline.svg)](https://git.feneas.org/diasporg/Poduptime/commits/develop)
[![coverage report](https://git.feneas.org/diasporg/Poduptime/badges/develop/coverage.svg)](https://git.feneas.org/diasporg/Poduptime/commits/develop)
============================
......
......@@ -48,3 +48,5 @@ while ($entry = $dirh->read()) {
unlink($file) ? 'Success!' : 'Failed.'
);
}
updateStatus('backup_data');
CREATE TABLE status (
id serial8 UNIQUE PRIMARY KEY,
masterversions_updated timestamp,
monthlystats_updated timestamp,
pods_updated timestamp,
pods_update_runtime int,
geodb_updated timestamp,
cacert_updated timestamp,
federation_crawldate timestamp,
backup_data timestamp,
date_updated timestamp DEFAULT current_timestamp
);
......@@ -64,7 +64,6 @@ fi
echo "Updating in new pod data...";
php update.php $@
touch last.data
echo "Finished update!"
echo "Backing up..."
......
<?php
/**
* Check status of previously pulled data.
*/
declare(strict_types=1);
$dur = time() - filemtime('last.data');
echo $dur;
if ($dur > 4500) {
http_response_code(500);
} else {
http_response_code(200);
}
......@@ -105,3 +105,16 @@ CREATE TABLE monthlystats (
total_uptime int,
date_checked timestamp DEFAULT current_timestamp
);
CREATE TABLE status (
id serial8 UNIQUE PRIMARY KEY,
masterversions_updated timestamp,
monthlystats_updated timestamp,
pods_updated timestamp,
pods_update_runtime int,
geodb_updated timestamp,
cacert_updated timestamp,
federation_crawldate timestamp,
backup_data timestamp,
date_updated timestamp DEFAULT current_timestamp
);
......@@ -83,3 +83,5 @@ foreach ($softwares as $software => $details) {
printf('%s:%s:%s ', $software, $masterversion, $devlastcommit ?: 'n/a');
}
updateStatus('masterversions_updated');
......@@ -54,3 +54,5 @@ foreach ($monthly_totals as $monthly) {
die('Error in SQL query: ' . $e->getMessage());
}
}
updateStatus('monthlystats_updated');
......@@ -53,3 +53,5 @@ foreach ($results as $result) {
echo $result . ' ';
echo exec("php-cgi add.php domain={$result}") . "\r\n";
}
updateStatus('federation_crawldate');
......@@ -22,6 +22,8 @@ use Longman\IPTools\Ip;
use Poduptime\PodStatus;
use RedBeanPHP\R;
$time_start = microtime(true);
$debug = isset($_GET['debug']) || (isset($argv) && in_array('debug', $argv, true));
$sqldebug = isset($_GET['sqldebug']) || (isset($argv) && in_array('sqldebug', $argv, true));
$develop = isset($_GET['develop']) || (isset($argv) && in_array('develop', $argv, true));
......@@ -169,7 +171,7 @@ foreach ($pods as $pod) {
try {
$masterdata = R::getRow('
SELECT version, devlastcommit, releasedate
SELECT version, devlastcommit, releasedate, date_checked
FROM masterversions
WHERE software = ?
ORDER BY id
......@@ -427,3 +429,8 @@ foreach ($pods as $pod) {
echo $newline;
}
updateStatus('pods_updated');
$time_end = microtime(true);
$execution_time = ($time_end - $time_start)/60;
updateStatus('pods_update_runtime', $execution_time);
......@@ -6,10 +6,10 @@
declare(strict_types=1);
use Carbon\Carbon;
use RedBeanPHP\R;
require_once __DIR__ . '/boot.php';
$lastfile = 'db/last.data';
$input = isset($_GET['input']) ? substr($_GET['input'], 1) : null;
$mapview = isset($_GET['mapview']) || $input === 'map';
$statsview = isset($_GET['statsview']) || $input === 'stats';
......@@ -18,8 +18,22 @@ $podminedit = isset($_GET['podminedit']) || $input === 'podminedit';
$edit = isset($_GET['edit']) || $input === 'edit';
$add = isset($_GET['add']) || $input === 'add';
$gettoken = isset($_GET['gettoken']) || $input === 'gettoken';
$status = isset($_GET['status']) || $input === 'status';
$simpleview = !($mapview || $podmin || $podminedit || $statsview);
$fullview = false;
try {
$dbstatus = R::getRow('
SELECT pods_updated
FROM status
ORDER BY pods_updated
LIMIT 1
');
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
$pods_updated = $dbstatus['pods_updated'];
?>
<!doctype html>
<html lang="en">
......@@ -120,6 +134,8 @@ $navs = [
include_once __DIR__ . '/statsview.php';
} elseif ($podmin) {
include_once __DIR__ . '/podmin.php';
} elseif ($status) {
include_once __DIR__ . '/status.php';
} elseif ($podminedit) {
include_once __DIR__ . '/podminedit.php';
} elseif ($edit) {
......@@ -136,7 +152,7 @@ $navs = [
</div>
</main>
<footer class="ml-3 text-muted">
<small>Data refreshed <?php echo Carbon::createFromTimestamp(filemtime($lastfile))->diffForHumans(); ?></small>
<small>Data refreshed <?php echo Carbon::createFromFormat('Y-m-d H:i:s', $pods_updated)->diffForHumans(); ?></small>
</footer>
<input type="hidden" name="input" value="<?php echo $input ?>"/>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
......
......@@ -7,6 +7,7 @@
declare(strict_types=1);
use DetectLanguage\DetectLanguage;
use RedBeanPHP\R;
/**
* Helper to get config values.
......@@ -210,3 +211,24 @@ function debugToConsole($data): void
echo "<script>console.log('Debug Objects: {$output}');</script>";
}
/**
* Update status table
*
* @param string
*/
function updateStatus($colname, $value)
{
if ($value) {
$colvalue = $value;
} else {
$colvalue = date('Y-m-d H:i:s');
}
try {
$u = R::dispense('status');
$u[$colname] = $colvalue;
R::store($u);
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
}
\ No newline at end of file
{
"name": "poduptime",
"version": "1.0.0",
"version": "2.5.0",
"description": "Poduptime is software to get live stats and data on listed Diaspora Pods.",
"main": "index.php",
"dependencies": {
......
<?php
declare(strict_types=1);
require_once __DIR__ . '/boot.php';
use Carbon\Carbon;
use RedBeanPHP\R;
try {
$updbstatus = R::getRow('
SELECT pods_updated
FROM status
ORDER BY pods_updated
LIMIT 1
');
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
try {
$durdbstatus = R::getRow('
SELECT pods_update_runtime
FROM status
ORDER BY pods_update_runtime
LIMIT 1
');
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
$pods_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s', $updbstatus['pods_updated'])->diffForHumans();
echo "<small>";
if ($pods_updated_stats < 120) {
echo "System status is Green<br>";
} else {
echo "System status is Red<br>";
}
echo "Last Update was " . $pods_updated_stats . " <br>";
echo "Last Update run duration was " . $durdbstatus['pods_update_runtime'] . " minutes";
echo "</small>";
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment