summaryrefslogtreecommitdiff
path: root/lib/snapshot.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-04-16 12:41:30 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-04-16 12:41:30 -0400
commit5128448c777e74c0e294c21ce80711c04395d6d4 (patch)
tree3b5920770bf76e085a318dc53eea283e5e75172a /lib/snapshot.php
parentc4040303cecc48aed66d0102de6b9f5ffdc64b22 (diff)
code complete on snapshot.php
Diffstat (limited to 'lib/snapshot.php')
-rw-r--r--lib/snapshot.php88
1 files changed, 80 insertions, 8 deletions
diff --git a/lib/snapshot.php b/lib/snapshot.php
index 4f9bb3f62..338c8d559 100644
--- a/lib/snapshot.php
+++ b/lib/snapshot.php
@@ -51,15 +51,9 @@ if (!defined('LACONICA')) {
class Snapshot {
- function __construct()
- {
- }
+ var $stats = null;
- function take()
- {
- }
-
- function report()
+ function __construct()
{
}
@@ -98,4 +92,82 @@ class Snapshot {
common_log(LOG_WARNING, "Unrecognized value for snapshot run config.");
}
}
+
+ function take()
+ {
+ $this->stats = array();
+
+ // Some basic identification stuff
+
+ $this->stats['version'] = LACONICA_VERSION;
+ $this->stats['phpversion'] = phpversion();
+ $this->stats['name'] = common_config('site', 'name');
+ $this->stats['root'] = common_root_url();
+
+ // non-identifying stats on various tables. Primary
+ // interest is size and rate of activity of service.
+
+ $tables = array('user',
+ 'notice',
+ 'subscription',
+ 'remote_profile',
+ 'user_group');
+
+ foreach ($tables as $table) {
+ $this->tableStats($table);
+ }
+
+ // stats on some important config options
+
+ $this->stats['theme'] = common_config('site', 'theme');
+ $this->stats['dbtype'] = common_config('db', 'type');
+ $this->stats['xmpp'] = common_config('xmpp', 'enabled');
+ $this->stats['inboxes'] = common_config('inboxes', 'enabled');
+ $this->stats['queue'] = common_config('queue', 'enabled');
+ $this->stats['license'] = common_config('license', 'url');
+ $this->stats['fancy'] = common_config('site', 'fancy');
+ $this->stats['private'] = common_config('site', 'private');
+ $this->stats['closed'] = common_config('site', 'closed');
+ $this->stats['memcached'] = common_config('memcached', 'enabled');
+ $this->stats['language'] = common_config('site', 'language');
+ $this->stats['timezone'] = common_config('site', 'timezone');
+ }
+
+ function report()
+ {
+ // XXX: Use OICU2 and OAuth to make authorized requests
+
+ $postdata = http_build_query($this->stats);
+
+ $opts = array('http' =>
+ array(
+ 'method' => 'POST',
+ 'header' => 'Content-type: application/x-www-form-urlencoded',
+ 'content' => $postdata,
+ 'user_agent' => 'Laconica/'.LACONICA_VERSION
+ )
+ );
+
+ $context = stream_context_create($opts);
+
+ $reporturl = common_config('snapshot', 'reporturl');
+
+ $result = file_get_contents($reporturl, false, $context);
+ }
+
+ function tableStats($table)
+ {
+ $inst = DB_DataObject::Factory($table);
+ $res = $inst->query('SELECT count(*) as cnt, '.
+ 'min(created) as first, '.
+ 'max(created) as last '.
+ 'from ' . $table);
+ if ($res) {
+ $this->stats[$table.'count'] = $inst->cnt;
+ $this->stats[$table.'first'] = $inst->first;
+ $this->stats[$table.'last'] = $inst->last;
+ }
+ $inst->free();
+ unset($inst);
+ }
}