public function testFullUsageArray() { $sender = $this->mockSender(); // $sender = new Sender(); // StatsdClient(SenderInterface $sender, $host = 'localhost', $port = 8126, $protocol='udp', $reducePacket = true, $fail_silently = true) $client = new StatsdClient($sender, $host = 'localhost', $port = 8126, 'udp', $reducePacket = true, $fail_silently = true); $data[] = "increment:1|c"; $data[] = "set:value|s"; $data[] = "gauge:value|g"; $data[] = "timing:10|ms"; $data[] = "decrement:-1|c"; $data[] = "key:1|c"; // send the data as array or directly as object $client->send($data); }
/** * @todo document */ function wfLogProfilingData() { global $wgDebugLogGroups, $wgDebugRawPage; $context = RequestContext::getMain(); $request = $context->getRequest(); $profiler = Profiler::instance(); $profiler->setContext($context); $profiler->logData(); $config = $context->getConfig(); if ($config->get('StatsdServer')) { $statsdServer = explode(':', $config->get('StatsdServer')); $statsdHost = $statsdServer[0]; $statsdPort = isset($statsdServer[1]) ? $statsdServer[1] : 8125; $statsdSender = new SocketSender($statsdHost, $statsdPort); $statsdClient = new StatsdClient($statsdSender); $statsdClient->send($context->getStats()->getBuffer()); } # Profiling must actually be enabled... if ($profiler instanceof ProfilerStub) { return; } if (isset($wgDebugLogGroups['profileoutput']) && $wgDebugLogGroups['profileoutput'] === false) { // Explicitly disabled return; } if (!$wgDebugRawPage && wfIsDebugRawPage()) { return; } $ctx = array('elapsed' => $request->getElapsedTime()); if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ctx['forwarded_for'] = $_SERVER['HTTP_X_FORWARDED_FOR']; } if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ctx['client_ip'] = $_SERVER['HTTP_CLIENT_IP']; } if (!empty($_SERVER['HTTP_FROM'])) { $ctx['from'] = $_SERVER['HTTP_FROM']; } if (isset($ctx['forwarded_for']) || isset($ctx['client_ip']) || isset($ctx['from'])) { $ctx['proxy'] = $_SERVER['REMOTE_ADDR']; } // Don't load $wgUser at this late stage just for statistics purposes // @todo FIXME: We can detect some anons even if it is not loaded. // See User::getId() $user = $context->getUser(); $ctx['anon'] = $user->isItemLoaded('id') && $user->isAnon(); // Command line script uses a FauxRequest object which does not have // any knowledge about an URL and throw an exception instead. try { $ctx['url'] = urldecode($request->getRequestURL()); } catch (Exception $ignored) { // no-op } $ctx['output'] = $profiler->getOutput(); $log = LoggerFactory::getInstance('profileoutput'); $log->info("Elapsed: {elapsed}; URL: <{url}>\n{output}", $ctx); }
/** * Send all buffered data to statsd. * * @return $this */ public function flush() { $this->client->send($this->buffer); $this->buffer = array(); return $this; }
public function testSampleRate() { $senderMock = $this->getMock('Liuggio\\StatsdClient\\Sender\\SenderInterface'); $senderMock->expects($this->once())->method('open')->will($this->returnValue(true)); $senderMock->expects($this->once())->method('write')->with($this->anything(), 'foo|@0.2'); $client = new StatsdClient($senderMock, false, false); $client->send('foo', 0.2); }