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

build failure under go 1.5.3, ubuntu 14.04 #14

Open
hbprotoss opened this issue Feb 2, 2016 · 4 comments
Open

build failure under go 1.5.3, ubuntu 14.04 #14

hbprotoss opened this issue Feb 2, 2016 · 4 comments

Comments

@hbprotoss
Copy link

# go get github.com/statsd/system
# github.com/statsd/system/pkg/memory
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:66: cannot use stat (type *linux.MemInfo) as type linux.MemInfo in argument to percent
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:67: cannot use stat (type *linux.MemInfo) as type linux.MemInfo in argument to swapPercent
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:70: invalid operation: stat["MemTotal"] (type *linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:71: cannot use stat (type *linux.MemInfo) as type linux.MemInfo in argument to used
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:72: invalid operation: stat["MemFree"] (type *linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:73: invalid operation: stat["Active"] (type *linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:74: invalid operation: stat["SwapTotal"] (type *linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:75: invalid operation: stat["SwapFree"] (type *linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:93: invalid operation: s["SwapTotal"] (type linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:94: invalid operation: s["SwapFree"] (type linux.MemInfo does not support indexing)
/data/go/pkg/src/github.com/statsd/system/pkg/memory/memory.go:94: too many errors
@IBMRob
Copy link

IBMRob commented Nov 16, 2016

Seeing the same problem on Ubuntu 16.04 with go1.6.2 on xLinux.

@pedroarthur
Copy link

That's because MemInfo changed to a struct. Before that, it was a type MemInfo map[string]uint64. The easy fix is to checkout github.com/c9s/goprocinfo/linux to 1cb208c8060065fad6c43524586d01ee05a78a6a.

@kumashiro
Copy link

kumashiro commented Dec 14, 2017

This should fix it:

diff --git a/pkg/memory/memory.go b/pkg/memory/memory.go
index 6f80b15..fc83197 100644
--- a/pkg/memory/memory.go
+++ b/pkg/memory/memory.go
@@ -1,5 +1,4 @@
-//
-// Memory resource.
+// Package memory defines Memory resource.
 //
 // This collector reports on the following meminfo metrics:
 //
@@ -67,12 +66,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:
@@ -89,9 +88,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) {
@@ -102,8 +101,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) {
@@ -114,8 +113,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.

@awb99
Copy link

awb99 commented Jan 16, 2018

Thanks guys for fixing! Can you tell me how to apply the patch? I am not familiar with how go gets the packages from git before compiling. And I am unsure if your fix is already on git, or if I have to run it on the machine where I will compile it...

asteriskauto added a commit to asteriskauto/system that referenced this issue Jul 27, 2018
ivanvc added a commit to ivanvc/system that referenced this issue Oct 24, 2019
As stated in statsd#14, MemInfo changed from a map to a struct,
breaking the compilation of the project. Trying to make this commit to
master so it's not published as a patch and formalizes the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants