Example #1
0
 /**
  * 更新 RRD 库 
  * 
  * @param string $monitor_id 
  * @static
  * @access public
  * @return void
  */
 public static function update($monitor_key, $data, $time)
 {
     // 更新 rrd 数据库
     if (!isset(self::$__redis)) {
         self::$__redis = \swan\redis\sw_redis::singleton();
     }
     $file_name = sw_create::create($monitor_key);
     $monitor_info = self::$__redis->get(SWAN_CACHE_MONITOR_PREFIX . $monitor_key);
     if (!$monitor_info) {
         throw new sw_exception('create rrd file faild. reason is get monitor info fail.');
     }
     $monitor_info = json_decode($monitor_info, true);
     $madapter_id = $monitor_info['madapter_id'];
     $metrics = array();
     foreach ($data as $metric_id => $value) {
         // 获取metric info
         $metric_info = self::$__redis->get(SWAN_CACHE_METRIC_PREFIX . $madapter_id . '_' . $metric_id);
         if (!$metric_info) {
             throw new sw_exception('create rrd file faild. reason is get monitor metric info fail.');
         }
         $metric_info = json_decode($metric_info, true);
         $metrics[$metric_info['metric_name']] = $value;
     }
     try {
         $updater = new \RRDUpdater($file_name);
         $updater->update($metrics, $time);
     } catch (\Exception $e) {
         throw new sw_exception($e);
     }
 }
Example #2
0
<?php

require_once 'core.php';
use lib\rrd_store\sw_create;
$rev = sw_create::create('2_4');