本文整理汇总了PHP中DBFarmRole::GetServersByFilter方法的典型用法代码示例。如果您正苦于以下问题:PHP DBFarmRole::GetServersByFilter方法的具体用法?PHP DBFarmRole::GetServersByFilter怎么用?PHP DBFarmRole::GetServersByFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBFarmRole
的用法示例。
在下文中一共展示了DBFarmRole::GetServersByFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
if (!$period) {
$period = '15';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids[$period]);
$la = (double) $res;
$retval[] = $la;
}
return $retval;
}
示例2: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$DBFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return 0;
}
$_roleBW = array();
$retval = array();
foreach ($servers as $DBServer) {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE);
if (!$type) {
$type = 'outbound';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $DBFarm->Hash, null, null, false);
preg_match_all("/[0-9]+/si", $this->snmpClient->get($this->snmpOids[$type]), $matches);
$bw_out = (double) $matches[0][0];
$bw = round($bw_out / 1024 / 1024, 2);
$_roleBW[] = $bw;
}
$roleBW = round(array_sum($_roleBW) / count($_roleBW), 2);
if ($farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== null && $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== '') {
$time = time() - $farmRoleMetric->dtLastPolled;
$bandwidth_usage = ($roleBW - (double) $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW)) * 8;
$bandwidth_channel_usage = $bandwidth_usage / $time;
// in Mbits/sec
$retval = round($bandwidth_channel_usage, 2);
} else {
$retval = 0;
}
$farmRoleMetric->setSetting(self::SETTING_BW_LAST_VALUE_RAW, $roleBW);
return array($retval);
}
示例3: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$DBFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return 0;
}
$roleBWRaw = array();
$retval = array();
foreach ($servers as $DBServer) {
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE) == 'inbound' ? 'receive' : 'transmit';
$netStat = (array) $DBServer->scalarizr->system->netStat();
foreach ($netStat as $interface => $usage) {
if ($interface != 'lo') {
break;
}
}
if ($usage) {
array_push($roleBWRaw, round($usage->{$type}->bytes / 1024 / 1024, 2));
}
}
$roleBW = round(array_sum($roleBWRaw) / count($roleBWRaw), 2);
if ($farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== null && $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW) !== '') {
$time = time() - $farmRoleMetric->dtLastPolled;
$bandwidthUsage = ($roleBW - (double) $farmRoleMetric->getSetting(self::SETTING_BW_LAST_VALUE_RAW)) * 8;
$bandwidthChannelUsage = $bandwidthUsage / $time;
// in Mbits/sec
$retval = round($bandwidthChannelUsage, 2);
} else {
$retval = 0;
}
$farmRoleMetric->setSetting(self::SETTING_BW_LAST_VALUE_RAW, $roleBW);
return array($retval);
}
示例4: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
try {
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
$index = 0;
if ($period == 15) {
$index = 2;
} elseif ($period == 5) {
$index = 1;
}
$la = $DBServer->scalarizr->system->loadAverage();
if ($la[$index] !== null && $la[$index] !== false) {
$la = (double) number_format($la[$index], 2);
}
$retval[] = $la;
} catch (Exception $e) {
\Scalr::getContainer()->logger(__CLASS__)->warn(new FarmLogMessage($DBServer->farmId, sprintf("Unable to read LoadAverage value from server %s: %s", $DBServer->getNameByConvention(), $e->getMessage()), $DBServer->serverId));
}
}
return count($retval) > 0 ? $retval : false;
}
示例5: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$retval = array();
if (count($servers) == 0) {
return false;
}
foreach ($servers as $DBServer) {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
// Think about global cache
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, 7, null, true);
$res = $this->snmpClient->getFullTree(".1.3.6.1.4.1.36632.5");
$result = array();
foreach ($res as $oid => $value) {
preg_match("/^(.*?)\\.36632\\.5\\.1\\.([0-9]+)\\.([0-9]+)\$/", $oid, $matches);
switch ($matches[2]) {
case "1":
//index
$result['index'][$matches[3]] = $value;
break;
case "2":
//metric_id
$result['metric_id'][$matches[3]] = $value;
break;
case "3":
//metric_name
$result['metric_name'][$matches[3]] = $value;
break;
case "4":
//metric_value
$result['metric_value'][$matches[3]] = $value;
break;
case "5":
//error
$result['error'][$matches[3]] = $value;
break;
}
}
foreach ($result['metric_id'] as $index => $metric_id) {
if ($metric_id == $farmRoleMetric->metricId) {
if ($result['error'][$index]) {
throw new Exception(sprintf(_("%s metric error on '%s' (%s): %s"), $result['metric_name'][$index], $DBServer->serverId, $DBServer->remoteIp, $result['error'][$index]));
}
$retval[] = $result['metric_value'][$index];
break;
}
}
}
return $retval;
}
示例6: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$curTime = time();
$newData = [];
$servers = $dbFarmRole->GetServersByFilter(['status' => SERVER_STATUS::RUNNING]);
if (!empty($farmRoleMetric->dtLastPolled)) {
$interval = $curTime - $farmRoleMetric->dtLastPolled;
if ($interval < 1) {
// The service was started less than one second ago
return false;
}
}
$mbitsPerInterface = [];
foreach ($servers as $DBServer) {
$type = $farmRoleMetric->getSetting(self::SETTING_BW_TYPE) == 'inbound' ? 'receive' : 'transmit';
$netStat = (array) $DBServer->scalarizr->system->netStat();
foreach ($netStat as $interface => $usage) {
if ($interface != 'lo' && !empty($usage)) {
$totalBytes = round($usage->{$type}->bytes);
$dataKey = $DBServer->serverId . '-' . $interface . '-' . $type;
$newData[$dataKey] = $totalBytes;
if (isset($interval)) {
if (is_array($farmRoleMetric->lastData) && array_key_exists($dataKey, $farmRoleMetric->lastData)) {
$lastTotalBytes = intval($farmRoleMetric->lastData[$dataKey]);
$usedBytes = $totalBytes - $lastTotalBytes;
if ($usedBytes > 0) {
$usedMBits = $usedBytes * 8 / 1024 / 1024 / $interval;
array_push($mbitsPerInterface, round($usedMBits, 2));
} else {
// The last value is considered to be incorrect as the server has been restarted
$missStep = true;
}
} else {
// The last value hasn't been set yet
$missStep = true;
}
}
}
}
}
$farmRoleMetric->lastData = $newData;
if (!isset($interval) || !empty($missStep)) {
// Sets the Server time to avoid differences between Database and Server time
$farmRoleMetric->dtLastPolled = $curTime;
$farmRoleMetric->save(false, ['settings', 'metric_id']);
return false;
}
return $mbitsPerInterface;
}
示例7: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$roleLA = 0;
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
try {
if ($DBServer->IsSupported('0.13.0')) {
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
$index = 0;
if ($period == 15) {
$index = 2;
} elseif ($period == 5) {
$index = 1;
}
$la = $DBServer->scalarizr->system->loadAverage();
if ($la[$index] !== null && $la[$index] !== false) {
$la = (double) number_format($la[$index], 2);
}
} else {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$period = $farmRoleMetric->getSetting(self::SETTING_LA_PERIOD);
if (!$period) {
$period = '15';
}
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids[$period]);
$la = (double) $res;
}
$retval[] = $la;
} catch (Exception $e) {
Logger::getLogger(__CLASS__)->warn(new FarmLogMessage($DBServer->farmId, sprintf("Unable to read LoadAverage value from server %s: %s", $DBServer->remoteIp, $e->getMessage())));
}
}
return count($retval) > 0 ? $retval : false;
}
示例8: farmUpdateRoleSettings
public static function farmUpdateRoleSettings(DBFarmRole $DBFarmRole, $oldSettings, $newSettings)
{
$db = \Scalr::getDb();
if (!$newSettings[DBFarmRole::SETTING_AWS_USE_EBS] && $oldSettings[DBFarmRole::SETTING_AWS_USE_EBS]) {
$db->Execute("DELETE FROM ec2_ebs WHERE farm_roleid = ? AND ismanual='0'", array($DBFarmRole->ID));
//TODO: Remove Volume?
}
$DBFarm = $DBFarmRole->GetFarmObject();
if ($newSettings[DBFarmRole::SETTING_AWS_USE_EBS] && !$oldSettings[DBFarmRole::SETTING_AWS_USE_EBS]) {
$servers = $DBFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
foreach ($servers as $DBServer) {
if (!$db->GetRow("SELECT id FROM ec2_ebs WHERE server_id=? AND ismanual='0' LIMIT 1", array($DBServer->serverId))) {
if (in_array($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_TYPE), array('standard', 'io1'))) {
$type = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_TYPE);
} else {
$type = 'standard';
}
$DBEBSVolume = new DBEBSVolume();
$DBEBSVolume->attachmentStatus = EC2_EBS_ATTACH_STATUS::CREATING;
$DBEBSVolume->isManual = false;
$DBEBSVolume->ec2AvailZone = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AVAIL_ZONE);
$DBEBSVolume->ec2Region = $DBFarmRole->CloudLocation;
$DBEBSVolume->farmId = $DBFarmRole->FarmID;
$DBEBSVolume->farmRoleId = $DBFarmRole->ID;
$DBEBSVolume->serverId = $DBServer->serverId;
$DBEBSVolume->serverIndex = $DBServer->index;
$DBEBSVolume->type = $type;
$DBEBSVolume->iops = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_IOPS);
$DBEBSVolume->size = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_SIZE);
$DBEBSVolume->snapId = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_SNAPID);
$DBEBSVolume->mount = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNT);
$DBEBSVolume->mountPoint = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT);
$DBEBSVolume->mountStatus = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNT) ? EC2_EBS_MOUNT_STATUS::AWAITING_ATTACHMENT : EC2_EBS_MOUNT_STATUS::NOT_MOUNTED;
$DBEBSVolume->clientId = $DBFarm->ClientID;
$DBEBSVolume->envId = $DBFarm->EnvID;
$DBEBSVolume->Save();
}
}
if ($newSettings[DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT] != $oldSettings[DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT]) {
$db->Execute("UPDATE ec2_ebs SET mountpoint=? WHERE farm_roleid=? AND ismanual='0'", array($DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_EBS_MOUNTPOINT), $DBFarmRole->ID));
}
}
}
示例9: farmUpdateRoleSettings
public static function farmUpdateRoleSettings(DBFarmRole $DBFarmRole, $oldSettings, $newSettings)
{
$db = Core::GetDBInstance();
$DBFarm = $DBFarmRole->GetFarmObject();
if (!$oldSettings[DBFarmRole::SETTING_AWS_USE_ELASIC_IPS] && $newSettings[DBFarmRole::SETTING_AWS_USE_ELASIC_IPS]) {
$servers = $DBFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
if (count($servers) == 0) {
return;
}
$AmazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($DBFarmRole->CloudLocation, $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $DBFarm->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
foreach ($servers as $DBServer) {
$address = $AmazonEC2Client->AllocateAddress();
$db->Execute("INSERT INTO elastic_ips SET env_id=?, farmid=?, farm_roleid=?, ipaddress=?, state='0', instance_id='', clientid=?, instance_index=?", array($DBServer->envId, $DBServer->farmId, $DBServer->farmRoleId, $address->publicIp, $DBServer->clientId, $DBServer->index));
Logger::getLogger(__CLASS__)->info(sprintf(_("Allocated new IP: %s"), $address->publicIp));
// Waiting...
Logger::getLogger(__CLASS__)->debug(_("Waiting 5 seconds..."));
sleep(5);
$assign_retries = 1;
while (true) {
try {
// Associate elastic ip address with instance
$AmazonEC2Client->AssociateAddress($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $address->publicIp);
} catch (Exception $e) {
if (!stristr($e->getMessage(), "does not belong to you") || $assign_retries == 3) {
throw new Exception($e->getMessage());
} else {
// Waiting...
Logger::getLogger(__CLASS__)->debug(_("Waiting 2 seconds..."));
sleep(2);
$assign_retries++;
continue;
}
}
break;
}
Logger::getLogger(__CLASS__)->info(sprintf(_("IP: %s assigned to instance '%s'"), $address->publicIp, $DBServer->serverId));
// Update leastic IPs table
$db->Execute("UPDATE elastic_ips SET state='1', server_id=? WHERE ipaddress=?", array($DBServer->serverId, $address->publicIp));
Scalr::FireEvent($DBFarmRole->FarmID, new IPAddressChangedEvent($DBServer, $address->publicIp));
}
}
}
示例10: getMongoClusterIndexes
public function getMongoClusterIndexes(DBFarmRole $dbFarmRole)
{
$shardsCount = (int) $dbFarmRole->GetSetting(self::ROLE_SHARDS_COUNT);
$replicasCount = (int) $dbFarmRole->GetSetting(self::ROLE_REPLICAS_COUNT);
$clusterMap = array();
$servers = $dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::PENDING_LAUNCH, SERVER_STATUS::PENDING, SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
foreach ($servers as $server) {
if ($server->GetProperty(self::SERVER_SHARD_INDEX) !== false && $server->GetProperty(self::SERVER_SHARD_INDEX) !== null) {
$clusterMap[$server->GetProperty(self::SERVER_SHARD_INDEX)][$server->GetProperty(self::SERVER_REPLICA_SET_INDEX)] = $server->status;
}
}
for ($shardIndex = 0; $shardIndex < $shardsCount; $shardIndex++) {
$isFirstReplicaInShardRunning = $clusterMap[$shardIndex][0] == SERVER_STATUS::RUNNING;
$nextShardIndex = $shardIndex + 1 < $shardsCount ? $shardIndex + 1 : false;
for ($replicaSetIndex = 0; $replicaSetIndex < $replicasCount; $replicaSetIndex++) {
$serverStatus = $clusterMap[$shardIndex][$replicaSetIndex];
// Checking config server (0-0)
if ($shardIndex == 0 && $replicaSetIndex == 0) {
if (is_null($serverStatus)) {
return array('shardIndex' => 0, 'replicaSetIndex' => 0);
}
// Waiting for config server
/*
if ($serverStatus != SERVER_STATUS::RUNNING) {
//var_dump('Waiting for config server');
return false;
}
*/
}
if ($nextShardIndex && count($clusterMap[$nextShardIndex]) < count($clusterMap[$shardIndex])) {
continue 2;
}
// if no running server at current position OR we're launching first server in shard
if ((is_null($serverStatus) || $serverStatus == SERVER_STATUS::PENDING_LAUNCH) && ($isFirstReplicaInShardRunning || $replicaSetIndex == 0)) {
return array('shardIndex' => $shardIndex, 'replicaSetIndex' => $replicaSetIndex);
}
}
}
return false;
}
示例11: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
if ($DBServer->IsSupported('0.13.0')) {
$szrClient = Scalr_Net_Scalarizr_Client::getClient($DBServer, Scalr_Net_Scalarizr_Client::NAMESPACE_SYSTEM, $DBServer->getPort(DBServer::PORT_API));
$ramUsage = $szrClient->memInfo();
$ram = (double) $ramUsage->total_free;
if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
$ram = $ram + (double) $ramUsage->cached;
}
} else {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids['memswap']);
preg_match_all("/[0-9]+/si", $res, $matches);
$ram = (double) $matches[0][0];
if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
$res = $this->snmpClient->get($this->snmpOids['cachedram']);
preg_match_all("/[0-9]+/si", $res, $matches);
$cram = (double) $matches[0][0];
$ram = $ram + $cram;
}
}
$retval[] = round($ram / 1024, 2);
}
return $retval;
}
示例12: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
$retval = array();
if (count($servers) == 0) {
return array();
}
foreach ($servers as $dbServer) {
$metrics = $dbServer->scalarizr->system->scalingMetrics();
foreach ($metrics as $metric) {
if ($metric->id == $farmRoleMetric->metricId) {
if ($metric->error) {
\Scalr::getContainer()->logger(__CLASS__)->warn(new FarmLogMessage($dbServer->farmId, sprintf("Unable to read '%s' value from server %s: %s", $metric->name, $dbServer->getNameByConvention(), $metric->error), $dbServer->serverId));
} else {
$retval[] = $metric->value;
}
break;
}
}
}
return $retval;
}
示例13: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
if ($dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_EXCLUDE_DBMSR_MASTER) == 1) {
$isMaster = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1;
if ($isMaster) {
continue;
}
}
$ramUsage = $DBServer->scalarizr->system->memInfo();
$ram = (double) $ramUsage->total_free;
if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
$ram = $ram + (double) $ramUsage->cached;
}
$retval[] = round($ram / 1024, 2);
}
return $retval;
}
示例14: getValue
public function getValue(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric)
{
$servers = $dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING));
$dbFarm = $dbFarmRole->GetFarmObject();
if (count($servers) == 0) {
return false;
}
$retval = array();
foreach ($servers as $DBServer) {
$port = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_SNMP_PORT);
$this->snmpClient->connect($DBServer->remoteIp, $port ? $port : 161, $dbFarm->Hash, null, null, false);
$res = $this->snmpClient->get($this->snmpOids['memswap']);
preg_match_all("/[0-9]+/si", $res, $matches);
$ram = (double) $matches[0][0];
if ($farmRoleMetric->getSetting(self::SETTING_USE_CACHED)) {
$res = $this->snmpClient->get($this->snmpOids['cachedram']);
preg_match_all("/[0-9]+/si", $res, $matches);
$cram = (double) $matches[0][0];
$ram = $ram + $cram;
}
$retval[] = round($ram / 1024, 2);
}
return $retval;
}
示例15: getNodeType
private function getNodeType(DBFarmRole $dbFarmRole, DBServer $dbServer)
{
if ($dbServer->index == 1) {
return self::NODE_TYPE_DISK;
}
$ramServers = 0;
$diskServers = 0;
foreach ($dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::RUNNING, SERVER_STATUS::INIT))) as $server) {
if ($server->GetProperty(self::SERVER_NODE_TYPE) == self::NODE_TYPE_DISK) {
$diskServers++;
} elseif ($server->GetProperty(self::SERVER_NODE_TYPE) == self::NODE_TYPE_RAM) {
$ramServers++;
}
}
$totalServers = $ramServers + $diskServers;
$currentRatio = $totalServers != 0 ? $diskServers / $totalServers * 100 : 0;
$sRatio = (int) trim($dbFarmRole->GetSetting(self::ROLE_NODES_RATIO), "%");
//$this->logger->error(new FarmLogMessage($dbFarmRole->FarmID, "Total: {$totalServers}, Disk: {$diskServers}, Ram: {$ramServers}, Ratio: {$currentRatio}, sRatio: {$sRatio}"));
if ($currentRatio <= $sRatio) {
return self::NODE_TYPE_DISK;
} else {
return self::NODE_TYPE_RAM;
}
}