Просмотр исходного кода

feat: update cloud config & go struct

HeWang 6 месяцев назад
Родитель
Сommit
1ea386eca9

+ 4 - 2
aarch64/pjibot_delivery/common/config/c_cloud.go

@@ -43,8 +43,9 @@ type ros struct {
 }
 
 type disk struct {
-	Name string `yaml:"name"`
-	Used uint64 `yaml:"used"`
+	Name string   `yaml:"name"`
+	Used uint64   `yaml:"used"`
+	Path []string `yaml:"path"`
 }
 type trigger struct {
 	Label  string   `yaml:"label"`
@@ -53,6 +54,7 @@ type trigger struct {
 
 type CollectLimitStruct struct {
 	Url   string `yaml:"url"`
+	Flag  int    `yaml:"flag"`
 	Day   int    `yaml:"day"`
 	Week  int    `yaml:"week"`
 	Month int    `yaml:"month"`

+ 3 - 0
aarch64/pjibot_delivery/配送机器人默认配置文件-cloud-config.yaml

@@ -1,6 +1,7 @@
 ---
 collect-limit:
   url: http://36.110.106.142:12341/web_server/collect_limit/can_collect
+  flag: 1 # 数采频率限制标志 0 - 关闭数采频率限制  1 - 开启数采频率限制
   day: 1
   week: 3
   month: 12
@@ -17,6 +18,8 @@ config-refresh-interval: 60
 disk:
   name: /dev/nvme0n1p1 # 磁盘名称
   used: 107000000000 # 磁盘占用阈值,单位bytes
+  path:
+    - /home/pji/cicv-data-closedloop
 has-one-msg: false
 bag-data-dir: /home/pji/cicv-data-closedloop/data/
 bag-copy-dir: /home/pji/cicv-data-closedloop/copy/

+ 3 - 1
aarch64/pjibot_guide/common/service/disk_clean.go

@@ -27,7 +27,9 @@ func DiskClean() {
 	for {
 		time.Sleep(1000 * time.Millisecond)
 		// 1 获取磁盘占用
-		diskUsed, _ := util.GetDiskUsed(commonConfig.CloudConfig.Disk.Name)
+		//diskUsed, _ := util.GetDiskUsed(commonConfig.CloudConfig.Disk.Name) // 获取整个磁盘空间
+
+		diskUsed, _ := util.GetDirectoryDiskUsed(commonConfig.CloudConfig.Disk.Path) // 获取指定目录空间
 		if diskUsed > commonConfig.CloudConfig.Disk.Used {
 			policy := commonConfig.PlatformConfig.TaskCachePolicy
 			c_log.GlobalLogger.Errorf("磁盘占用 %v 超过 %v,触发删除规则 %v", diskUsed, commonConfig.CloudConfig.Disk.Used, policyToDescription[policy])

+ 4 - 2
aarch64/pjibot_patrol/common/config/c_cloud.go

@@ -43,8 +43,9 @@ type ros struct {
 }
 
 type disk struct {
-	Name string `yaml:"name"`
-	Used uint64 `yaml:"used"`
+	Name string   `yaml:"name"`
+	Used uint64   `yaml:"used"`
+	Path []string `yaml:"path"`
 }
 type trigger struct {
 	Label  string   `yaml:"label"`
@@ -53,6 +54,7 @@ type trigger struct {
 
 type CollectLimitStruct struct {
 	Url   string `yaml:"url"`
+	Flag  int    `yaml:"flag"`
 	Day   int    `yaml:"day"`
 	Week  int    `yaml:"week"`
 	Month int    `yaml:"month"`

+ 3 - 0
aarch64/pjibot_patrol/巡检机器人默认配置文件-cloud-config.yaml

@@ -1,6 +1,7 @@
 ---
 collect-limit:
   url: http://36.110.106.142:12341/web_server/collect_limit/can_collect
+  flag: 1 # 数采频率限制标志 0 - 关闭数采频率限制  1 - 开启数采频率限制
   day: 1
   week: 3
   month: 12
@@ -17,6 +18,8 @@ config-refresh-interval: 60
 disk:
   name: /dev/nvme0n1p1 # 磁盘名称
   used: 100000000000 # 100G 磁盘占用阈值,单位bytes
+  path:
+    - /home/pji/cicv-data-closedloop
 has-one-msg-topic: false
 bag-data-dir: /home/pji/cicv-data-closedloop/data/
 bag-copy-dir: /home/pji/cicv-data-closedloop/copy/

+ 3 - 2
aarch64/pjisuv/common/config/c_cloud.go

@@ -35,8 +35,9 @@ type ros struct {
 	Nodes         []string `yaml:"nodes"`
 }
 type disk struct {
-	Name string `yaml:"name"`
-	Used uint64 `yaml:"used"`
+	Name string   `yaml:"name"`
+	Used uint64   `yaml:"used"`
+	Path []string `yaml:"path"`
 }
 
 type trigger struct {

+ 2 - 0
aarch64/pjisuv/多功能车-cloud-config.yaml

@@ -15,6 +15,8 @@ config-refresh-interval: 60
 disk:
   name: /dev/vdb # 磁盘名称
   used: 900000000000 # 磁盘占用阈值,单位bytes
+  path:
+    - /mnt/media/sda1/cicv-data-closedloop
 bag-data-dir: /mnt/media/sda1/cicv-data-closedloop/data/
 bag-copy-dir: /mnt/media/sda1/cicv-data-closedloop/copy/
 time-to-label-json-path: /mnt/media/sda1/cicv-data-closedloop/timeToLabel.json

+ 2 - 0
aarch64/pjisuv/金龙车-cloud-config.yaml

@@ -15,6 +15,8 @@ config-refresh-interval: 60
 disk:
   name: /dev/vdb # 磁盘名称
   used: 900000000000 # 磁盘占用阈值,单位bytes
+  path:
+    - /mnt/media/sda1/cicv-data-closedloop
 bag-data-dir: /mnt/media/sda1/cicv-data-closedloop/data/
 bag-copy-dir: /mnt/media/sda1/cicv-data-closedloop/copy/
 time-to-label-json-path: /mnt/media/sda1/cicv-data-closedloop/timeToLabel.json

+ 17 - 7
common/util/u_resource.go

@@ -140,19 +140,29 @@ func GetDiskUsed(filesystem string) (uint64, error) {
 
 // GetDirectoryDiskUsed 获取目录列表的总大小
 func GetDirectoryDiskUsed(directories []string) (uint64, error) {
-	cmd := exec.Command("du", "-s", directories[0])
+	cmd := exec.Command("du", "-s")
+	cmd.Args = append(cmd.Args, directories...)
 	output, err := cmd.CombinedOutput()
 	if err != nil {
+		fmt.Println(err)
 		return 0, err
 	}
 	lines := strings.Split(string(output), "\n")
-	fields := strings.Fields(lines[0])
-	parseUint, err := strconv.ParseUint(fields[0], 10, 64)
-	fmt.Println("parseUint", parseUint)
-	if err != nil {
-		return 0, err
+	sum := uint64(0)
+	for _, line := range lines {
+		if len(line) > 0 {
+			fmt.Println(line)
+			fields := strings.Fields(line)
+			parseUint, err := strconv.ParseUint(fields[0], 10, 64)
+			fmt.Println("parseUint", parseUint)
+			if err != nil {
+				fmt.Println(err)
+				return 0, err
+			}
+			sum += parseUint
+		}
 	}
-	return parseUint, nil
+	return sum, nil
 }
 
 // GetDiskUsagePercent 获取磁盘使用率