MaxSem has uploaded a new change for review.
https://gerrit.wikimedia.org/r/319260
Change subject: WIP: count page with geo tags
......................................................................
WIP: count page with geo tags
Bug: T149722
Change-Id: I1fa2d69549af5527105efa4403329182399ab238
---
A geo-tag-counts.php
A src/Graphite.php
A src/Mysql.php
3 files changed, 72 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/discovery-stats
refs/changes/60/319260/1
diff --git a/geo-tag-counts.php b/geo-tag-counts.php
new file mode 100644
index 0000000..2999053
--- /dev/null
+++ b/geo-tag-counts.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace DiscoveryStats;
+
+require_once( __DIR__ . '/vendor/autoload.php' );
+
+$config = json_decode( file_get_contents( __DIR__ . '/config.json' ) );
+
+$matrix = new SiteMatrix();
+$db = '/etc/mysql/conf.d/analytics-research-client.cnf';
+$switchToDb = $db->prepare( 'USE :dbname' );
+$graphite = new Graphite( $config );
+
+foreach ( $matrix->getSites() as $site ) {
+ $switchToDb->execute( [ ':dbname' => $site->getDbName() ] );
+ $siteKey = $site->getFamily() . '.' . $site->getCode();
+ $res = $db->query( 'SELECT count(*) AS num FROM geo_tags WHERE
gt_primary=1' );
+ if ( $res && ( $row = reset( $res ) ) ) {
+ $siteKey = $site->getFamily() . '.' . $site->getCode();
+ $graphite->record( "geodata.pages.$siteKey.hourly" );
+ }
+}
diff --git a/src/Graphite.php b/src/Graphite.php
new file mode 100644
index 0000000..7a65164
--- /dev/null
+++ b/src/Graphite.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace DiscoveryStats;
+
+class Graphite {
+ /** @var string */
+ private $host;
+ /** @var int */
+ private $port;
+ /* @var int */
+ private $timestamp;
+
+ public function __construct( $config ) {
+ $this->host = $config->graphiteHost;
+ $this->port = $config->graphitePort;
+ $this->timestamp = time();
+ }
+
+ public function record( $metric, $value ) {
+ $packet = "{$metric} {$value} {$this->timestamp}";
+ $nc = "nc -q0 {$this->host} {$this->port}";
+ $command = "echo \"$packet\" | $nc";
+
+ exec( $command );
+ }
+}
diff --git a/src/Mysql.php b/src/Mysql.php
new file mode 100644
index 0000000..82fefcb
--- /dev/null
+++ b/src/Mysql.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace DiscoveryStats;
+
+use Exception;
+use PDO;
+
+class Mysql {
+ /**
+ *
+ */
+ public static function connect( $config, $host ) {
+ $ini = parse_ini_file( $config );
+
+ if ( !$ini ) {
+ throw new Exception( "Error opening mysql config $config" );
+ }
+
+ return new PDO( "mysql:host=$host",
+ $config['client']['user'],
+ $config['client']['password']
+ );
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/319260
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1fa2d69549af5527105efa4403329182399ab238
Gerrit-PatchSet: 1
Gerrit-Project: analytics/discovery-stats
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits