Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into softirq_collector
Browse files Browse the repository at this point in the history
Signed-off-by: abbeywoodyear <abbey.woodyear@thehutgroup.com>
  • Loading branch information
abbeywoodyear committed May 25, 2023
2 parents 93f8972 + df1b53b commit 65e9c3a
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 218 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Name | Description | OS
---------|-------------|----
ntp | Exposes local NTP daemon health to check [time](./docs/TIME.md) | _any_
runit | Exposes service status from [runit](http://smarden.org/runit/). | _any_
supervisord | Exposes service status from [supervisord](http://supervisord.org/). | _any_

### Perf Collector

Expand Down
21 changes: 13 additions & 8 deletions collector/bcache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,19 @@ func bcachePeriodStatsToMetric(ps *bcache.PeriodStats, labelValue string) []bcac
extraLabel: label,
extraLabelValue: labelValue,
},
{
name: "cache_readaheads_total",
desc: "Count of times readahead occurred.",
value: float64(ps.CacheReadaheads),
metricType: prometheus.CounterValue,
extraLabel: label,
extraLabelValue: labelValue,
},
}
if ps.CacheReadaheads != 0 {
bcacheReadaheadMetrics := []bcacheMetric{
{
name: "cache_readaheads_total",
desc: "Count of times readahead occurred.",
value: float64(ps.CacheReadaheads),
metricType: prometheus.CounterValue,
extraLabel: label,
extraLabelValue: labelValue,
},
}
metrics = append(metrics, bcacheReadaheadMetrics...)
}
return metrics
}
Expand Down
6 changes: 3 additions & 3 deletions collector/device_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func newDeviceFilter(ignoredPattern, acceptPattern string) (f deviceFilter) {
return
}

// ignores returns whether the device should be ignored
// ignored returns whether the device should be ignored
func (f *deviceFilter) ignored(name string) bool {
return ((f.ignorePattern != nil && f.ignorePattern.MatchString(name)) ||
(f.acceptPattern != nil && !f.acceptPattern.MatchString(name)))
return (f.ignorePattern != nil && f.ignorePattern.MatchString(name)) ||
(f.acceptPattern != nil && !f.acceptPattern.MatchString(name))
}
11 changes: 10 additions & 1 deletion collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
udevIDRevision = "ID_REVISION"
udevIDSerialShort = "ID_SERIAL_SHORT"
udevIDWWN = "ID_WWN"
udevSCSIIdentSerial = "SCSI_IDENT_SERIAL"
)

type typedFactorDesc struct {
Expand Down Expand Up @@ -286,13 +287,21 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
level.Debug(c.logger).Log("msg", "Failed to parse udev info", "err", err)
}

// This is usually the serial printed on the disk label.
serial := info[udevSCSIIdentSerial]

// If it's undefined, fallback to ID_SERIAL_SHORT instead.
if serial == "" {
serial = info[udevIDSerialShort]
}

ch <- c.infoDesc.mustNewConstMetric(1.0, dev,
fmt.Sprint(stats.MajorNumber),
fmt.Sprint(stats.MinorNumber),
info[udevIDPath],
info[udevIDWWN],
info[udevIDModel],
info[udevIDSerialShort],
serial,
info[udevIDRevision],
)

Expand Down
154 changes: 89 additions & 65 deletions collector/fixtures/e2e-64k-page-output.txt

Large diffs are not rendered by default.

154 changes: 89 additions & 65 deletions collector/fixtures/e2e-output.txt

Large diffs are not rendered by default.

