Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error #17

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions pkg/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (m *Memory) Report() {
m.client.Gauge("swap.percent", swapPercent(stat))

if m.Extended {
m.client.Gauge("total", bytes(stat["MemTotal"]))
m.client.Gauge("total", bytes(stat.MemTotal))
m.client.Gauge("used", bytes(used(stat)))
m.client.Gauge("free", bytes(stat["MemFree"]))
m.client.Gauge("active", bytes(stat["Active"]))
m.client.Gauge("swap.total", bytes(stat["SwapTotal"]))
m.client.Gauge("swap.free", bytes(stat["SwapFree"]))
m.client.Gauge("free", bytes(stat.MemFree))
m.client.Gauge("active", bytes(stat.Active))
m.client.Gauge("swap.total", bytes(stat.SwapTotal))
m.client.Gauge("swap.free", bytes(stat.SwapFree))
}

case <-m.exit:
Expand All @@ -89,9 +89,9 @@ func (m *Memory) Stop() error {
}

// calculate swap percentage.
func swapPercent(s linux.MemInfo) int {
total := s["SwapTotal"]
used := total - s["SwapFree"]
func swapPercent(s *linux.MemInfo) int {
total := s.SwapTotal
used := total - s.SwapFree
p := float64(used) / float64(total) * 100

if math.IsNaN(p) {
Expand All @@ -102,8 +102,8 @@ func swapPercent(s linux.MemInfo) int {
}

// calculate percentage.
func percent(s linux.MemInfo) int {
total := s["MemTotal"]
func percent(s *linux.MemInfo) int {
total := s.MemTotal
p := float64(used(s)) / float64(total) * 100

if math.IsNaN(p) {
Expand All @@ -114,8 +114,8 @@ func percent(s linux.MemInfo) int {
}

// used memory.
func used(s linux.MemInfo) uint64 {
return s["MemTotal"] - s["MemFree"] - s["Buffers"] - s["Cached"]
func used(s *linux.MemInfo) uint64 {
return s.MemTotal - s.MemFree - s.Buffers - s.Cached
}

// convert to bytes.
Expand Down