Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from mdlayher/xfs-init
Initial XFS collector
- Loading branch information
Showing
11 changed files
with
306 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ collectors=$(cat << COLLECTORS | |
bonding | ||
megacli | ||
wifi | ||
xfs | ||
zfs | ||
COLLECTORS | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters