[MediaWiki-commits] [Gerrit] analytics/discovery-stats[production]: Add client usage of structured data
MaxSem has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/327456 ) Change subject: Add client usage of structured data .. Add client usage of structured data Really gotta add the ability to do this kind of stuff to reportupdater, but no time right now. Bug: T153272 Change-Id: I40bac9a1c7ae38455fc0111fc2b4c1bb1206a4cf (cherry picked from commit 19a55d34739923181789f456401978e2abb6f960) --- A bin/daily.sh M src/Graphite.php A structured-usage.php 3 files changed, 64 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/discovery-stats refs/changes/56/327456/1 diff --git a/bin/daily.sh b/bin/daily.sh new file mode 100755 index 000..1a411af --- /dev/null +++ b/bin/daily.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +BASEDIR=`dirname "$0"`/.. + +/usr/bin/php $BASEDIR/structured-usage.php diff --git a/src/Graphite.php b/src/Graphite.php index 7a65164..85e848d 100644 --- a/src/Graphite.php +++ b/src/Graphite.php @@ -16,8 +16,11 @@ $this->timestamp = time(); } -public function record( $metric, $value ) { -$packet = "{$metric} {$value} {$this->timestamp}"; +public function record( $metric, $value, $timestamp = null ) { +if ( $timestamp === null ) { +$timestamp = $this->timestamp; +} +$packet = "{$metric} {$value} {$timestamp}"; $nc = "nc -q0 {$this->host} {$this->port}"; $command = "echo \"$packet\" | $nc"; diff --git a/structured-usage.php b/structured-usage.php new file mode 100644 index 000..06456a3 --- /dev/null +++ b/structured-usage.php @@ -0,0 +1,54 @@ +getSites() as $site ) { +$dbName = $site->getDbName(); +// Can't quote it, have to validate +if ( !preg_match( '/^[a-z0-9_]+$/', $dbName ) ) { +throw new \Exception( "Invalid database '$dbName'" ); +} +if ( $site->isPrivate() || in_array( $dbName, $wikiBlacklist ) ) { +continue; +} + +query( "USE $dbName" ); +$siteKey = $site->getFamily() . '.' . $site->getCode(); + +$res = query( "SELECT count(*) AS num FROM page_props WHERE pp_propname='jsonconfig_getdata'" ); +if ( $res && ( $row = $res->fetch() ) && $row['num'] ) { +$graphite->record( "daily.structured-data.client.pagecount.$siteKey", +$row['num'], +$timestamp +); +} +} + +function query( $sql ) { +global $db; + +$res = $db->query( $sql ); +if ( !$res ) { +$err = $db->errorInfo(); +throw new \Exception( "{$err[0]}: {$err[2]}" ); +} + +return $res; +} -- To view, visit https://gerrit.wikimedia.org/r/327456 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I40bac9a1c7ae38455fc0111fc2b4c1bb1206a4cf Gerrit-PatchSet: 1 Gerrit-Project: analytics/discovery-stats Gerrit-Branch: production Gerrit-Owner: MaxSem___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
[MediaWiki-commits] [Gerrit] analytics/discovery-stats[production]: Add client usage of structured data
MaxSem has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/327456 ) Change subject: Add client usage of structured data .. Add client usage of structured data Really gotta add the ability to do this kind of stuff to reportupdater, but no time right now. Bug: T153272 Change-Id: I40bac9a1c7ae38455fc0111fc2b4c1bb1206a4cf (cherry picked from commit 19a55d34739923181789f456401978e2abb6f960) --- A bin/daily.sh M src/Graphite.php A structured-usage.php 3 files changed, 64 insertions(+), 2 deletions(-) Approvals: MaxSem: Verified; Looks good to me, approved diff --git a/bin/daily.sh b/bin/daily.sh new file mode 100755 index 000..1a411af --- /dev/null +++ b/bin/daily.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +BASEDIR=`dirname "$0"`/.. + +/usr/bin/php $BASEDIR/structured-usage.php diff --git a/src/Graphite.php b/src/Graphite.php index 7a65164..85e848d 100644 --- a/src/Graphite.php +++ b/src/Graphite.php @@ -16,8 +16,11 @@ $this->timestamp = time(); } -public function record( $metric, $value ) { -$packet = "{$metric} {$value} {$this->timestamp}"; +public function record( $metric, $value, $timestamp = null ) { +if ( $timestamp === null ) { +$timestamp = $this->timestamp; +} +$packet = "{$metric} {$value} {$timestamp}"; $nc = "nc -q0 {$this->host} {$this->port}"; $command = "echo \"$packet\" | $nc"; diff --git a/structured-usage.php b/structured-usage.php new file mode 100644 index 000..06456a3 --- /dev/null +++ b/structured-usage.php @@ -0,0 +1,54 @@ +getSites() as $site ) { +$dbName = $site->getDbName(); +// Can't quote it, have to validate +if ( !preg_match( '/^[a-z0-9_]+$/', $dbName ) ) { +throw new \Exception( "Invalid database '$dbName'" ); +} +if ( $site->isPrivate() || in_array( $dbName, $wikiBlacklist ) ) { +continue; +} + +query( "USE $dbName" ); +$siteKey = $site->getFamily() . '.' . $site->getCode(); + +$res = query( "SELECT count(*) AS num FROM page_props WHERE pp_propname='jsonconfig_getdata'" ); +if ( $res && ( $row = $res->fetch() ) && $row['num'] ) { +$graphite->record( "daily.structured-data.client.pagecount.$siteKey", +$row['num'], +$timestamp +); +} +} + +function query( $sql ) { +global $db; + +$res = $db->query( $sql ); +if ( !$res ) { +$err = $db->errorInfo(); +throw new \Exception( "{$err[0]}: {$err[2]}" ); +} + +return $res; +} -- To view, visit https://gerrit.wikimedia.org/r/327456 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I40bac9a1c7ae38455fc0111fc2b4c1bb1206a4cf Gerrit-PatchSet: 1 Gerrit-Project: analytics/discovery-stats Gerrit-Branch: production Gerrit-Owner: MaxSemGerrit-Reviewer: MaxSem ___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits