Преглед на файлове

加入monitor模块,实时监控设备状态

lishengyin преди 3 години
родител
ревизия
2feee4b19e

+ 3 - 1
CMakeLists.txt

@@ -23,6 +23,7 @@ option(build_userApp "build module userApp" ON)
 option(build_TCPClient "build module TCPClient" ON)
 option(build_recorder "build module recorder" ON)
 option(build_Cleaner "build modele Cleaner" ON)
+option(build_monitor "build modele monitor" ON)
 option(WITH_FFMPEG "with ffmpeg" ON)
 option(WITH_OPENCV "with opencv" ON)
 option(WITH_ZLMediaKit "with ZLMediaKit" OFF)
@@ -91,7 +92,7 @@ else()
 endif()
 
 
-##FFmpeg
+#FFmpeg
 if(WITH_FFMPEG)
   if(CMAKE_TOOLCHAIN_FILE)
     if(EXISTS ${PROJECT_SOURCE_DIR}/include/libavcodec)
@@ -158,6 +159,7 @@ include_directories(${PROJECT_SOURCE_DIR}/modules/dataType/include/)
 include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/include/)
 include_directories(${PROJECT_SOURCE_DIR}/modules/recorder/include/)
 include_directories(${PROJECT_SOURCE_DIR}/modules/Cleaner/include/)
+include_directories(${PROJECT_SOURCE_DIR}/modules/monitor/include/)
 
 include_directories(${ToolKit_Root})
 include_directories(${MediaKit_Root})

+ 7 - 0
cmake/FindFFmpeg.cmake

