diff --git a/machinery/src/cloud/Cloud.go b/machinery/src/cloud/Cloud.go index d6f2fd4d..62dcd7fe 100644 --- a/machinery/src/cloud/Cloud.go +++ b/machinery/src/cloud/Cloud.go @@ -95,6 +95,9 @@ func GetSystemInfo() (models.System, error) { var usedMem uint64 = 0 var totalMem uint64 = 0 var freeMem uint64 = 0 + + var processUsedMem uint64 = 0 + architecture := "" cpuId := "" KernelVersion := "" @@ -133,18 +136,27 @@ func GetSystemInfo() (models.System, error) { } } + process, err := sysinfo.Self() + if err == nil { + memInfo, err := process.Memory() + if err == nil { + processUsedMem = memInfo.Resident + } + } + system := models.System{ - Hostname: hostname, - CPUId: cpuId, - KernelVersion: KernelVersion, - Version: agentVersion, - MACs: MACs, - IPs: IPs, - BootTime: uint64(bootTime.Unix()), - Architecture: architecture, - UsedMemory: usedMem, - TotalMemory: totalMem, - FreeMemory: freeMem, + Hostname: hostname, + CPUId: cpuId, + KernelVersion: KernelVersion, + Version: agentVersion, + MACs: MACs, + IPs: IPs, + BootTime: uint64(bootTime.Unix()), + Architecture: architecture, + UsedMemory: usedMem, + TotalMemory: totalMem, + FreeMemory: freeMem, + ProcessUsedMemory: processUsedMem, } return system, nil @@ -200,6 +212,11 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models. uptimeString := carbon.Parse(uptimeFormatted).DiffForHumans() uptimeString = strings.ReplaceAll(uptimeString, "ago", "") + // Do the same for boottime + bootTimeFormatted := time.Unix(int64(system.BootTime), 0).Format("2006-01-02 15:04:05") + boottimeString := carbon.Parse(bootTimeFormatted).DiffForHumans() + boottimeString = strings.ReplaceAll(boottimeString, "ago", "") + // We'll check which mode is enabled for the camera. onvifEnabled := "false" if config.Capture.IPCamera.ONVIFXAddr != "" { @@ -239,6 +256,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models. "totalMemory" : "%d", "usedMemory" : "%d", "freeMemory" : "%d", + "processMemory" : "%d", "mac_list" : %s, "ip_list" : %s, "board" : "", @@ -246,6 +264,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models. "disk3size" : "%s", "diskvdasize" : "%s", "uptime" : "%s", + "boot_time" : "%s", "siteID" : "%s", "onvif" : "%s", "numberoffiles" : "33", @@ -254,7 +273,7 @@ func HandleHeartBeat(configuration *models.Configuration, communication *models. "docker" : true, "kios" : false, "raspberrypi" : false - }`, config.Key, system.Version, system.CPUId, username, key, name, isEnterprise, system.Hostname, system.Architecture, system.TotalMemory, system.UsedMemory, system.FreeMemory, macs, ips, "0", "0", "0", uptimeString, config.HubSite, onvifEnabled) + }`, config.Key, system.Version, system.CPUId, username, key, name, isEnterprise, system.Hostname, system.Architecture, system.TotalMemory, system.UsedMemory, system.FreeMemory, system.ProcessUsedMemory, macs, ips, "0", "0", "0", uptimeString, boottimeString, config.HubSite, onvifEnabled) var jsonStr = []byte(object) buffy := bytes.NewBuffer(jsonStr) diff --git a/machinery/src/models/System.go b/machinery/src/models/System.go index 0e873a1e..e29a54b6 100644 --- a/machinery/src/models/System.go +++ b/machinery/src/models/System.go @@ -1,16 +1,17 @@ package models type System struct { - CPUId string `json:"cpu_idle" bson:"cpu_idle"` - Hostname string `json:"hostname" bson:"hostname"` - Version string `json:"version" bson:"version"` - Release string `json:"release" bson:"release"` - BootTime uint64 `json:"boot_time" bson:"boot_time"` - KernelVersion string `json:"kernel_version" bson:"kernel_version"` - MACs []string `json:"macs" bson:"macs"` - IPs []string `json:"ips" bson:"ips"` - Architecture string `json:"architecture" bson:"architecture"` - UsedMemory uint64 `json:"used_memory" bson:"used_memory"` - TotalMemory uint64 `json:"total_memory" bson:"total_memory"` - FreeMemory uint64 `json:"free_memory" bson:"free_memory"` + CPUId string `json:"cpu_idle" bson:"cpu_idle"` + Hostname string `json:"hostname" bson:"hostname"` + Version string `json:"version" bson:"version"` + Release string `json:"release" bson:"release"` + BootTime uint64 `json:"boot_time" bson:"boot_time"` + KernelVersion string `json:"kernel_version" bson:"kernel_version"` + MACs []string `json:"macs" bson:"macs"` + IPs []string `json:"ips" bson:"ips"` + Architecture string `json:"architecture" bson:"architecture"` + UsedMemory uint64 `json:"used_memory" bson:"used_memory"` + TotalMemory uint64 `json:"total_memory" bson:"total_memory"` + FreeMemory uint64 `json:"free_memory" bson:"free_memory"` + ProcessUsedMemory uint64 `json:"process_used_memory" bson:"process_used_memory"` } diff --git a/machinery/src/utils/main.go b/machinery/src/utils/main.go index cd05f672..6d36f04d 100644 --- a/machinery/src/utils/main.go +++ b/machinery/src/utils/main.go @@ -271,108 +271,3 @@ func CreateFragmentedMP4(fullName string, fragmentedDuration int64) { os.Remove(fullName) os.Rename(fullName+"f.mp4", fullName) } - -/*func FloatToString(input_num float64) string { - // to convert a float number to a string - return strconv.FormatFloat(input_num, 'f', 6, 64) -} - -func ParseFMP4(file *bytes.Reader) (error, uint64, uint64, []*mp4.MediaSegment, uint64) { - var ftypSize, moovSize uint64 - var segments []*mp4.MediaSegment - var duration uint64 - parsedMp4, err := mp4.DecodeFile(file, mp4.WithDecodeMode(mp4.DecModeLazyMdat)) - if parsedMp4 != nil && parsedMp4.Init != nil && err == nil { - ftypSize = parsedMp4.Init.Ftyp.Size() - moovSize = parsedMp4.Init.Moov.Size() - duration = parsedMp4.Moov.Trak.Tkhd.Duration - segments = parsedMp4.Segments - } - return err, ftypSize, moovSize, segments, duration -} - -func ParseFMP4Detail(fullName string) { - - // open fullName - file, err := os.Open(fullName) - if err != nil { - log.Log.Error("Error opening file: " + err.Error()) - } - defer file.Close() - - fileBytes, err := ioutil.ReadAll(file) - if err != nil { - log.Log.Error("Error reading file: " + err.Error()) - } - fileReader := bytes.NewReader(fileBytes) - - err, ftypSize, moovSize, segments, dur := ParseFMP4(fileReader) - fmt.Println("========== Fragmented details =================") - fmt.Println(dur) - fmt.Println(ftypSize) - fmt.Println(moovSize) - fmt.Println(len(segments)) - - // Calculate duration of segments - var totalDuration uint64 - for _, segment := range segments { - fragments := segment.Fragments - - for _, fragment := range fragments { - var sampleDuration uint32 - samples := fragment.Moof.Traf.Trun.Samples - for _, sample := range samples { - sampleDuration += sample.Dur - } - fmt.Println(sampleDuration) - totalDuration += uint64(sampleDuration) - } - } - - misingDuration := dur - totalDuration/100 - fmt.Println(misingDuration) - fmt.Println(totalDuration/100 + misingDuration) -} - -func CreateFragmentByteRanges(log log.Logging, fileName string, ftypSize uint64, moovSize uint64, segments []*mp4.MediaSegment) (string, []models.BytesRangeOnTime) { - size := strconv.FormatInt(int64(ftypSize+moovSize), 10) - - var fileFragments strings.Builder - fileFragments.WriteString("#EXT-X-MAP:URI=\"" + fileName + "\",BYTERANGE=\"" + size + "@0\"\n") - - var bytesRangeOnTime []models.BytesRangeOnTime - var currentTime uint32 - for _, segment := range segments { - fragments := segment.Fragments - for _, fragment := range fragments { - var sampleDuration uint32 - samples := fragment.Moof.Traf.Trun.Samples - for _, sample := range samples { - sampleDuration += sample.Dur - } - currentTime = currentTime + sampleDuration - duration := FloatToString(float64(sampleDuration / 100000)) - - startPos := fragment.Moof.StartPos - start := strconv.FormatInt(int64(startPos), 10) - - totalSize := fragment.Mdat.Size() + fragment.Moof.Size() - size := strconv.FormatInt(int64(totalSize), 10) - - fileFragments.WriteString("#EXTINF:" + duration + ",\n") // @TODO calculate the duration - fileFragments.WriteString("#EXT-X-BYTERANGE:" + size + "@" + start + "\n") - fileFragments.WriteString(fileName + "\n") - - byteRange := models.BytesRangeOnTime{ - Duration: duration, - Time: FloatToString(float64(currentTime) / 100000), - Range: size + "@" + start, - } - bytesRangeOnTime = append(bytesRangeOnTime, byteRange) - } - } - - bytesRanges := fileFragments.String() - log.Info("Fragments calculate from " + fileName + ": " + bytesRanges) - return bytesRanges, bytesRangeOnTime -}*/