30 changes: 20 additions & 10 deletions collector/fixtures/sys.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Mode: 400
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/class/dmi/id/product_version
Lines: 1
�[�
�[�
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/class/dmi/id/sys_vendor
Expand Down Expand Up @@ -1440,7 +1440,7 @@ Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/class/power_supply/BAT0/model_name
Lines: 1
LNV-45N1��
LNV-45N1��
Mode: 444
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/class/power_supply/BAT0/power
Expand Down Expand Up @@ -2396,7 +2396,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_day/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_five_minute
Expand Down Expand Up @@ -2439,7 +2439,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_five_minute/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_hour
Expand Down Expand Up @@ -2482,7 +2482,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_hour/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_total
Expand Down Expand Up @@ -2525,7 +2525,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/stats_total/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/writeback_rate_debug
Expand Down Expand Up @@ -3545,6 +3545,16 @@ Lines: 1
1,3-5,9
Mode: 664
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/system/cpu/offline
Lines: 1

Mode: 664
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/devices/system/cpu/online
Lines: 1
0-3
Mode: 664
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/devices/system/edac
Mode: 755
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -3900,7 +3910,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_day/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_five_minute
Expand Down Expand Up @@ -3943,7 +3953,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_five_minute/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_hour
Expand Down Expand Up @@ -3986,7 +3996,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_hour/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Directory: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_total
Expand Down Expand Up @@ -4029,7 +4039,7 @@ Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/stats_total/cache_readaheads
Lines: 1
0
13
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: sys/fs/bcache/deaddd54-c735-46d5-868e-f331c5fd7c74/tree_depth
Expand Down
64 changes: 57 additions & 7 deletions collector/softnet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ import (
)

type softnetCollector struct {
fs procfs.FS
processed *prometheus.Desc
dropped *prometheus.Desc
timeSqueezed *prometheus.Desc
logger log.Logger
fs procfs.FS
processed *prometheus.Desc
dropped *prometheus.Desc
timeSqueezed *prometheus.Desc
cpuCollision *prometheus.Desc
receivedRps *prometheus.Desc
flowLimitCount *prometheus.Desc
softnetBacklogLen *prometheus.Desc
logger log.Logger
}

const (
Expand Down Expand Up @@ -65,19 +69,41 @@ func NewSoftnetCollector(logger log.Logger) (Collector, error) {
"Number of times processing packets ran out of quota",
[]string{"cpu"}, nil,
),
cpuCollision: prometheus.NewDesc(
prometheus.BuildFQName(namespace, softnetSubsystem, "cpu_collision_total"),
"Number of collision occur while obtaining device lock while transmitting",
[]string{"cpu"}, nil,
),
receivedRps: prometheus.NewDesc(
prometheus.BuildFQName(namespace, softnetSubsystem, "received_rps_total"),
"Number of times cpu woken up received_rps",
[]string{"cpu"}, nil,
),
flowLimitCount: prometheus.NewDesc(
prometheus.BuildFQName(namespace, softnetSubsystem, "flow_limit_count_total"),
"Number of times flow limit has been reached",
[]string{"cpu"}, nil,
),
softnetBacklogLen: prometheus.NewDesc(
prometheus.BuildFQName(namespace, softnetSubsystem, "backlog_len"),
"Softnet backlog status",
[]string{"cpu"}, nil,
),
logger: logger,
}, nil
}

// Update gets parsed softnet statistics using procfs.
func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error {
var cpu string

stats, err := c.fs.NetSoftnetStat()
if err != nil {
return fmt.Errorf("could not get softnet statistics: %w", err)
}

for cpuNumber, cpuStats := range stats {
cpu := strconv.Itoa(cpuNumber)
for _, cpuStats := range stats {
cpu = strconv.FormatUint(uint64(cpuStats.Index), 10)

ch <- prometheus.MustNewConstMetric(
c.processed,
Expand All @@ -97,6 +123,30 @@ func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error {
float64(cpuStats.TimeSqueezed),
cpu,
)
ch <- prometheus.MustNewConstMetric(
c.cpuCollision,
prometheus.CounterValue,
float64(cpuStats.CPUCollision),
cpu,
)
ch <- prometheus.MustNewConstMetric(
c.receivedRps,
prometheus.CounterValue,
float64(cpuStats.ReceivedRps),
cpu,
)
ch <- prometheus.MustNewConstMetric(
c.flowLimitCount,
prometheus.CounterValue,
float64(cpuStats.FlowLimitCount),
cpu,
)
ch <- prometheus.MustNewConstMetric(
c.softnetBacklogLen,
prometheus.GaugeValue,
float64(cpuStats.SoftnetBacklogLen),
cpu,
)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions collector/supervisord.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func NewSupervisordCollector(logger log.Logger) (Collector, error) {
xrpc = xmlrpc.NewClient(*supervisordURL)
}

level.Warn(logger).Log("msg", "This collector is deprecated and will be removed in the next major version release.")

return &supervisordCollector{
upDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "up"),
Expand Down
2 changes: 1 addition & 1 deletion collector/zfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewZFSCollector(logger log.Logger) (Collector, error) {
linuxPathMap: map[string]string{
"zfs_abd": "abdstats",
"zfs_arc": "arcstats",
"zfs_dbuf": "dbuf_stats",
"zfs_dbuf": "dbufstats",
"zfs_dmu_tx": "dmu_tx",
"zfs_dnode": "dnodestats",
"zfs_fm": "fm",
Expand Down
4 changes: 2 additions & 2 deletions collector/zfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
// kstatDataChar = "0"
// kstatDataInt32 = "1"
// kstatDataUint32 = "2"
// kstatDataInt64 = "3"
kstatDataInt64 = "3"
kstatDataUint64 = "4"
// kstatDataLong = "5"
// kstatDataUlong = "6"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler

// kstat data type (column 2) should be KSTAT_DATA_UINT64, otherwise ignore
// TODO: when other KSTAT_DATA_* types arrive, much of this will need to be restructured
if parts[1] == kstatDataUint64 {
if parts[1] == kstatDataUint64 || parts[1] == kstatDataInt64 {
key := fmt.Sprintf("kstat.zfs.misc.%s.%s", fmtExt, parts[0])
value, err := strconv.ParseUint(parts[2], 10, 64)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion collector/zfs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func TestAbdstatsParsing(t *testing.T) {
}

func TestDbufstatsParsing(t *testing.T) {
dbufstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/dbuf_stats")
dbufstatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/dbufstats")
if err != nil {
t.Fatal(err)
}
Expand Down
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/beevik/ntp v0.3.0
github.com/coreos/go-systemd/v22 v22.5.0
github.com/dennwc/btrfs v0.0.0-20230312211831-a1f570bd01a1
github.com/ema/qdisc v0.0.0-20200603082823-62d0308e3e00
github.com/ema/qdisc v0.0.0-20230120214811-5b708f463de3
github.com/go-kit/log v0.2.1
github.com/godbus/dbus/v5 v5.1.0
github.com/hashicorp/go-envparse v0.1.0
Expand All @@ -21,15 +21,15 @@ require (
github.com/mdlayher/netlink v1.7.2
github.com/mdlayher/wifi v0.0.0-20220330172155-a44c70b6d3c8
github.com/opencontainers/selinux v1.11.0
github.com/prometheus-community/go-runit v0.0.0-20150630195641-06ad41a06c4a
github.com/prometheus/client_golang v1.15.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.42.0
github.com/prometheus/exporter-toolkit v0.9.1
github.com/prometheus/procfs v0.9.0
github.com/prometheus-community/go-runit v0.1.0
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.44.0
github.com/prometheus/exporter-toolkit v0.10.0
github.com/prometheus/procfs v0.10.0
github.com/safchain/ethtool v0.3.0
golang.org/x/exp v0.0.0-20230213192124-5e25df0256eb
golang.org/x/sys v0.7.0
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
golang.org/x/sys v0.8.0
howett.net/plist v1.0.0
)

Expand All @@ -48,15 +48,14 @@ require (
github.com/mdlayher/genetlink v1.2.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
Expand Down
Loading

0 comments on commit 65e9c3a

Please sign in to comment.