2017-04-21 22:19:35 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-10-03 11:35:24 +00:00
|
|
|
//go:build !noxfs
|
2020-06-12 08:26:30 +00:00
|
|
|
// +build !noxfs
|
|
|
|
|
2017-04-21 22:19:35 +00:00
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-11-14 10:53:51 +00:00
|
|
|
"github.com/go-kit/log"
|
2017-04-21 22:19:35 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/procfs/xfs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// An xfsCollector is a Collector which gathers metrics from XFS filesystems.
|
|
|
|
type xfsCollector struct {
|
2019-12-31 16:19:37 +00:00
|
|
|
fs xfs.FS
|
|
|
|
logger log.Logger
|
2017-04-21 22:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2017-09-28 13:06:26 +00:00
|
|
|
registerCollector("xfs", defaultEnabled, NewXFSCollector)
|
2017-04-21 22:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewXFSCollector returns a new Collector exposing XFS statistics.
|
2019-12-31 16:19:37 +00:00
|
|
|
func NewXFSCollector(logger log.Logger) (Collector, error) {
|
2019-05-07 04:38:21 +00:00
|
|
|
fs, err := xfs.NewFS(*procPath, *sysPath)
|
2017-04-21 22:19:35 +00:00
|
|
|
if err != nil {
|
2019-11-29 13:51:31 +00:00
|
|
|
return nil, fmt.Errorf("failed to open sysfs: %w", err)
|
2017-04-21 22:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &xfsCollector{
|
2019-12-31 16:19:37 +00:00
|
|
|
fs: fs,
|
|
|
|
logger: logger,
|
2017-04-21 22:19:35 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update implements Collector.
|
|
|
|
func (c *xfsCollector) Update(ch chan<- prometheus.Metric) error {
|
2019-05-07 04:38:21 +00:00
|
|
|
stats, err := c.fs.SysStats()
|
2017-04-21 22:19:35 +00:00
|
|
|
if err != nil {
|
2019-11-29 13:51:31 +00:00
|
|
|
return fmt.Errorf("failed to retrieve XFS stats: %w", err)
|
2017-04-21 22:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
|
|
|
},
|
2017-07-07 05:27:52 +00:00
|
|
|
{
|
|
|
|
name: "block_mapping_reads_total",
|
|
|
|
desc: "Number of block map for read operations for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.Reads),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_writes_total",
|
|
|
|
desc: "Number of block map for write operations for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.Writes),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_unmaps_total",
|
|
|
|
desc: "Number of block unmaps (deletes) for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.Unmaps),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_extent_list_insertions_total",
|
|
|
|
desc: "Number of extent list insertions for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.ExtentListInsertions),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_extent_list_deletions_total",
|
|
|
|
desc: "Number of extent list deletions for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.ExtentListDeletions),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_extent_list_lookups_total",
|
|
|
|
desc: "Number of extent list lookups for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.ExtentListLookups),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "block_mapping_extent_list_compares_total",
|
|
|
|
desc: "Number of extent list compares for a filesystem.",
|
|
|
|
value: float64(s.BlockMapping.ExtentListCompares),
|
|
|
|
},
|
|
|
|
{
|
2017-10-20 22:41:51 +00:00
|
|
|
name: "block_map_btree_lookups_total",
|
2017-07-07 05:27:52 +00:00
|
|
|
desc: "Number of block map B-tree lookups for a filesystem.",
|
2017-10-20 22:41:51 +00:00
|
|
|
value: float64(s.BlockMapBTree.Lookups),
|
2017-07-07 05:27:52 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-20 22:41:51 +00:00
|
|
|
name: "block_map_btree_compares_total",
|
2017-07-07 05:27:52 +00:00
|
|
|
desc: "Number of block map B-tree compares for a filesystem.",
|
2017-10-20 22:41:51 +00:00
|
|
|
value: float64(s.BlockMapBTree.Compares),
|
2017-07-07 05:27:52 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-20 22:41:51 +00:00
|
|
|
name: "block_map_btree_records_inserted_total",
|
2017-07-07 05:27:52 +00:00
|
|
|
desc: "Number of block map B-tree records inserted for a filesystem.",
|
2017-10-20 22:41:51 +00:00
|
|
|
value: float64(s.BlockMapBTree.RecordsInserted),
|
2017-07-07 05:27:52 +00:00
|
|
|
},
|
|
|
|
{
|
2017-10-20 22:41:51 +00:00
|
|
|
name: "block_map_btree_records_deleted_total",
|
2017-07-07 05:27:52 +00:00
|
|
|
desc: "Number of block map B-tree records deleted for a filesystem.",
|
2017-10-20 22:41:51 +00:00
|
|
|
value: float64(s.BlockMapBTree.RecordsDeleted),
|
2017-07-07 05:27:52 +00:00
|
|
|
},
|
2019-07-15 14:28:09 +00:00
|
|
|
{
|
|
|
|
name: "directory_operation_lookup_total",
|
|
|
|
desc: "Number of file name directory lookups which miss the operating systems directory name lookup cache.",
|
|
|
|
value: float64(s.DirectoryOperation.Lookups),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "directory_operation_create_total",
|
|
|
|
desc: "Number of times a new directory entry was created for a filesystem.",
|
|
|
|
value: float64(s.DirectoryOperation.Creates),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "directory_operation_remove_total",
|
|
|
|
desc: "Number of times an existing directory entry was created for a filesystem.",
|
|
|
|
value: float64(s.DirectoryOperation.Removes),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "directory_operation_getdents_total",
|
|
|
|
desc: "Number of times the directory getdents operation was performed for a filesystem.",
|
|
|
|
value: float64(s.DirectoryOperation.Getdents),
|
|
|
|
},
|
2020-10-22 16:14:33 +00:00
|
|
|
{
|
|
|
|
name: "inode_operation_attempts_total",
|
|
|
|
desc: "Number of times the OS looked for an XFS inode in the inode cache.",
|
|
|
|
value: float64(s.InodeOperation.Attempts),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_found_total",
|
|
|
|
desc: "Number of times the OS looked for and found an XFS inode in the inode cache.",
|
|
|
|
value: float64(s.InodeOperation.Found),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_recycled_total",
|
|
|
|
desc: "Number of times the OS found an XFS inode in the cache, but could not use it as it was being recycled.",
|
|
|
|
value: float64(s.InodeOperation.Recycle),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_missed_total",
|
|
|
|
desc: "Number of times the OS looked for an XFS inode in the cache, but did not find it.",
|
|
|
|
value: float64(s.InodeOperation.Missed),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_duplicates_total",
|
|
|
|
desc: "Number of times the OS tried to add a missing XFS inode to the inode cache, but found it had already been added by another process.",
|
|
|
|
value: float64(s.InodeOperation.Duplicate),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_reclaims_total",
|
|
|
|
desc: "Number of times the OS reclaimed an XFS inode from the inode cache to free memory for another purpose.",
|
|
|
|
value: float64(s.InodeOperation.Reclaims),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "inode_operation_attribute_changes_total",
|
|
|
|
desc: "Number of times the OS explicitly changed the attributes of an XFS inode.",
|
|
|
|
value: float64(s.InodeOperation.AttributeChange),
|
|
|
|
},
|
2019-07-15 14:28:09 +00:00
|
|
|
{
|
|
|
|
name: "read_calls_total",
|
|
|
|
desc: "Number of read(2) system calls made to files in a filesystem.",
|
|
|
|
value: float64(s.ReadWrite.Read),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "write_calls_total",
|
|
|
|
desc: "Number of write(2) system calls made to files in a filesystem.",
|
|
|
|
value: float64(s.ReadWrite.Write),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_active_total",
|
|
|
|
desc: "Number of vnodes not on free lists for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Active),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_allocate_total",
|
|
|
|
desc: "Number of times vn_alloc called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Allocate),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_get_total",
|
|
|
|
desc: "Number of times vn_get called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Get),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_hold_total",
|
|
|
|
desc: "Number of times vn_hold called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Hold),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_release_total",
|
|
|
|
desc: "Number of times vn_rele called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Release),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_reclaim_total",
|
|
|
|
desc: "Number of times vn_reclaim called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Reclaim),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "vnode_remove_total",
|
|
|
|
desc: "Number of times vn_remove called for a filesystem.",
|
|
|
|
value: float64(s.Vnode.Remove),
|
|
|
|
},
|
2017-04-21 22:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range metrics {
|
|
|
|
desc := prometheus.NewDesc(
|
2017-09-28 13:06:26 +00:00
|
|
|
prometheus.BuildFQName(namespace, subsystem, m.name),
|
2017-04-21 22:19:35 +00:00
|
|
|
m.desc,
|
|
|
|
labels,
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
desc,
|
|
|
|
prometheus.CounterValue,
|
|
|
|
m.value,
|
|
|
|
s.Name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|