Skip to content

Commit

Permalink
<WEB 框架修改>
Browse files Browse the repository at this point in the history
  • Loading branch information
iceopen committed Apr 12, 2017
1 parent a511676 commit af9e62b
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions main.go
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
}

0 comments on commit af9e62b

Please sign in to comment.