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

scollector: include slab as free mem for linux os.mem #2250

Merged
merged 2 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions cmd/scollector/collectors/collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ const (
osDiskPctFreeDesc = "The percent_free property indicates what percentage of the disk is available."
osDiskTotalDesc = "The space_total property indicates in bytes how much total space is on the disk."
osDiskUsedDesc = "The space_used property indicates in bytes how much space is used on the disk."
osMemFreeDesc = "Number, in bytes, of physical memory currently unused and available."
osMemPctFreeDesc = "The percent of free memory. In Linux free memory includes memory used by buffers and cache."
osMemTotalDesc = "Total amount, in bytes, of physical memory available to the operating system."
osMemUsedDesc = "The amount of used memory. In Linux this excludes memory used by buffers and cache."
osMemFreeDesc = "The number of bytes of physical memory currently unused and available. In Linux this metric considers buffers, cache, and slab to be free memory."
osMemPctFreeDesc = "The percent of free memory. In Linux this metric considers buffers, cache, and slab to be free memory."
osMemTotalDesc = "The total amount of physical memory available in bytes to the operating system."
osMemUsedDesc = "The amount of used memory. In Linux this metric excludes buffers, cache, from used memory."
osNetAdminStatusDesc = "The desired state of the interface. The testing(3) state indicates that no operational packets can be passed. When a managed system initializes, all interfaces start with ifAdminStatus in the down(2) state. As a result of either explicit management action or per configuration information retained by the managed system, ifAdminStatus is then changed to either the up(1) or testing(3) states (or remains in the down(2) state)."
osNetBroadcastDesc = "The rate at which broadcast packets are sent or received on the network interface."
osNetBytesDesc = "The rate at which bytes are sent or received over the network interface."
Expand Down
13 changes: 7 additions & 6 deletions cmd/scollector/collectors/procstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func c_procstats_linux() (opentsdb.MultiDataPoint, error) {
}); err != nil {
Error = err
}
mem := make(map[string]float64)
mem := make(map[string]int64)
if err := readLine("/proc/meminfo", func(s string) error {
m := meminfoRE.FindStringSubmatch(s)
if m == nil {
return nil
}
i, err := strconv.ParseFloat(m[2], 64)
i, err := strconv.ParseInt(m[2], 10, 64)
if err != nil {
return err
}
Expand All @@ -70,11 +70,12 @@ func c_procstats_linux() (opentsdb.MultiDataPoint, error) {
}); err != nil {
Error = err
}
Add(&md, osMemTotal, int(mem["MemTotal"])*1024, nil, metadata.Gauge, metadata.Bytes, osMemTotalDesc)
Add(&md, osMemFree, (int(mem["MemFree"])+int(mem["Buffers"])+int(mem["Cached"]))*1024, nil, metadata.Gauge, metadata.Bytes, osMemFreeDesc)
Add(&md, osMemUsed, (int(mem["MemTotal"])-(int(mem["MemFree"])+int(mem["Buffers"])+int(mem["Cached"])))*1024, nil, metadata.Gauge, metadata.Bytes, osMemUsedDesc)
bufferCacheSlab := mem["Buffers"] + mem["Cached"] + mem["Slab"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of repetition of mem["stringConstant"] here. Would it make sense to define a few variables and reuse them?

Add(&md, osMemTotal, mem["MemTotal"]*1024, nil, metadata.Gauge, metadata.Bytes, osMemTotalDesc)
Add(&md, osMemFree, (mem["MemFree"]+bufferCacheSlab)*1024, nil, metadata.Gauge, metadata.Bytes, osMemFreeDesc)
Add(&md, osMemUsed, (mem["MemTotal"]-mem["MemFree"]+bufferCacheSlab)*1024, nil, metadata.Gauge, metadata.Bytes, osMemUsedDesc)
if mem["MemTotal"] != 0 {
Add(&md, osMemPctFree, (mem["MemFree"]+mem["Buffers"]+mem["Cached"])/mem["MemTotal"]*100, nil, metadata.Gauge, metadata.Pct, osMemFreeDesc)
Add(&md, osMemPctFree, (float64(mem["MemFree"])+float64(bufferCacheSlab))/float64(mem["MemTotal"])*100, nil, metadata.Gauge, metadata.Pct, osMemFreeDesc)
}

num_cores := 0
Expand Down