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

Initial XFS collector #568

Merged
merged 1 commit into from Apr 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ time | Exposes the current system time. | _any_
uname | Exposes system information as provided by the uname system call. | Linux
vmstat | Exposes statistics from `/proc/vmstat`. | Linux
wifi | Exposes WiFi device and station statistics. | Linux
xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+)
zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/)

### Disabled by default
Expand Down
25 changes: 25 additions & 0 deletions collector/fixtures/e2e-output.txt
Expand Up @@ -2143,6 +2143,7 @@ node_scrape_collector_success{collector="sockstat"} 1
node_scrape_collector_success{collector="stat"} 1
node_scrape_collector_success{collector="textfile"} 1
node_scrape_collector_success{collector="wifi"} 1
node_scrape_collector_success{collector="xfs"} 1
node_scrape_collector_success{collector="zfs"} 1
# HELP node_sockstat_FRAG_inuse Number of FRAG sockets in state inuse.
# TYPE node_sockstat_FRAG_inuse gauge
Expand Down Expand Up @@ -2222,6 +2223,30 @@ node_wifi_station_transmit_failed_total{device="wlan0"} 2
# HELP node_wifi_station_transmit_retries_total The total number of times a station has had to retry while sending a packet.
# TYPE node_wifi_station_transmit_retries_total counter
node_wifi_station_transmit_retries_total{device="wlan0"} 10
# HELP node_xfs_allocation_btree_compares_total Number of allocation B-tree compares for a filesystem.
# TYPE node_xfs_allocation_btree_compares_total counter
node_xfs_allocation_btree_compares_total{device="sda1"} 0
# HELP node_xfs_allocation_btree_lookups_total Number of allocation B-tree lookups for a filesystem.
# TYPE node_xfs_allocation_btree_lookups_total counter
node_xfs_allocation_btree_lookups_total{device="sda1"} 0
# HELP node_xfs_allocation_btree_records_deleted_total Number of allocation B-tree records deleted for a filesystem.
# TYPE node_xfs_allocation_btree_records_deleted_total counter
node_xfs_allocation_btree_records_deleted_total{device="sda1"} 0
# HELP node_xfs_allocation_btree_records_inserted_total Number of allocation B-tree records inserted for a filesystem.
# TYPE node_xfs_allocation_btree_records_inserted_total counter
node_xfs_allocation_btree_records_inserted_total{device="sda1"} 0
# HELP node_xfs_extent_allocation_blocks_allocated_total Number of blocks allocated for a filesystem.
# TYPE node_xfs_extent_allocation_blocks_allocated_total counter
node_xfs_extent_allocation_blocks_allocated_total{device="sda1"} 872
# HELP node_xfs_extent_allocation_blocks_freed_total Number of blocks freed for a filesystem.
# TYPE node_xfs_extent_allocation_blocks_freed_total counter
node_xfs_extent_allocation_blocks_freed_total{device="sda1"} 0
# HELP node_xfs_extent_allocation_extents_allocated_total Number of extents allocated for a filesystem.
# TYPE node_xfs_extent_allocation_extents_allocated_total counter
node_xfs_extent_allocation_extents_allocated_total{device="sda1"} 1
# HELP node_xfs_extent_allocation_extents_freed_total Number of extents freed for a filesystem.
# TYPE node_xfs_extent_allocation_extents_freed_total counter
node_xfs_extent_allocation_extents_freed_total{device="sda1"} 0
# HELP node_zfs_arc_anon_evictable_data kstat.zfs.misc.arcstats.anon_evictable_data
# TYPE node_zfs_arc_anon_evictable_data untyped
node_zfs_arc_anon_evictable_data 0
Expand Down
24 changes: 24 additions & 0 deletions collector/fixtures/sys/fs/xfs/sda1/stats/stats
@@ -0,0 +1,24 @@
extent_alloc 1 872 0 0
abt 0 0 0 0
blk_map 61 29 1 1 1 91 0
bmbt 0 0 0 0
dir 3 2 1 52
trans 4 40 0
ig 5 1 0 4 0 0 1
log 8 21 0 5821 4
push_ail 44 0 1102 15 0 2 0 2 0 2
xstrat 1 0
rw 28 0
attr 0 0 0 0
icluster 2 2 2
vnodes 4 0 0 0 1 1 1 0
buf 22 25 14 0 0 8 0 8 8
abtb2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
abtc2 2 1 1 1 0 0 0 0 0 0 0 0 0 0 0
bmbt2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ibt2 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0
fibt2 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0
rmapbt 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
qm 0 0 0 0 0 0 0 0
xpc 3571712 3568056 0
debug 0
140 changes: 140 additions & 0 deletions collector/xfs_linux.go
@@ -0,0 +1,140 @@
// 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.

package collector

import (
"fmt"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs/sysfs"
"github.com/prometheus/procfs/xfs"
)

// An xfsCollector is a Collector which gathers metrics from XFS filesystems.
type xfsCollector struct {
fs sysfs.FS
}

func init() {
Factories["xfs"] = NewXFSCollector
}

