Skip to content

Commit 650bc5d

Browse files
committed
update
1 parent 4d07f9e commit 650bc5d

File tree

9 files changed

+49
-54
lines changed

9 files changed

+49
-54
lines changed

controller/dashboard.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@
88
package controller
99

1010
import (
11-
"github.com/gin-gonic/gin"
1211
"net/http"
13-
"pi-monitor/device"
12+
13+
"github.com/gin-gonic/gin"
1414
)
1515

1616
func Dashboard(c *gin.Context) {
17-
var data = gin.H{}
18-
var host = device.GetHost()
19-
20-
data["title"] = host.Vendor + " Monitor"
21-
data["host"] = host
22-
23-
c.HTML(http.StatusOK, "dashboard.tmpl", data)
17+
c.HTML(http.StatusOK, "index.html", gin.H{})
2418
}

main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ import (
1212
)
1313

1414
func main() {
15-
//service.InitNetStat()
16-
//service.GetNet()
17-
// service.GetDisk()
18-
// return
1915
route.Run()
2016
}

pi-monitor

12 MB
Binary file not shown.

route/route.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
package route
99

1010
import (
11-
"pi-monitor/api"
1211
"pi-monitor/controller"
1312
"pi-monitor/websocket"
1413
)
1514

1615
func route() {
17-
server.Gin.LoadHTMLGlob("views/**/*")
18-
server.Gin.Static("static/", "static/")
16+
server.Gin.LoadHTMLFiles("web/index.html")
17+
server.Gin.Static("assets/", "web/assets/")
1918
server.Gin.GET("/", controller.Dashboard)
2019
server.Gin.GET("/ws", websocket.HandleWebSocket)
21-
server.Gin.GET("/api/get", api.Collect)
20+
//server.Gin.GET("/api/get", api.Collect)
2221
}

service/disk.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/wonderivan/logger"
66
)
77

