xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / stats / stats.php (62f8587b50910b08e4d634f8aa46fc7df76e2d0a) (4,422B) (mode 100644) [raw]
<?php
include_once(__DIR__ . '/../graph.inc.php');

$_sub = empty($paras) ? 'month' : array_shift($paras);
switch ($_sub) {
default:
case 'month':
	$period = 'hour';
	$start = gmmktime(0, 0, 0, gmdate('m') - 1, gmdate('d'), gmdate('Y'));
	$end = gmmktime(0, 0, 0, gmdate('m'), gmdate('d') + 1, gmdate('Y')) - 1;
	break;

case '12hours':
	$period = 'minute';
	$start = gmmktime(gmdate('H') + 12, 0, 0, gmdate('m'), gmdate('d') - 1, gmdate('Y'));
	$end = gmmktime(gmdate('H') + 1, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y')) - 1;
	break;

case 'year':
	$period = 'day';
	$start = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y') - 1);
	$end = gmmktime(0, 0, 0, gmdate('m'), gmdate('d') + 1, gmdate('Y')) - 1;
	break;
}

$rg['stats_menu'][$_sub] = 1;
$body .= rg_template('stats/menu.html', $rg, TRUE /*xss*/);

if (1) {
	/* main stats page */
	$rg['graph'] = array();
	$rg['graph']['users'] = 'bla';

	$subtitle = gmdate('Y-m-d H:i:s', $start)
		. ' - ' . gmdate('Y-m-d H:i:s', $end) . " UTC\n";

	$a = array(
		'bg_style' => 'fill: #bdf',
		'h' => 150,
		'title_style' => 'color: #fff',
		'subtitle' => $subtitle,
		'subtitle_style' => 'color: #00f; font-size: 8pt',
		'data_style' => 'fill: #ffa',
		'data_line_style' => 'fill: #f00',
		'data_line_width' => 1,
		'gap' => 0,
		'footer_style' => 'font-color: #000; font-size: 8pt'
	);

	$b = $a;
	$b['title'] = '🛸 Users';
	$r = rg_user_data($db, 'create_account', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['users'] = 'Error generating user graph: '
			. rg_user_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:users'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🐸 Repositories';
	$r = rg_repo_data($db, 'create_repo', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['repos'] = 'Error generating repo graph: '
			. rg_repo_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:repos'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🐛 Bugs';
	$r = rg_repo_data($db, 'create_bug', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['bugs'] = 'Error generating bugs graph: '
			. rg_repo_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:bugs'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '⛙ Merge requests';
	$r = rg_mr_data($db, 'create_mr', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['mrs'] = 'Error generating mr graph: '
			. rg_mr_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:mrs'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🎥 Requests (web, API, ssh, git)';
	$r = rg_conns_data($db, 'total', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['requests'] = 'Error generating requests graph: '
			. rg_stats_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:requests'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '📅 Repositories history entries';
	$r = rg_repo_data($db, 'history', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['repo_history'] = 'Error generating repo history graph: '
			. rg_repo_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:repo_history'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🔑 SSH keys';
	$r = rg_ssh_data($db, 'create_key', $start, $end, $period, 'sum');
	if ($r === FALSE) {
		$rg['graph']['keys'] = 'Error generating keys graph: '
			. rg_ssh_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:keys'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '💽 Disk space used (GiB)';
	$r = rg_stats_data($db, 'disk', $start, $end, $period, 'avg');
	if ($r === FALSE) {
		$rg['graph']['disk'] = 'Error generating disk graph: '
			. rg_stats_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:disk'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🧠 Memory used (MiB)';
	$r = rg_stats_data($db, 'mem', $start, $end, $period, 'avg');
	if ($r === FALSE) {
		$rg['graph']['mem'] = 'Error generating disk graph: '
			. rg_stats_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:mem'] = rg_graph($b);
	}

	$b = $a;
	$b['title'] = '🚜 Load';
	$r = rg_stats_data($db, 'load', $start, $end, $period, 'avg');
	if ($r === FALSE) {
		$rg['graph']['load'] = 'Error generating disk graph: '
			. rg_stats_error() . '!';
	} else {
		$b['data'] = $r;
		$rg['graph']['HTML:load'] = rg_graph($b);
	}

	$body .= rg_template('stats/stats.html', $rg, TRUE /*xss*/);
}

Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master