Monitoring\Metric\Clients\Connection\AbstractSocket
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 : hb.dt_other.time_sel***ost:t8misc1.ny.7w7.us,env:prod,is_cli:0.
|
protected function writeToSocket(string $message): void
{
if (!is_resource($this->socket)) {
throw new SocketException($this->host, $this->port, "Couldn't write to socket");
}
fwrite($this->socket, $message);
}
protected function connect(string $host, int $port, int $timeout, bool $persistent): void
{
$errorNumber = 0;
$errorMessage = '';
|
| parent::writeToSocket($message);
| 1 : hb.dt_other.time_sel***ost:t8misc1.ny.7w7.us,env:prod,is_cli:0.
| class UdpSocket extends AbstractSocket
{
private const HEADER_SIZE = 8;
protected function writeToSocket(string $message): void
{
parent::writeToSocket($message);
usleep(10);
}
protected function getUrl(string $host): string
{
return "udp://$host";
|
| $this->writeToSocket($packet);
| 1 : ["hb.dt_other.time_s***st:t8misc1.ny.7w7.us,env:prod,is_cli:0"]
| }
if (!$this->isConnected()) {
$this->connect($this->host, $this->port, $this->timeout, $this->isPersistent);
}
foreach ($this->cutIntoMtuSizedPackets($messages) as $packet) {
$this->writeToSocket($packet);
}
}
private function cutIntoMtuSizedPackets(array $messages): array
{
if ($this->allowFragmentation()) {
|
| $this->sendMessages([$message]);
| 1 : hb.dt_other.time_sel***host:t8misc1.ny.7w7.us,env:prod,is_cli:0
| public function send(string $message): void
{
if (empty($message)) {
return;
}
$this->sendMessages([$message]);
}
public function sendMessages(array $messages): void
{
if (count($messages) === 0) {
return;
|
| $this->connection->send($message);
| 1 : hb.dt_other.time_select
1 : 0 1 : c 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| foreach ($tags as $tagName => $tagValue) {
$tagArray[] = ($tagName . ':' . $tagValue);
}
$message .= '|#' . implode(',', $tagArray);
}
$this->connection->send($message);
}
private function validateMetricName(string $metric): void
{
if (substr($metric, -1) === '.') {
return;
|
| $this->send($metric, $value, 'c', $tags);
| 1 : dt_other.time_select
1 : 0 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| $tags['event'] = $event;
$this->count($this->eventMetric, 1, $tags);
}
public function count(string $metric, float $value, array $tags = []): void
{
$this->send($metric, $value, 'c', $tags);
}
private function send(string $metric, $value, string $type, array $tags = []): void
{
$this->validateMetricName($metric);
if (!empty($this->namespace)) {
|
| $this->count($metric, $value, $tags);
| 1 : dt_other.time_select
1 : 0 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| $this->namespace = $config['namespace'] ?? '';
$this->eventMetric = $config['event_metric'] ?? self::DEFAULT_EVENT_METRIC;
}
public function increment(string $metric, int $value, array $tags = null): void
{
$this->count($metric, $value, $tags);
}
public function gauge(string $metric, float $value, array $tags = []): void
{
$this->send($metric, $value, 'g', $tags);
}
|
| $this->getClient($clientClass)->$method($metric, $value, $tags);
| 1 : increment
1 : dt_other.time_select 1 : 0 1 : {"host":"t8misc1.ny.7w7.us","env":"prod","is_cli":0}
| foreach (self::CLIENTS as $clientClass) {
if ($this->isDegraded($clientClass)) {
continue;
}
try {
$this->getClient($clientClass)->$method($metric, $value, $tags);
continue;
} catch (ValidateException $e) {
ErrorHandler::sentry()->captureException($e);
continue;
} catch (DisabledException $e) {
|
| static::i()->send('increment', $metric, $value, $tags);
| 1 : dt_other.time_select
1 : [] 1 : 0
| $this->config = CC('metric') ?? [];
$this->global_tags = $this->getGlobalTags();
}
public static function inc(string $metric, array $tags = [], int $value = 1): void
{
static::i()->send('increment', $metric, $value, $tags);
}
public static function gauge(string $metric, float $value, array $tags = []): void
{
static::i()->send(__FUNCTION__, $metric, $value, $tags);
}
|
| \Monitoring\Metric\Metrics::inc($metric, [], $value);
| 1 : {"time":0.4441738128***.44417381286621094,"dt-phone":1,"hit":1}
| foreach ($metrics as $name => $value) {
$metric = $this->prepareMetricName($this->name . '.' . $name);
if ($name === 'time') {
\Monitoring\Metric\Metrics::histogram($metric, $value);
} else {
\Monitoring\Metric\Metrics::inc($metric, [], $value);
}
}
}
private function prepareMetricName(string $metric): string
{
|
| $this->sendMetric($inc);
| 1 : {"time":0.4441738128***.44417381286621094,"dt-phone":1,"hit":1}
1 : []
| if (! is_array($inc))
$inc = [$inc => 1];
if (! isset($inc['hit']))
$inc['hit'] = 1;
$this->save($inc, $data);
$this->sendMetric($inc);
}
// Compatibility ONLY !! - direct api-socket write
protected function save(array $inc=[], array $data=[]) {
Profiler::info("iStat/api(".$this->name.")", $inc + ($data ? ['data' => $data] : []));
$this->goApiSave($inc, $data);
|
| $this->hit($inc, $data);
| 1 : {"time":0.4441738128***e_web":0.44417381286621094,"dt-phone":1}
1 : [] 1 : hit-select time-sele***it-TDB15 time-TDB15 hit-TDB16 time-TDB16
| Profiler::info("iStat/api(".$this->name.")", $inc + ($data ? ['data' => $data] : []));
$this->goApiSave($inc, $data);
}
// Compatibility ONLY !! - direct api-socket write
PUBLIC function apcHit(array $inc=[], array $data=[], /* string */ $keys="", $flush = true) {
$this->hit($inc, $data);
}
// You DO NOT need this call on web pages - only tests need it
// flush APC cache
function apcFlush($keys, $data=[]) {
// do not need this anymore
|
| i('Stat', 'dt-'.$node)->apcHit($hit, $data, $keys);
| 1 : select
| // accesses to non-main dt by name
if ($node == 'other') {
$n = str_replace("dt.", "", $this->st);
$hit['dt-'.$n] = 1;
}
i('Stat', 'dt-'.$node)->apcHit($hit, $data, $keys);
}
// cache iStat APC-hit keys in APC
function iStatKeys() { # keys
$K = "dt:".$this->st.".istat_keys"; // keys used
$keys = apcu_fetch($K);
|
| $this->iStat("select");
| 1 : 1401245
1 : {"phone7":"1401245","phone8":"1401245","_limit":1} 1 : * 1 : null
| } else {
\Profiler::in("DT::select");
}
try {
$r = $DBE->select("$fields from $table", $where, "all_hash", $DB_Parallel);
$this->iStat("select");
} catch (\Exception $ex) {
$this->_fail_warn($ex);
$r = $this->_dbe_b()->select("$fields from " . $this->_bt(), $where, "all_hash", $DB_Parallel);
$this->iStat("select", ['fail' => 1]);
}
|
| $d = $this->select($key, $wh, $fields, $DB_Parallel);
| 1 : 1401245
1 : {"phone7":"1401245","phone8":"1401245"} 1 : * 1 : null
| */
function select_one($key, $uk, $fields="*", \DB_Parallel &$DB_Parallel = null) { # {field:value, ...}
\Profiler::in("DT::one");
$wh = is_array($uk) ? $uk : ["id" => $uk];
$wh["_limit"] = 1;
$d = $this->select($key, $wh, $fields, $DB_Parallel);
\Profiler::out([$this->st, $key, "uk" => $uk, "exists" => (bool) $d]);
return $d ? reset($d) : [];
}
/**
* @param $key - shard_key
|
| return $this->M($namespace)->select_one($this->shard_key($namespace, $key), $key, $fields, $DB_Parallel); # shard-key, $id (using "id" as a shard key)
| 1 : phone
1 : {"phone7":"1401245","phone8":"1401245"} 1 : * 1 : null
| * @param DB_Parallel|null $DB_Parallel
* @return array
* @throws DB_Parallel_Exception
*/
function _load($namespace, $key, $fields="*", DB_Parallel &$DB_Parallel = null) {
return $this->M($namespace)->select_one($this->shard_key($namespace, $key), $key, $fields, $DB_Parallel); # shard-key, $id (using "id" as a shard key)
}
/**
* @param $namespace
* @param $key
* @param DB_Parallel|null $DB_Parallel
|
| $D = $this->_load($namespace, $key, "*", $DB_Parallel);
| 1 : phone
1 : {"phone7":"1401245","phone8":"1401245"} 1 : null
| Profiler::in("KRDB::DT::load/request", [$namespace, $key]);
}
} else {
Profiler::in("KRDB::DT::load", [$namespace, $key]);
}
$D = $this->_load($namespace, $key, "*", $DB_Parallel);
if (!$DB_Parallel || $DB_Parallel->isComplete()) {
if (!$D) {
Profiler::info("NO DATA");
Profiler::out();
return is_array($key) ? $key : [];
|
| $D = $this->storage->load($this->namespace, $key, $DB_Parallel);
| 1 : {"phone7":"1401245","phone8":"1401245"}
1 : null
| // --------------------------------------------------------------------------
// FOR OVERLOAD
// Physical Database integration
// actual load
PUBLIC function load($key, DB_Parallel &$DB_Parallel = null) { # parsed data
$D = $this->storage->load($this->namespace, $key, $DB_Parallel);
if (! $this->track_changes)
unset($D["_updated"]);
return $D;
}
// actual save
|
| $this->D = $this->namespace->load($key, $DB_Parallel);
| 1 : {"namespace":"phone"***changes":1,"storage":{},"cache_cap":100}
1 : {"phone7":"1401245","phone8":"1401245"} 1 : null
| // !! Never Call Directly
// use KRDB::i($ns, $id) or KRDB::i($ns)[$id]
function __construct(KRDB_Namespace $namespace, /* string */ $key, DB_Parallel &$DB_Parallel = null) {
$this->namespace = $namespace;
$this->key = $key;
$this->D = $this->namespace->load($key, $DB_Parallel);
//THIS CODE MAKES MEMORY LEAK!
//$this->K = $this;
$this->K = null; // avoid circ references
$this->P = null;
if ($namespace->C())
|
| $K = new $class($this, $key, $DB_Parallel);
| 1 : {"phone7":"1401245","phone8":"1401245"}
1 : null
| return $this->cache[$k];
$class = NVL($this->C("class"), "KRDB");
// OOM solution for spiders
if (count($this->cache) > $this->cache_cap)
$this->reset_cache();
$K = new $class($this, $key, $DB_Parallel);
if (!$DB_Parallel || $DB_Parallel->isComplete()) {
$this->cache[$k] = $K;
return $K;
}
}
| KRDB_PhoneNS
|
| 1 : 1401245
1 : null
| throw new RunTimeException("1,4,7,8 digit phone prefix supported");
/*
if (substr($key, 0, 1) == '1')
throw new RunTimeException("Only US phones supported");
*/
return parent::KRDB(['phone7' => substr($key, 0, 7), 'phone8' => substr($key, 0, 8)], $DB_Parallel);
}
|
| $I = $N->KRDB($key, $DB_Parallel);
| 1 : phone
1 : 1401245
| if ($key === false) {
$I = $N;
} elseif (is_string($key) && strpos($key, ":") === false) {
$I = $N[$key];
} else {
$I = $N->KRDB($key, $DB_Parallel);
}
Profiler::out();
return $I;
}
/**
| Phone_Prefix
|
| 1 : 4012459636
| return self::info6($prefix);
}
static function info6($prefix) {
$prefix = self::_no1($prefix);
$prefix6 = substr($prefix, 0, 6);
$prefix7 = KRDB::i('phone', "1".$prefix6)->info;
if ($prefix7["zips"]??[]) {
foreach ($prefix7["zips"] as $k=>$v){
if (!(int)$v) {
unset($prefix7["zips"][$k]);
}
| Phone_Prefix
|
| 1 : 4012459636
| * @param type $prefix
* @return type
*/
static function info7($prefix) {
//fetch prefix 6 info
return self::info6($prefix);
}
static function info6($prefix) {
$prefix = self::_no1($prefix);
$prefix6 = substr($prefix, 0, 6);
$prefix7 = KRDB::i('phone', "1".$prefix6)->info;
| Action_Phone_Root
|
| 1 : 4012459636
| if (!$teaser && !$this->forbidden_phone) {
SEO_MissingData::hit("phone");
go(Phone::reversePhoneLookupReportUrl($p, false));
}
}
$this->prefix_info = $prefix_info = Phone_Prefix::info7($p);
if ($all_interlinks = Phone::getInterlinks("1".$p)) {
$interlinks = [];
$cnts = [];
foreach ($all_interlinks as $k=>$v) {
$knd = $v["kind"];
|
| return call_user_func_array( [$this, $method], $r);
| 1 : phone
| }
} catch(Exception $ex) {
\Log::alert( $ex->getMessage() );
}
try {
return call_user_func_array( [$this, $method], $r);
} catch(RedirectException $ex) {
return $ex->getMessage();
}
}
function page404() {
|
| return $this->_reflection_call($method);
| 1 : phone
1 : phone
| if (method_exists($this, $method) )
$mex=1;
}
}
if ($mex)
return $this->_reflection_call($method);
// use template name (same as url)
return $url;
}
/* internal */
// serve method (normal or gzipped)
|
| $r = $A->_call($method, $path);
| 1 : phone
1 : {"p":"4012459636","c***":"table-scroll","forbidden_phone":null}
| Profiler::disable();
CD::set("AJAX", 1);
}
Profiler::in("${class}::$method", $p);
$A = new $class($p);
$r = $A->_call($method, $path);
Profiler::out();
//respect called action's desire to act as AJAX.
$is_ajax = CD("AJAX");
// AJAX methods - default - no templates
if ($is_ajax) {
|
| $template = self::action($url, $params); // PARAM by REF!
| 1 : phone
1 : {"p":"4012459636","c***":"table-scroll","forbidden_phone":null} 1 : _layout
| self::$layout=$layout;
if ($r = strpos($url,"?"))
$url = substr($url, 0, $r);
$url = substr($url,1); // remove leading "/"
restore_msg($params);
$template = self::action($url, $params); // PARAM by REF!
if (isset($_GET['TPL']) ) {
echo "<div style='padding-left: 3px; background: #eee'>";
vvv($params);
echo "</div>";
}
|
| Controller::dispatch($_SERVER["REDIRECT_URL"], $_GET + $_POST, "_layout");
| 1 : phone
1 : {"p":"4012459636","c***":"table-scroll","forbidden_phone":null} 1 : _layout
| <?
Controller::dispatch($_SERVER["REDIRECT_URL"], $_GET + $_POST, "_layout");
exit; |
Error\ErrorHandler::Error\{closure}([0:ErrorException: fwri..]) Error\ErrorHandler->invokeListeners([ 0:[3 items], 1:ErrorException: fwri..]) Error\ErrorHandler->handleError([0:8, 1:fwrite..o host, 2:/rd/li..et.php, 3:20]) Monitoring\Metric\Clients\Connection\AbstractSocket->writeToSocket([0:hb.dt_..cli:0 ]) Monitoring\Metric\Clients\Connection\UdpSocket->writeToSocket([0:hb.dt_..cli:0 ]) Monitoring\Metric\Clients\Connection\InetSocket->sendMessages([ 0:[1 items]]) Monitoring\Metric\Clients\Connection\InetSocket->send([0:hb.dt_.._cli:0]) Monitoring\Metric\Clients\StatsdClient->send([0:hb.dt_..select, 1:0, 2:c 3:[3 items]])