VOID RefreshHardwareInfo() { GPU_INFO gpuInfo; MC_TIMING_REPORT timingReport; DWORD brightness; Memory_Clear(&gpuInfo, sizeof(GPU_INFO)); PhpUpdateCpuInformation(); GPU_GetInfo(&gpuInfo); PushSharedMemory->HarwareInformation.Processor.MhzCurrent = CPU_GetSpeed(); PushSharedMemory->HarwareInformation.Processor.Load = GetCpuLoad(); PushSharedMemory->HarwareInformation.Processor.MaxCoreUsage = GetMaxCoreLoad(); PushSharedMemory->HarwareInformation.Processor.Temperature = GetCpuTemp(); PushSharedMemory->HarwareInformation.DisplayDevice.Load = gpuInfo.Load; PushSharedMemory->HarwareInformation.DisplayDevice.EngineClock = gpuInfo.EngineClock; PushSharedMemory->HarwareInformation.DisplayDevice.MemoryClock = gpuInfo.MemoryClock; PushSharedMemory->HarwareInformation.DisplayDevice.Voltage = gpuInfo.Voltage; PushSharedMemory->HarwareInformation.DisplayDevice.Temperature = gpuInfo.Temperature; PushSharedMemory->HarwareInformation.DisplayDevice.FrameBuffer.Used = gpuInfo.MemoryUsed; PushSharedMemory->HarwareInformation.DisplayDevice.FrameBuffer.Load = gpuInfo.MemoryUsage; PushSharedMemory->HarwareInformation.DisplayDevice.FanSpeed = gpuInfo.FanSpeed; PushSharedMemory->HarwareInformation.DisplayDevice.FanDutyCycle = gpuInfo.FanDutyCycle; PushSharedMemory->HarwareInformation.Memory.Used = GetRamUsed(); PushSharedMemory->HarwareInformation.Memory.Load = GetRamUsage(); if (DiskMonitorInitialized) PushSharedMemory->HarwareInformation.Disk.ReadWriteRate = GetDiskReadWriteRate(); DDCCIGetTimingReport(MonitorHandles[1], &timingReport); PushSharedMemory->HarwareInformation.Display.RefreshRate = timingReport.dwVerticalFrequencyInHZ / 100; DDCCIGetVCPFeature(MonitorHandles[1], VCP_BRIGHTNESS, NULL, &brightness, NULL); PushSharedMemory->HarwareInformation.Display.Brightness = brightness; }
void DSHeartbeatManager::Run(CThread * thread, void * arg) { //1.register int32_t error_register = 0; struct tm *time_now; time_t lt; lt = time(NULL); time_now = localtime(<); srand((unsigned)time(NULL)); int64_t time_next = ((config_->block_report_time_hour() - time_now->tm_hour + 24) % 24) * 3600000000 + ((config_->block_report_time_minite() - time_now->tm_min + 60) % 60) * 60000000 + //加上一个随机数避免所有DS在同一时间进行block report rand() % 120 * 60000000; if (0 == time_next) time_next = LAST_REPORT_INTERVAL; last_report_ = TimeUtil::GetTime() + time_next; //try register untill success while (false == DSRegister()) { //register fail 5 times, try connect to NS if (4 < error_register) { if (ds_impl_->net_server()->ConnectToNS()) error_register = 0; else LOGV(LL_ERROR, "Can not connect to NameServer"); } LOGV(LL_ERROR, "ds_register return error"); ++error_register; } LOGV(LL_DEBUG, "ds_register return success"); int32_t err_times = 0; const char *fs_path = config_->block_storage_directory().c_str(); while (1) { //2. send heartbeat every 10(default) sec int32_t ret_code = GetDiskUsage(fs_path, &ds_metrics_->used_space_, &ds_metrics_->total_space_); if (BLADE_FILESYSTEM_ERROR == ret_code) { LOGV(LL_ERROR, "get disk usage error."); ds_metrics_->used_space_ = -1; ds_metrics_->total_space_ = -1; } int32_t used_pecent = 0; int32_t total_space_log = ds_metrics_->total_space_ / (1024*1024*1024); if (0 != ds_metrics_->total_space_) { used_pecent = (ds_metrics_->used_space_)*100/ds_metrics_->total_space_; } int32_t ret_cpu_load = GetCpuLoad(); if (0 > ret_cpu_load) { LOGV(LL_ERROR, "get cpu load error."); ret_cpu_load = -1; } ds_metrics_->cpu_load_ = ret_cpu_load; ds_metrics_->num_connection_ = ds_impl_->num_connection(); //send heartbeat HeartbeatPacket * p = new HeartbeatPacket(rack_id_, ds_id_, *ds_metrics_); if (NULL == p) { LOGV(LL_ERROR, "new Heartbeatpacket error."); continue; } int32_t ret_pack = p->Pack(); if (BLADE_SUCCESS != ret_pack) { delete p; LOGV(LL_ERROR, "Heartbeatpacket packet pack error"); } uint64_t ns_id = config_->ns_id(); int64_t socket_fd = ds_impl_->net_server()->stream_handler()->end_point().GetFd(); uint64_t ns_id_use = BladeNetUtil::GetPeerID(socket_fd); if (ns_id_use != ns_id) { LOGV(LL_ERROR, "Error in the connection with NS,ns_id:%ld \ ns_id_use:%ld", ns_id, ns_id_use); sleep(DS_RECONNECT_NS_TIME); ds_impl_->net_server()->ConnectToNS(); delete p; continue; } int32_t error = Singleton<AmFrame>::Instance().SendPacket( ds_impl_->net_server()->stream_handler()->end_point(), p, true, NULL, NS_OP_TIMEOUT); if (0 == error) { err_times = 0; LOGV(LL_DEBUG, "heartbeat success.CPU:%d/total:%dGB/used:%d%/num:%d", ds_metrics_->cpu_load_, total_space_log, used_pecent, ds_metrics_->num_connection_); } else { LOGV(LL_ERROR, "send heartbeat error."); ++err_times; if (4 < err_times) { if (ds_impl_->net_server()->ConnectToNS()) err_times = 0; else LOGV(LL_ERROR, "Can not connect to NameServer"); } delete p; } //3.block report if needed if (last_report_ <= TimeUtil::GetTime()) { set<BlockInfo * > report; ds_impl_->dataset()->GetBlockReport(report); if (false == DSBlockReport(report)) { LOGV(LL_ERROR, "ds block report error"); } else { LOGV(LL_INFO, "ds block report success."); } } //4.sleep sleep(HEARTBEAT_INTERVAL_SECS); }