8-
type device struct {
8+
type Device struct {
99
Name string
1010
Mountpoint string
1111
Fstype string
@@ -15,17 +15,19 @@ type device struct {
1515
UsedPercent float64
1616
}
1717

18-
var Disks []*device
18+
//var Disks []*Device
19+
20+
func GetDisk() []*Device {
21+
var Disks []*Device
1922

20-
func GetDisk() []*device {
2123
partitions, err := disk.Partitions(false)
2224
if err != nil {
2325
logger.Error(err)
2426
}
2527

2628
for _, dev := range partitions {
2729

28-
d := &device{}
30+
d := &Device{}
2931
d.Name = dev.Device
3032
d.Mountpoint = dev.Mountpoint
3133
d.Fstype = dev.Fstype

service/host.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414
)
1515

1616
type Host struct {
17-
Hostname string // 主机名
18-
OS string // 系统版本
19-
Vendor string // 厂家
20-
Model string // 硬件版本
21-
Serial string // 序列号
22-
BootTime string // 启动时间
23-
Kernal string // 内核信息
24-
InterfaceNum int // 网卡数
25-
Disks []*device // 存储设备
17+
Hostname string // 主机名
18+
OS string // 系统版本
19+
Vendor string // 厂家
20+
Model string // 硬件版本
21+
Serial string // 序列号
22+
BootTime string // 启动时间
23+
Kernal string // 内核信息
24+
InterfaceNum int // 网卡数
25+
//Disks []*Device // 存储设备
2626
}
2727

2828
type UpTime struct {
@@ -100,17 +100,17 @@ func kernel() {
100100
}
101101

102102
func netInterface() {
103-
n := GetNet().Interface
104-
nt := &netInter{}
105-
nt.Count = len(n)
106-
for _, val := range n {
107-
nt.Names = append(nt.Names, val.Name)
108-
}
103+
// n := GetNet().Interface
104+
// nt := &netInter{}
105+
// nt.Count = len(n)
106+
// for _, val := range n {
107+
// nt.Names = append(nt.Names, val.Name)
108+
// }
109109
}
110110

111-
func diskDevice() {
112-
hostInfo.Disks = GetDisk()
113-
}
111+
// func diskDevice() {
112+
// hostInfo.Disks = GetDisk()
113+
// }
114114

115115
//readLine 读取文件第一行
116116
func readLine(path string) string {
@@ -251,8 +251,8 @@ func getHost() {
251251
serial()
252252
bootTime(info.BootTime)
253253
kernel()
254-
hostInfo.InterfaceNum = len(GetNet().Interface)
255-
diskDevice()
254+
hostInfo.InterfaceNum = len(GetNet())
255+
//diskDevice()
256256
}
257257

258258
func GetHost() *Host {

service/net.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
)
99

1010
type Net struct {
11-
Interface []*inter
11+
Interface []*Inter
1212
}
1313

14-
type inter struct {
14+
type Inter struct {
1515
Name string
1616
HardwareAddr string
1717
Addrs net.InterfaceAddrList
@@ -44,7 +44,7 @@ func loadNetStat() []net.IOCountersStat {
4444
// logger.Debug(netLastTime)
4545
// }
4646

47-
func GetNet() *Net {
47+
func GetNet() []*Inter {
4848

4949
list, err := net.Interfaces()
5050
if err != nil {
@@ -56,7 +56,8 @@ func GetNet() *Net {
5656
logger.Error(err)
5757
}
5858

59-
n := &Net{}
59+
//n := &Net{}
60+
var Interface []*Inter
6061

6162
time.Sleep(time.Second)
6263

@@ -72,11 +73,11 @@ func GetNet() *Net {
7273
if len(netLastStat) != 0 {
7374
old := search(val.Name, netLastStat)
7475
diff = float64(timeNow.UnixNano()/1e6-netLastTime.UnixNano()/1e6) / 1000
75-
recv = float64(s.BytesRecv-old.BytesRecv) / diff / 1024
76-
send = float64(s.BytesSent-old.BytesSent) / diff / 1024
76+
recv = float64(s.BytesRecv-old.BytesRecv) / diff
77+
send = float64(s.BytesSent-old.BytesSent) / diff
7778
}
7879

79-
i := &inter{
80+
i := &Inter{
8081
Name: val.Name,
8182
HardwareAddr: val.HardwareAddr,
8283
Addrs: val.Addrs,
@@ -95,13 +96,13 @@ func GetNet() *Net {
9596
// logger.Info("BytesSent:", s.BytesSent)
9697
// logger.Info("BytesSent:", old.BytesSent)
9798
// }
98-
n.Interface = append(n.Interface, i)
99+
Interface = append(Interface, i)
99100
}
100101

101102
netLastStat = stat[:]
102103
netLastTime = timeNow
103104

104-
return n
105+
return Interface
105106
}
106107

107108
func search(name string, stat []net.IOCountersStat) net.IOCountersStat {

service/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Index(c *gin.Context) {
1919
data["boottime"] = host.BootTime
2020
data["kernal"] = host.Kernal
2121
data["netCount"] = host.InterfaceNum
22-
data["disks"] = host.Disks
22+
//data["disks"] = host.Disks
2323

2424
c.HTML(http.StatusOK, "home.tmpl", data)
2525
}

websocket/websocket.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ type statistics struct {
1414
Host *service.Host
1515
CPU *service.CPU
1616
Memory *service.Memory
17-
Net *service.Net
17+
Disks []*service.Device
18+
NetDev []*service.Inter
1819
}
1920

2021
var upgrader = websocket.Upgrader{
@@ -38,7 +39,8 @@ func init() {
3839
Host: service.GetHost(),
3940
CPU: service.GetCPU(),
4041
Memory: service.GetMem(),
41-
Net: service.GetNet(),
42+
Disks: service.GetDisk(),
43+
NetDev: service.GetNet(),
4244
}
4345

4446
for _, conn := range Conns {
@@ -86,7 +88,8 @@ func Write(conn *websocket.Conn) {
8688
Host: service.GetHost(),
8789
CPU: service.GetCPU(),
8890
Memory: service.GetMem(),
89-
Net: service.GetNet(),
91+
Disks: service.GetDisk(),
92+
NetDev: service.GetNet(),
9093
}
9194
logger.Info("timesince:", time.Since(t1))
9295

0 commit comments

Comments
 (0)