/** * 添加服务器 */ public function add() { $submit = $this->post('submit'); $server = $this->post('server'); $ip = $this->post('ip'); $port = $this->post_uint('port'); $os = $this->post('os'); $security_name = $this->post('security_name'); $pass_phrase = $this->post('pass_phrase'); $auth_protocol = $this->post('auth_protocol'); $priv_protocol = $this->post('priv_protocol'); if (!$submit && (!$server || $port <= 0 || !$ip || !$security_name || !$pass_phrase)) { view::assign('tips', PLEASE_INPUT_ALL); return; } mserver::add($server, $ip, $port, $os, $security_name, $pass_phrase, $auth_protocol, $priv_protocol); }
<?php //crontab $base = dirname(__FILE__) . '/'; require $base . '../config.php'; load_file(SHARE_ROOT . 'class/shareMysql.php'); $mysql = new shareMysql(DB_HOST, DB_USER, DB_PASS, DB_PRE, DB_NAME, DB_PORT, CHARSET); $servers = $mysql->select('server')->query(); load_file($base . '../model/server.php'); $t = microtime(true); $day_break = time::day_break(); foreach ($servers as $s) { echo "==========" . $s['name'] . "==============\r\n"; $ip = ip::long_to_ip($s['ip']); $security_name = mserver::decode_security_name($s); $pass_phrase = mserver::decode_pass_phrase($s); $snmp = new snmpworker($s['type'], $ip . ':' . $s['port'], $security_name, SNMP_AUTH_PRIV, $s['auth_protocol'], $pass_phrase, $s['priv_protocol'], $pass_phrase); $rs = $snmp->get('.1.3.6.1.4.1.2021'); $where = array(); //内存 $data = array(); $where['time'] = $day_break; $where['server_id'] = $s['id']; $data['now'] = $_SERVER['REQUEST_TIME']; $mem_total = clean($rs['UCD-SNMP-MIB::memTotalReal.0']); $mem_free = clean($rs['UCD-SNMP-MIB::memAvailReal.0']); $mem_buffers = clean($rs['UCD-SNMP-MIB::memBuffer.0']); $mem_cache = clean($rs['UCD-SNMP-MIB::memCached.0']); $data['mem_used'] = $mem_total - $mem_free - $mem_buffers - $mem_cache; echo "mem_used : " . $data['mem_used'] . "\r\n"; update_data('memory', $where, $data);