@@ -36,6 +36,7 @@ using namespace std::chrono;
3636#include " common/FileSystemUtil.h"
3737#include " common/StringTools.h"
3838#include " host_monitor/Constants.h"
39+ #include " host_monitor/SystemInformationTools.h"
3940#include " host_monitor/common/FastFieldParser.h"
4041#include " logger/Logger.h"
4142
@@ -1148,4 +1149,48 @@ bool LinuxSystemInterface::GetProcessOpenFilesOnce(pid_t pid, ProcessFd& process
11481149
11491150 return true ;
11501151}
1152+
1153+ bool LinuxSystemInterface::InitGPUCollectorOnce (const FieldMap& fieldMap) {
1154+ if (!CheckGPUDevice ()) {
1155+ return false ;
1156+ }
1157+
1158+ if (!mDcgmCollector .IsLibraryLoaded ()) {
1159+ LOG_ERROR (sLogger , (" GPU collector initialization failed" , " DCGM library not loaded" ));
1160+ return false ;
1161+ }
1162+
1163+ if (!mDcgmCollector .CanInitialize ()) {
1164+ if (mDcgmCollector .IsFullyInitialized ()) {
1165+ LOG_INFO (sLogger , (" GPU collector already initialized" , " skipping initialization" ));
1166+ return true ;
1167+ } else {
1168+ LOG_ERROR (sLogger , (" GPU collector initialization failed" , " DCGM collector in invalid state" ));
1169+ return false ;
1170+ }
1171+ }
1172+
1173+ if (!mDcgmCollector .Initialize (fieldMap)) {
1174+ LOG_ERROR (sLogger , (" GPU collector initialization failed" , " DCGM initialization error" ));
1175+ return false ;
1176+ }
1177+
1178+ return true ;
1179+ }
1180+
1181+ bool LinuxSystemInterface::GetGPUInformationOnce (GPUInformation& gpuInfo) {
1182+ if (!mDcgmCollector .IsFullyInitialized ()) {
1183+ LOG_ERROR (sLogger , (" GPU data retrieval failed" , " DCGM collector not ready" ));
1184+ return false ;
1185+ }
1186+
1187+ bool success = mDcgmCollector .Collect (gpuInfo);
1188+ if (!success) {
1189+ LOG_ERROR (sLogger , (" GPU data retrieval failed" , " collection operation failed" ));
1190+ } else {
1191+ LOG_DEBUG (sLogger , (" GPU data retrieval successful" , " metrics collected" )(" gpu_count" , gpuInfo.stats .size ()));
1192+ }
1193+
1194+ return success;
1195+ }
11511196} // namespace logtail
0 commit comments