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

buddyinfo: Add support for /proc/buddyinfo for linux free memory fragmentation. #454

Merged
merged 7 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ The following individuals have contributed code to this repository
* Siavash Safi <siavash.safi@gmail.com>
* Stephen Shirley <kormat@gmail.com>
* Steve Durrheimer <s.durrheimer@gmail.com>
* Thorhallur Sverrisson <toti@toti.is>
* Tobias Schmidt <tobidt@gmail.com>
* Will Rouesnel <w.rouesnel@gmail.com>
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http
Name | Description | OS
---------|-------------|----
bonding | Exposes the number of configured and active slaves of Linux bonding interfaces. | Linux
buddyinfo | Exposes statistics of memory fragments as reported by /proc/buddyinfo. | Linux
devstat | Exposes device statistics | Dragonfly, FreeBSD
drbd | Exposes Distributed Replicated Block Device statistics | Linux
interrupts | Exposes detailed interrupts statistics. | Linux, OpenBSD
Expand Down
74 changes: 74 additions & 0 deletions collector/buddyinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2017 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !nobuddyinfo
// +build !windows,!netbsd

package collector

import (
"fmt"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/procfs"
)

const (
buddyInfoSubsystem = "buddyinfo"
)

type buddyinfoCollector struct {
desc *prometheus.Desc
}

func init() {
Factories["buddyinfo"] = NewBuddyinfoCollector
}

// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector() (Collector, error) {
desc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, buddyInfoSubsystem, "count"),
"Count of free blocks according to size.",
[]string{"node", "zone", "size"}, nil,
)
return &buddyinfoCollector{desc}, nil
}

// Update calls (*buddyinfoCollector).getBuddyInfo to get the platform specific
// buddyinfo metrics.
func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) (err error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return fmt.Errorf("failed to open procfs: %v", err)
}

buddyInfo, err := fs.NewBuddyInfo()
if err != nil {
return fmt.Errorf("couldn't get buddyinfo: %s", err)
}

log.Debugf("Set node_buddy: %#v", buddyInfo)
for _, entry := range buddyInfo {
for size, value := range entry.Sizes {
ch <- prometheus.MustNewConstMetric(
c.desc,
prometheus.GaugeValue, value,
entry.Node, entry.Zone, strconv.Itoa(size),
)
}
}
return nil
}
35 changes: 35 additions & 0 deletions collector/fixtures/e2e-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@ node_bonding_slaves{master="int"} 2
# HELP node_boot_time Node boot time, in unixtime.
# TYPE node_boot_time gauge
node_boot_time 1.418183276e+09
# HELP node_buddyinfo_count Count of free blocks according to size.
# TYPE node_buddyinfo_count gauge
node_buddyinfo_count{node="0",size="0",zone="DMA"} 1
node_buddyinfo_count{node="0",size="0",zone="DMA32"} 759
node_buddyinfo_count{node="0",size="0",zone="Normal"} 4381
node_buddyinfo_count{node="0",size="1",zone="DMA"} 0
node_buddyinfo_count{node="0",size="1",zone="DMA32"} 572
node_buddyinfo_count{node="0",size="1",zone="Normal"} 1093
node_buddyinfo_count{node="0",size="10",zone="DMA"} 3
node_buddyinfo_count{node="0",size="10",zone="DMA32"} 0
node_buddyinfo_count{node="0",size="10",zone="Normal"} 0
node_buddyinfo_count{node="0",size="2",zone="DMA"} 1
node_buddyinfo_count{node="0",size="2",zone="DMA32"} 791
node_buddyinfo_count{node="0",size="2",zone="Normal"} 185
node_buddyinfo_count{node="0",size="3",zone="DMA"} 0
node_buddyinfo_count{node="0",size="3",zone="DMA32"} 475
node_buddyinfo_count{node="0",size="3",zone="Normal"} 1530
node_buddyinfo_count{node="0",size="4",zone="DMA"} 2
node_buddyinfo_count{node="0",size="4",zone="DMA32"} 194
node_buddyinfo_count{node="0",size="4",zone="Normal"} 567
node_buddyinfo_count{node="0",size="5",zone="DMA"} 1
node_buddyinfo_count{node="0",size="5",zone="DMA32"} 45
node_buddyinfo_count{node="0",size="5",zone="Normal"} 102
node_buddyinfo_count{node="0",size="6",zone="DMA"} 1
node_buddyinfo_count{node="0",size="6",zone="DMA32"} 12
node_buddyinfo_count{node="0",size="6",zone="Normal"} 4
node_buddyinfo_count{node="0",size="7",zone="DMA"} 0
node_buddyinfo_count{node="0",size="7",zone="DMA32"} 0
node_buddyinfo_count{node="0",size="7",zone="Normal"} 0
node_buddyinfo_count{node="0",size="8",zone="DMA"} 1
node_buddyinfo_count{node="0",size="8",zone="DMA32"} 0
node_buddyinfo_count{node="0",size="8",zone="Normal"} 0
node_buddyinfo_count{node="0",size="9",zone="DMA"} 1
node_buddyinfo_count{node="0",size="9",zone="DMA32"} 0
node_buddyinfo_count{node="0",size="9",zone="Normal"} 0
# HELP node_context_switches Total number of context switches.
# TYPE node_context_switches counter
node_context_switches 3.8014093e+07
Expand Down
3 changes: 3 additions & 0 deletions collector/fixtures/proc/buddyinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Node 0, zone DMA 1 0 1 0 2 1 1 0 1 1 3
Node 0, zone DMA32 759 572 791 475 194 45 12 0 0 0 0
Node 0, zone Normal 4381 1093 185 1530 567 102 4 0 0 0 0
1 change: 1 addition & 0 deletions end-to-end-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -euf -o pipefail

collectors=$(cat << COLLECTORS
buddyinfo
conntrack
diskstats
drbd
Expand Down