fix: resolved all vue-tsc errors

This commit is contained in:
0xJacky 2023-11-29 22:04:30 +08:00
parent d325dd7493
commit ab1adcfa3d
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
64 changed files with 675 additions and 451 deletions

View file

@ -6,18 +6,18 @@ import (
"time"
)
type Usage struct {
Time time.Time `json:"x"`
Usage interface{} `json:"y"`
type Usage[T uint64 | float64] struct {
Time time.Time `json:"x"`
Usage T `json:"y"`
}
var (
CpuUserRecord []Usage
CpuTotalRecord []Usage
NetRecvRecord []Usage
NetSentRecord []Usage
DiskWriteRecord []Usage
DiskReadRecord []Usage
CpuUserRecord []Usage[float64]
CpuTotalRecord []Usage[float64]
NetRecvRecord []Usage[uint64]
NetSentRecord []Usage[uint64]
DiskWriteRecord []Usage[uint64]
DiskReadRecord []Usage[uint64]
LastDiskWrites uint64
LastDiskReads uint64
LastNetSent uint64
@ -37,9 +37,10 @@ func init() {
now := time.Now()
// init record slices
for i := 100; i > 0; i-- {
u := Usage{Time: now.Add(time.Duration(-i) * time.Second), Usage: 0}
CpuUserRecord = append(CpuUserRecord, u)
CpuTotalRecord = append(CpuTotalRecord, u)
uf := Usage[float64]{Time: now.Add(time.Duration(-i) * time.Second), Usage: 0}
CpuUserRecord = append(CpuUserRecord, uf)
CpuTotalRecord = append(CpuTotalRecord, uf)
u := Usage[uint64]{Time: now.Add(time.Duration(-i) * time.Second), Usage: 0}
NetRecvRecord = append(NetRecvRecord, u)
NetSentRecord = append(NetSentRecord, u)
DiskWriteRecord = append(DiskWriteRecord, u)

View file

@ -41,14 +41,14 @@ func recordCpu(now time.Time) {
cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
cpuSystemUsage *= 100
u := Usage{
u := Usage[float64]{
Time: now,
Usage: cpuUserUsage,
}
CpuUserRecord = append(CpuUserRecord, u)
s := Usage{
s := Usage[float64]{
Time: now,
Usage: cpuUserUsage + cpuSystemUsage,
}
@ -75,11 +75,11 @@ func recordNetwork(now time.Time) {
if len(network) == 0 {
return
}
NetRecvRecord = append(NetRecvRecord, Usage{
NetRecvRecord = append(NetRecvRecord, Usage[uint64]{
Time: now,
Usage: network[0].BytesRecv - LastNetRecv,
})
NetSentRecord = append(NetSentRecord, Usage{
NetSentRecord = append(NetSentRecord, Usage[uint64]{
Time: now,
Usage: network[0].BytesSent - LastNetSent,
})
@ -96,11 +96,11 @@ func recordNetwork(now time.Time) {
func recordDiskIO(now time.Time) {
readCount, writeCount := getTotalDiskIO()
DiskReadRecord = append(DiskReadRecord, Usage{
DiskReadRecord = append(DiskReadRecord, Usage[uint64]{
Time: now,
Usage: readCount - LastDiskReads,
})
DiskWriteRecord = append(DiskWriteRecord, Usage{
DiskWriteRecord = append(DiskWriteRecord, Usage[uint64]{
Time: now,
Usage: writeCount - LastDiskWrites,
})

View file

@ -23,11 +23,11 @@ type MemStat struct {
}
type DiskStat struct {
Total string `json:"total"`
Used string `json:"used"`
Percentage float64 `json:"percentage"`
Writes Usage `json:"writes"`
Reads Usage `json:"reads"`
Total string `json:"total"`
Used string `json:"used"`
Percentage float64 `json:"percentage"`
Writes Usage[uint64] `json:"writes"`
Reads Usage[uint64] `json:"reads"`
}
func GetMemoryStat() (MemStat, error) {