@@ -34,6 +34,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
             /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
   
     find_library(
@@ -43,6 +44,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
 	    /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu
     )
   
     find_library(
@@ -52,6 +54,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
 	    /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
  
     find_library(
@@ -61,6 +64,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
 	    /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
 
     find_library(
@@ -70,6 +74,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
 	    /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
 
     find_library(
@@ -79,6 +84,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
 	    /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
     find_library(
             FFMPEG_LIBAVDEVICE
@@ -87,6 +93,7 @@ else (FFMPEG_LIBRARIES AND FFMPEG_INCLUDE_DIR)
             /usr/lib64
             /usr/local/lib
             /usr/local/ffmpeg/lib
+            /usr/lib/aarch64-linux-gnu/
     )
   if (WITH_FFMPEG_AVDEVICE AND NOT FFMPEG_LIBAVDEVICE)
     message(FATAL_ERROR "Not find FFmpeg LIBAVDEVICE ")

+ 0 - 1
cmake/FindMYSQL.cmake

@@ -31,7 +31,6 @@ else(WIN32)
       $ENV{MYSQL_INCLUDE_DIR}
       $ENV{MYSQL_DIR}/include
       /usr/local/mysql/include
-      /opt/mysql/mysql/include
       PATH_SUFFIXES
       mysql
    )

BIN
lib/libmodules.so


+ 4 - 0
modules/CMakeLists.txt

@@ -43,6 +43,10 @@ if(build_Cleaner)
   list(APPEND module_list Cleaner)
   install(DIRECTORY Cleaner/include/ DESTINATION include)
 endif()
+if(build_monitor)
+  list(APPEND module_list monitor)
+  install(DIRECTORY monitor/include/ DESTINATION include)
+endif()
 
 if(HAVE_FFMPEG)
   include_directories(${FFMPEG_INCLUDE_DIR})

+ 2 - 1
modules/inference/src/inference.cpp

@@ -411,6 +411,7 @@ namespace MIVA{
                     if (obj_meta->class_id == 0) {
                         NvDsComp_BboxInfo boxInfo;
                         boxInfo = obj_meta->detector_bbox_info;
+                
                         NvBbox_Coords box_Coord;
                         box_Coord = boxInfo.org_bbox_coords;
                         Point p;
@@ -483,7 +484,7 @@ namespace MIVA{
                         NvDsComp_BboxInfo boxInfo;
                         boxInfo = obj_meta->detector_bbox_info;
                         NvBbox_Coords box_Coord;
-                        box_Coord = boxInfo.org_bbox_coords;
+                        box_Coord = boxInfo.org_bbox_coords; 
                         cv::Point top_left;
                         cv::Point bottom_right;
                         top_left.x = box_Coord.left;

+ 108 - 0
modules/monitor/include/monitor.h

@@ -0,0 +1,108 @@
+/*
+ * @Description: 
+ * @Version: 1.0
+ * @Autor: lishengyin
+ * @Date: 2022-01-10 15:01:15
+ * @LastEditors: lishengyin
+ * @LastEditTime: 2022-01-10 16:00:35
+ */
+#pragma once
+
+#include <iostream>
+#include <map>
+#include <time.h>
+#include <dirent.h>
+#include <time.h>
+#include <cstdlib>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "Util/logger.h"
+#include "Util/NoticeCenter.h"
+#include "Poller/EventPoller.h"
+#include "Player/PlayerProxy.h"
+#include "Rtmp/RtmpPusher.h"
+#include "Common/config.h"
+#include "Pusher/MediaPusher.h"
+#include "Extension/Frame.h"
+#include "Util/SqlPool.h"
+#include "Network/TcpClient.h"
+#include "Poller/Timer.h"
+
+using namespace toolkit;
+using namespace std;
+
+namespace MIVA
+{
+    class monitor
+    {
+    private:
+        FILE *file = nullptr;
+
+    public:
+        monitor();
+        ~monitor();
+
+        /**
+         * @description: 创建实例
+         * @param {*}
+         * @return {*}
+         */        
+        static std::shared_ptr<monitor> CreateNew();
+        
+        /**
+         * @description: 初始化
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t Init();
+
+        /**
+         * @description: 释放资源
+         * @param {*}
+         * @return {*}
+         */        
+        void Destory();
+
+        /**
+         * @description: 获取内存使用情况
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t getMemoryUsage();
+
+        /**
+         * @description: 获取Cpu使用情况
+         * TODO
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t getCpuUsage();
+
+        /**
+         * @description: 获取温度
+         * TODO
+         * @param {*}
+         * @return {*}
+         */      
+        int32_t getTemp();
+
+        /**
+         * @description: 获取Gpu使用情况
+         * TODO
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t getGpuUsage();
+
+        /**
+         * @description: 获取文件句柄使用情况
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t getFdUsage();
+    };
+} // namespace MIVA
+

+ 115 - 0
modules/monitor/src/monitor.cpp

@@ -0,0 +1,115 @@
+/*
+ * @Description: 
+ * @Version: 1.0
+ * @Autor: lishengyin
+ * @Date: 2022-01-10 15:01:23
+ * @LastEditors: lishengyin
+ * @LastEditTime: 2022-01-10 16:06:25
+ */
+#include <monitor.h>
+
+namespace MIVA
+{
+    std::shared_ptr<monitor> m_monitor = nullptr;
+    monitor::monitor(){
+
+    }
+    
+    monitor::~monitor(){
+        this->Destory();
+    }
+
+    /**
+     * @description: 初始化
+     * @param {*}
+     * @return {*}
+     */    
+    int32_t monitor::Init(){
+        this->file = fopen("/proc/meminfo","r");
+        if(this->file == nullptr) return -1;
+
+        return 0;
+    } 
+
+    /**
+     * @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;
+        char keyword[20];
+        char valuech[20];
+        long mem = 0;
+        fscanf(file,"MemTotal: %s kB\n",keyword);
+        mem = atol(keyword)/1000;
+        fscanf(file,"MemFree: %s kB\n",valuech);
+        fscanf(file,"MemAvailable: %s kB\n",valuech);
+        MemoryUsage=atol(valuech)/1000;
+        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: 获取温度
+     * TODO
+     * @param {*}
+     * @return {*}
+     */      
+    int32_t monitor::getTemp(){
+        int32_t temp = 0;
+
+        return temp;
+    }
+
+    /**
+     * @description: 获取文件句柄使用情况
+     * @param {*}
+     * @return {*}
+     */    
+    int32_t monitor::getFdUsage(){
+        int32_t fdUsage = 0;
+
+        return fdUsage;
+    }
+} // namespace MIVA

+ 2 - 0
modules/userApp/include/user_app.h

@@ -52,6 +52,7 @@
 #include "HttpClient.h"
 #include "recorder.h"
 #include "Cleaner.h"
+#include "monitor.h"
 #include <httplib.h>
 
 using namespace toolkit;
@@ -179,6 +180,7 @@ namespace MIVA
         std::shared_ptr<HttpClient> m_httpClient = NULL;
         std::shared_ptr<recorder> m_recorder = nullptr;
         std::shared_ptr<Cleaner> m_Cleaner = nullptr;
+        std::shared_ptr<monitor> m_monitor = nullptr;
 
         Socket::Ptr m_udpClient = NULL;
 

+ 13 - 6
modules/userApp/src/user_app.cpp

@@ -92,6 +92,8 @@ namespace MIVA
         
         this->m_recorder = recorder::CreateNew();
         this->m_Cleaner = Cleaner::CreateNew();
+        this->m_monitor = monitor::CreateNew();
+
         // 查询基础配置
         SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime FROM MIVA_DB.`MivaConfig`");
         sqlSelectConfig << sqlRet;
@@ -204,12 +206,13 @@ namespace MIVA
     void UserApp::Destroy()
     {
         InfoL << "System exited successfully!";
-        this->m_timer0 = NULL;
-        this->m_timer1 = NULL;
-        this->m_timer2 = NULL;
-        this->m_udpClient = NULL;
-        this->m_tcpClient = NULL; 
-        this->m_Infer = NULL;
+        this->m_timer0 = nullptr;
+        this->m_timer1 = nullptr;
+        this->m_timer2 = nullptr;
+        this->m_udpClient = nullptr;
+        this->m_tcpClient = nullptr; 
+        this->m_Infer = nullptr;
+        this->m_monitor = nullptr;
     }
     
     /**
@@ -550,6 +553,10 @@ namespace MIVA
     {
         vector<vector<string>> sqlRet;
         vector<DataSource>::iterator iter;
+        char ctime[80];
+        getDataTime(ctime);
+        SqlWriter sqlUpdate_DeviceState("UPDATE MIVA_DB.DeviceState SET CpuUsage='?',GpuUsage='?',MemoryUsage='?',Temp='?',FdUsage='?',updateTime='?'");
+        sqlUpdate_DeviceState << this->m_monitor->getCpuUsage() << this->m_monitor->getGpuUsage()  << this->m_monitor->getMemoryUsage() << this->m_monitor->getTemp() << this->m_monitor->getFdUsage() << ctime << sqlRet;
 
         SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime FROM MIVA_DB.`MivaConfig`");
         sqlSelectConfig << sqlRet;

+ 1 - 1
source/bin/config_infer_primary_yoloV5.txt

@@ -58,7 +58,7 @@ output-blob-names=prob
 interval=0
 maintain-aspect-ratio=1
 parse-bbox-func-name=NvDsInferParseCustomYoloV5
-custom-lib-path=/home/nvidia/work/MIVA/lib/libnvdsinfer_custom_impl_Yolo.so
+custom-lib-path=/home/lcfc/work/MIVA/lib/libnvdsinfer_custom_impl_Yolo.so
 engine-create-func-name=NvDsInferYoloCudaEngineGet
 #scaling-filter=0
 #scaling-compute-hw=0

BIN
source/bin/main