// NewXFSCollector returns a new Collector exposing XFS statistics.
func NewXFSCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}

return &xfsCollector{
fs: fs,
}, nil
}

// Update implements Collector.
func (c *xfsCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.XFSStats()
if err != nil {
return fmt.Errorf("failed to retrieve XFS stats: %v", err)
}

for _, s := range stats {
c.updateXFSStats(ch, s)
}

return nil
}

// updateXFSStats collects statistics for a single XFS filesystem.
func (c *xfsCollector) updateXFSStats(ch chan<- prometheus.Metric, s *xfs.Stats) {
const (
subsystem = "xfs"
)

var (
labels = []string{"device"}
)

// Metric names and descriptions are sourced from:
// http://xfs.org/index.php/Runtime_Stats.
//
// Each metric has a name that roughly follows the pattern of
// "node_xfs_category_value_total", using the categories and value names
// found on the XFS wiki.
//
// Note that statistics for more than one internal B-tree are measured,
// and as such, each one must be differentiated by name.
metrics := []struct {
name string
desc string
value float64
}{
{
name: "extent_allocation_extents_allocated_total",
desc: "Number of extents allocated for a filesystem.",
value: float64(s.ExtentAllocation.ExtentsAllocated),
},
{
name: "extent_allocation_blocks_allocated_total",
desc: "Number of blocks allocated for a filesystem.",
value: float64(s.ExtentAllocation.BlocksAllocated),
},
{
name: "extent_allocation_extents_freed_total",
desc: "Number of extents freed for a filesystem.",
value: float64(s.ExtentAllocation.ExtentsFreed),
},
{
name: "extent_allocation_blocks_freed_total",
desc: "Number of blocks freed for a filesystem.",
value: float64(s.ExtentAllocation.BlocksFreed),
},
{
name: "allocation_btree_lookups_total",
desc: "Number of allocation B-tree lookups for a filesystem.",
value: float64(s.AllocationBTree.Lookups),
},
{
name: "allocation_btree_compares_total",
desc: "Number of allocation B-tree compares for a filesystem.",
value: float64(s.AllocationBTree.Compares),
},
{
name: "allocation_btree_records_inserted_total",
desc: "Number of allocation B-tree records inserted for a filesystem.",
value: float64(s.AllocationBTree.RecordsInserted),
},
{
name: "allocation_btree_records_deleted_total",
desc: "Number of allocation B-tree records deleted for a filesystem.",
value: float64(s.AllocationBTree.RecordsDeleted),
},
}

for _, m := range metrics {
desc := prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, m.name),
m.desc,
labels,
nil,
)

ch <- prometheus.MustNewConstMetric(
desc,
prometheus.CounterValue,
m.value,
s.Name,
)
}
}
1 change: 1 addition & 0 deletions end-to-end-test.sh
Expand Up @@ -28,6 +28,7 @@ collectors=$(cat << COLLECTORS
bonding
megacli
wifi
xfs
zfs
COLLECTORS
)
Expand Down
2 changes: 1 addition & 1 deletion node_exporter.go
Expand Up @@ -32,7 +32,7 @@ import (
)

const (
defaultCollectors = "arp,conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,zfs"
defaultCollectors = "arp,conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,xfs,zfs"
)

var (
Expand Down
16 changes: 16 additions & 0 deletions vendor/github.com/prometheus/procfs/sysfs/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions vendor/github.com/prometheus/procfs/sysfs/fs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions vendor/github.com/prometheus/procfs/xfs/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/prometheus/procfs/xfs/xfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions vendor/vendor.json
Expand Up @@ -131,14 +131,20 @@
{
"checksumSHA1": "cD4xn1qxbkiuXqUExpdnDroCTrY=",
"path": "github.com/prometheus/procfs",
"revision": "a1dba9ce8baed984a2495b658c82687f8157b98f",
"revisionTime": "2017-02-16T22:32:56Z"
"revision": "332f6238064950a97bc3ed3f5421f6418537e707",
"revisionTime": "2017-04-21T21:58:51Z"
},
{
"checksumSHA1": "kOWRcAHWFkId0aCIOSOyjzC0Zfc=",
"checksumSHA1": "eiBAd4edewJTOtTwxh/ubJdjd+I=",
"path": "github.com/prometheus/procfs/sysfs",
"revision": "332f6238064950a97bc3ed3f5421f6418537e707",
"revisionTime": "2017-04-21T21:58:51Z"
},
{
"checksumSHA1": "xCiFAAwVTrjsfZT1BIJQ3DgeNCY=",
"path": "github.com/prometheus/procfs/xfs",
"revision": "a1dba9ce8baed984a2495b658c82687f8157b98f",
"revisionTime": "2017-02-16T22:32:56Z"
"revision": "332f6238064950a97bc3ed3f5421f6418537e707",
"revisionTime": "2017-04-21T21:58:51Z"
},
{
"checksumSHA1": "uozMgPjB4AggpuuJkGq3FgAs4CA=",
Expand Down