123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-01-10 15:01:23
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-13 11:20:09
- */
- #include <monitor.h>
- namespace MIVA
- {
- std::shared_ptr<monitor> m_monitor = nullptr;
- monitor::monitor(){
- }
-
- monitor::~monitor(){
- this->Destory();
- }
-
- /**
- * @description: 释放
- * @param {*}
- * @return {*}
- */
- void monitor::Destory(){
- if(this->file != nullptr) fclose(this->file);
- }
- /**
- * @description: 创建实例
- * @param {*}
- * @return {*}
- */
- std::shared_ptr<monitor> monitor::CreateNew(){
- if(m_monitor == nullptr) m_monitor = std::make_shared<monitor>();
- return m_monitor;
- }
- /**
- * @description: 获取内存使用情况
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getMemoryUsage(){
- int32_t MemoryUsage = 0;
- this->file = fopen("/proc/meminfo","r");
- char keyword[20];
- char valuech[20];
- fscanf(file,"MemTotal: %s kB\n",keyword);
- //long mem = 0;
- //mem = atol(keyword)/1000;
- fscanf(file,"MemFree: %s kB\n",valuech);
- fscanf(file,"MemAvailable: %s kB\n",valuech);
- MemoryUsage=atol(valuech)/1000;
- if(this->file != nullptr) fclose(this->file);
- return MemoryUsage;
- }
- /**
- * @description: 获取Cpu使用情况
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getCpuUsage(){
- int32_t CpuUsage = 0;
- return CpuUsage;
- }
- /**
- * @description: 获取GPU使用情况
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getGpuUsage(){
- int32_t gpuUsage = 0;
- return gpuUsage;
- }
- /**
- * @description: 获取CPU温度
- * TODO
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getCpuTemp(){
- int32_t temp = 0;
- string shell = "cat /sys/class/thermal/thermal_zone0/temp";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- temp = std::atoi(iter->c_str());
- }
- return temp;
- }
- /**
- * @description: 获取GPU温度
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getGpuTemp(){
- int32_t temp = 0;
- string shell = "cat /sys/devices/virtual/thermal/thermal_zone1/temp";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- temp = std::atoi(iter->c_str());
- }
- return temp;
- }
- /**
- * @description: 获取AUX的温度
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getAUXTemp(){
- int32_t temp = 0;
- string shell = "cat /sys/devices/virtual/thermal/thermal_zone2/temp";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- temp = std::atoi(iter->c_str());
- }
- return temp;
- }
- /**
- * @description: 获取A0的温度
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getA0Temp(){
- int32_t temp = 0;
- string shell = "cat /sys/devices/virtual/thermal/thermal_zone3/temp";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- temp = std::atoi(iter->c_str());
- }
- return temp;
- }
- /**
- * @description: 获取Thermal的温度
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getThermalTemp(){
- int32_t temp = 0;
- string shell = "cat /sys/devices/virtual/thermal/thermal_zone5/temp";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- temp = std::atoi(iter->c_str());
- }
- return temp;
- }
- /**
- * @description: 获取文件句柄使用情况
- * @param {*}
- * @return {*}
- */
- int32_t monitor::getFdUsage(){
- int32_t fdUsage = 0;
- //string shell = "lsof -p $(pidof main) | wc -l";
- string shell = "cat ../../data/state/fdState";
- vector<string> results;
- CShell::exeShellCmd(shell, results);
- for(auto iter = results.begin(); iter != results.end(); iter++){
- fdUsage = std::atoi(iter->c_str());
- }
- return fdUsage;
- }
- } // namespace MIVA
|