-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/go-martini/martini" | ||
"gopkg.in/gin-gonic/gin.v1" | ||
"github.com/shirou/gopsutil/mem" | ||
"github.com/shirou/gopsutil/cpu" | ||
"github.com/shirou/gopsutil/disk" | ||
"github.com/martini-contrib/render" | ||
"net/http" | ||
) | ||
|
||
func init() { | ||
martini.Env = martini.Prod | ||
} | ||
|
||
func main() { | ||
m := martini.Classic() | ||
m.Use(render.Renderer()) | ||
gin.SetMode("release") | ||
r := gin.Default() | ||
//SWAP大小 | ||
m.Get("/swap/info", func(r render.Render) { | ||
r.GET("/swap/info", func(c *gin.Context) { | ||
swap, _ := mem.SwapMemory() | ||
r.JSON(200, swap) | ||
c.JSON(200, swap) | ||
}) | ||
//虚拟内存 | ||
m.Get("/vmem/info", func(r render.Render) { | ||
r.GET("/vmem/info", func(c *gin.Context) { | ||
vmem, _ := mem.VirtualMemory() | ||
r.JSON(200, vmem) | ||
}) | ||
//CPU 运行时情况 | ||
m.Get("/cpu/time", func(r render.Render){ | ||
cpuTime, _ := cpu.Times(true) | ||
r.JSON(200, cpuTime) | ||
c.JSON(200, vmem) | ||
}) | ||
|
||
//CPU 信息详细 | ||
m.Get("/cpu/info",func(r render.Render){ | ||
r.GET("/cpu/info", func(c *gin.Context) { | ||
cpuinfo, _ := cpu.Info() | ||
r.JSON(200, cpuinfo) | ||
c.JSON(200, cpuinfo) | ||
}) | ||
|
||
//CPU 运行时情况 | ||
r.GET("/cpu/time", func(c *gin.Context) { | ||
cpuTime, _ := cpu.Times(true) | ||
c.JSON(200, cpuTime) | ||
}) | ||
////硬盘列表 信息详细 | ||
m.Get("/disk/list", func(r render.Render) { | ||
r.GET("/disk/list",func(c *gin.Context) { | ||
diskPart, _ := disk.Partitions(true) | ||
r.JSON(200, diskPart) | ||
c.JSON(200, diskPart) | ||
}) | ||
//硬盘使用 信息详细 | ||
m.Get("/disk/usage", func(r render.Render){ | ||
r.GET("/disk/usage", func(c *gin.Context) { | ||
diskInfo, _ := disk.Usage("/") | ||
r.JSON(200, diskInfo) | ||
c.JSON(200, diskInfo) | ||
}) | ||
//制定目录使用 信息详细 | ||
m.Post("/disk/path", func(r render.Render, req *http.Request){ | ||
path := req.FormValue("path") | ||
r.POST("/disk/path", func(c *gin.Context){ | ||
path := c.PostForm("path") | ||
diskInfo, _ := disk.Usage(path) | ||
r.JSON(200, diskInfo) | ||
c.JSON(200, diskInfo) | ||
}) | ||
//m.Run() | ||
m.RunOnAddr(":8848") | ||
r.Run(":8848") // listen and serve on 0.0.0.0:8080 | ||
} |