add agent
This commit is contained in:
@@ -1 +1,69 @@
|
||||
package cmii_uav_watchdog_agent
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmii-uav-watchdog-agent/services"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 创建一个默认的 Gin 路由
|
||||
var r = gin.Default() // 定义一个 GET 路由
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "pong"})
|
||||
})
|
||||
|
||||
// 定义一个 POST 路由
|
||||
r.POST("/echo", func(c *gin.Context) {
|
||||
var json map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&json); err == nil {
|
||||
c.JSON(http.StatusOK, json)
|
||||
} else {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
}
|
||||
})
|
||||
|
||||
r.GET("/cpu", func(c *gin.Context) {
|
||||
cpuInfo := services.GetCPUInfo() // 直接返回 CPU 信息
|
||||
c.JSON(http.StatusOK, cpuInfo)
|
||||
})
|
||||
|
||||
r.GET("/memory", func(c *gin.Context) {
|
||||
memInfo := services.GetMemoryInfo() // 直接返回内存信息
|
||||
c.JSON(http.StatusOK, memInfo)
|
||||
})
|
||||
|
||||
r.GET("/disk", func(c *gin.Context) {
|
||||
diskInfo := services.GetDiskInfo() // 直接返回磁盘信息
|
||||
c.JSON(http.StatusOK, diskInfo)
|
||||
})
|
||||
|
||||
r.GET("/motherboard", func(c *gin.Context) {
|
||||
mbInfo := services.GetMotherboardInfo() // 直接返回主板信息
|
||||
c.JSON(http.StatusOK, mbInfo)
|
||||
})
|
||||
|
||||
r.GET("/network", func(c *gin.Context) {
|
||||
networkInterfaces := services.GetNetworkInterfaces()
|
||||
c.JSON(http.StatusOK, networkInterfaces)
|
||||
})
|
||||
r.GET("/all", func(c *gin.Context) {
|
||||
allInfo := services.GetAllInfo()
|
||||
c.JSON(http.StatusOK, allInfo)
|
||||
})
|
||||
//r.GET("/phy", func(c *gin.Context) {
|
||||
// allInfo, _ := services.GetPVForLV()
|
||||
// c.JSON(http.StatusOK, allInfo)
|
||||
//})
|
||||
// 启动服务,监听在 8080 端口
|
||||
r.Run(":8098")
|
||||
// 等待终止信号
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigs
|
||||
fmt.Println("Shutting down service...")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user