public static function onArticleViewAfterParser(Article $article, ParserOutput $parserOutput) { global $wgCityId, $wgDBname; // we collect production data from Oasis only /* $app = F::app(); if ( !$app->checkSkin( 'oasis', $app->wg->Skin ) || $app->wg->DevelEnvironment || $app->wg->StagingEnvironment ) { return true; } */ if (class_exists('WScribeClient')) { try { $title = $article->getTitle(); $fields = array('wikiId' => intval($wgCityId), 'databaseName' => $wgDBname, 'articleId' => $title->getArticleID(), 'namespaceId' => $title->getNamespace(), 'articleTitle' => $title->getText(), 'parserTime' => $parserOutput->getPerformanceStats('time'), 'wikitextSize' => $parserOutput->getPerformanceStats('wikitextSize'), 'htmlSize' => $parserOutput->getPerformanceStats('htmlSize'), 'expFuncCount' => $parserOutput->getPerformanceStats('expFuncCount'), 'nodeCount' => $parserOutput->getPerformanceStats('nodeCount'), 'postExpandSize' => $parserOutput->getPerformanceStats('postExpandSize'), 'tempArgSize' => $parserOutput->getPerformanceStats('tempArgSize')); $data = json_encode($fields); WScribeClient::singleton(self::SCRIBE_KEY)->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } } // Logging parser activity for monitoring // wiki and article info are sent to logstash anyways so no need to repeat them here WikiaLogger::instance()->info("Parser execution", ['parser-time' => round($parserOutput->getPerformanceStats('time') * 1000), 'node-count' => (int) $parserOutput->getPerformanceStats('nodeCount'), 'wikitext-size' => (int) $parserOutput->getPerformanceStats('wikitextSize'), 'skin-name' => RequestContext::getMain()->getSkin()->getSkinName()]); return true; }
/** * This method is called via hook at the end of the request handling * * Make the list of unique URLs and send them to Fastly via Scribe queue * * @author macbre * * @return bool true - it's a hook */ static function onRestInPeace() { // don't process an empty queue if (empty(self::$urls)) { return true; } wfProfileIn(__METHOD__); $scribe = WScribeClient::singleton(self::SCRIBE_KEY); try { wfDebug(sprintf("%s: sending %d unique URLs to the purger (%d items were queued in total)\n", __METHOD__, count(self::$urls), self::$urlsCount)); foreach (self::$urls as $url => $data) { wfDebug(sprintf("%s: %s\n", __METHOD__, $url)); // send to Scribe queue $scribe->send(json_encode($data)); // debugging data to be sent to both sFlow (for monitoring) and Kibana (for debugging) $context = ['url' => $data['url'], 'method' => $data['method']]; // log purges using SFlow (BAC-1258) SFlow::operation('varnish.purge', $context); // log purges using Kibana (BAC-1317) WikiaLogger::instance()->info('varnish.purge', $context); } } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } wfProfileOut(__METHOD__); return true; }
/** * storeData -- push data frame to Stomp * * @param String $type * @author Piotr Molski (MoLi) * @access private * */ private function send_log() { wfProfileIn(__METHOD__); try { $data = json_encode(array('cityId' => $this->mCityId, 'pageId' => $this->mPageId, 'revId' => $this->mRevId, 'logId' => $this->mLogId, 'serverName' => $this->mServerName, 'archive' => $this->mArchive, 'hostname' => wfHostname(), 'beaconId' => wfGetBeaconId())); WScribeClient::singleton($this->mKey)->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } wfProfileOut(__METHOD__); }
/** * Send data via Scribe * * @param ProfilerData $data */ public function send(ProfilerData $data) { if (!$this->checkDependencies()) { return; } $scribeKey = $this->getScribeKey($data->getEngine()); $data = array('time' => microtime(true), 'engine' => $data->getEngine(), 'profile' => $data->getProfile(), 'context' => Transaction::getAttributes(), 'request' => $data->getRequest(), 'entries' => $data->getEntries()); $data = json_encode($data); try { WScribeClient::singleton($scribeKey)->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } }
/** * Send a set of events with a provided context * * @param array $events set of events to be sent * @param array $context request context to be attached to each event (can be empty) */ private static function send(array $events, array $context = array()) { // no data to send if (empty($events)) { return; } $data = ['time' => microtime(true), 'app' => Transaction::APP_NAME, 'context' => $context, 'events' => $events]; $data = json_encode($data); try { WScribeClient::singleton(self::SCRIBE_KEY)->send($data); } catch (TException $e) { if (is_callable('Wikia::log')) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } } }
/** * @param Title $title * @return bool */ function efSearchDigestRecordMiss($title) { global $wgEnableScribeReport, $wgCityId; if (empty($wgEnableScribeReport)) { return true; } if (!is_object($title)) { return true; } $params = array("sd_wiki" => $wgCityId, "sd_query" => $title->getText()); // use scribe try { $message = array('method' => 'searchmiss', 'params' => $params); $data = json_encode($message); WScribeClient::singleton('trigger')->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } return true; }
/** * wikia function * purges list of keys via surrogate key purge mechanism in Varnish * @ * @access public * @static */ static function VarnishPurgeKey($keyArr) { global $wgEnableScribeReport; wfProfileIn(__METHOD__); $queue = 'varnish_purges_by_key'; if (empty($wgEnableScribeReport)) { wfProfileOut(__METHOD__); return true; } if (!is_array($keyArr)) { $keyArr = array($keyArr); } try { foreach ($keyArr as $key) { if (!is_string($key)) { throw new MWException('Bad purge key'); } wfDebug("Purging key {$key} via Scribe\n"); $data = json_encode(array('key' => $key, 'time' => time())); WScribeClient::singleton($queue)->send($data); } } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } wfProfileOut(__METHOD__); }
/** * informJobQueue * Send information to the backend script what job was added * * @static * @access public * * @param Integer count of job params * * @author Piotr Molski (MoLi) * @return true */ public static function informJobQueue($job_count = 1) { global $wgCityId, $wgDBname, $wgEnableScribeReport; if (empty($wgEnableScribeReport)) { return true; } $params = array('dbname' => $wgDBname, 'wiki_id' => $wgCityId, 'jobs' => $job_count); try { $message = array('method' => 'jobqueue', 'params' => $params); $data = json_encode($message); WScribeClient::singleton('trigger')->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } return true; }
/** * Hook function to delete all watches for User * @param $oUser User: object * @return bool (always true) */ public static function clearGlobalWatch($oUser) { global $wgEnableScribeReport, $wgCityId; wfProfileIn(__METHOD__); if (empty($wgEnableScribeReport)) { wfProfileOut(__METHOD__); return true; } if (!$oUser instanceof User) { wfProfileOut(__METHOD__); return true; } $user_id = $oUser->getId(); if (empty($user_id)) { wfProfileOut(__METHOD__); return true; } $params = array('wl_user' => $user_id, 'wl_wikia' => $wgCityId); try { $message = array('method' => 'removeWatch', 'params' => array($params)); $data = json_encode($message); WScribeClient::singleton('trigger')->send($data); } catch (Exception $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } wfProfileOut(__METHOD__); return true; }
/** * addStats * * counts statistics for blocks * * @author tor <*****@*****.**> * * @param $blockerId Int unique block identifier * @param $type Int unique block type identifier * * @todo use a message queue for this */ public static function addStats($blockerId, $type) { global $wgUser, $wgCityId; wfProfileIn(__METHOD__); if (wfReadOnly()) { wfProfileOut(__METHOD__); return; } // hack to not count testFilters hits, // otherwise phalanxexempt users will *not* get here if ($wgUser->isAllowed('phalanxexempt')) { wfProfileOut(__METHOD__); return; } if (class_exists('WScribeClient')) { try { $fields = array('blockId' => $blockerId, 'blockType' => $type, 'blockTs' => wfTimestampNow(), 'blockUser' => $wgUser->getName(), 'city_id' => $wgCityId); $data = json_encode($fields); WScribeClient::singleton(self::SCRIBE_KEY)->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } } else { global $wgExternalDatawareDB; $fields = array('ps_blocker_id' => $blockerId, 'ps_blocker_type' => $type, 'ps_timestamp' => wfTimestampNow(), 'ps_blocked_user' => $wgUser->getName(), 'ps_wiki_id' => $wgCityId); $dbw = wfGetDB(DB_MASTER, array(), $wgExternalDatawareDB); $dbw->insert('phalanx_stats', $fields); } wfProfileOut(__METHOD__); }
public function sendLog() { wfProfileIn(__METHOD__); try { $data = json_encode($this->mParams); WScribeClient::singleton($this->mKey)->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } wfProfileOut(__METHOD__); }
<?php ini_set("include_path", dirname(__FILE__) . "/.."); $IP = $GLOBALS["IP"]; require_once "commandLine.inc"; require_once $IP . "/extensions/wikia/Scribe/ScribeClient.php"; $wgScribeHost = '10.10.10.163'; $wgScribePort = 1463; $count = 1; for ($i = 0; $i <= $count; $i++) { echo "send {$i} message \n"; $res = WScribeClient::singleton('cat_test')->send('msg_test' . $i); } echo print_r($res, true) . "\n";
/** * SavePreferencesHook * * Store row from user table before changes of preferences are saved. * Called by Hook SavePreferences * Data is stored in external storage archive1 * * @author Krzysztof Krzyżaniak (eloy) <*****@*****.**> * @access public * @static * * @return bool true process other hooks */ public static function SavePreferencesHook($formData, $error) { global $wgSpecialsDB, $wgEnableScribeReport, $wgUser; if (wfReadOnly()) { return true; } wfProfileIn(__METHOD__); $id = $wgUser->getId(); if ($id) { /** * caanot use "insert from select" because we got two different db * clusters. But we should have all user data already loaded. */ $options = $wgUser->getOptions(); $a = array(); if (!empty($options)) { foreach ($options as $oname => $oval) { array_push($a, $oname . '=' . $oval); } } $user_options = implode("\n", $a); $params = array("user_id" => $id, "user_name" => $wgUser->mName, "user_real_name" => $wgUser->mRealName, "user_password" => $wgUser->mPassword, "user_newpassword" => $wgUser->mNewpassword, "user_email" => $wgUser->mEmail, "user_options" => $user_options, "user_touched" => $wgUser->mTouched, "user_token" => $wgUser->mToken); if (!empty($wgEnableScribeReport)) { # use scribe try { $message = array('method' => 'savepreferences', 'params' => $params); $data = json_encode($message); WScribeClient::singleton('trigger')->send($data); } catch (TException $e) { Wikia::log(__METHOD__, 'scribeClient exception', $e->getMessage()); } } else { $dbw = wfGetDB(DB_MASTER, array(), $wgSpecialsDB); /** * so far encodeOptions is public by default but could be * private in future */ $dbw->insert("user_history", $params, __METHOD__); $dbw->commit(__METHOD__); } } wfProfileOut(__METHOD__); return true; }