2016-12-06 20:22:26 +01:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
2016-12-08 16:06:53 +01:00
|
|
|
// +build linux
|
2016-02-25 13:55:02 +01:00
|
|
|
// +build !nozfs
|
|
|
|
|
2016-12-08 16:06:53 +01:00
|
|
|
package collector
|
|
|
|
|
2016-02-25 13:55:02 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/common/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type zfsMetricValue int
|
|
|
|
|
|
|
|
const zfsErrorValue = zfsMetricValue(-1)
|
|
|
|
|
|
|
|
var zfsNotAvailableError = errors.New("ZFS / ZFS statistics are not available")
|
|
|
|
|
|
|
|
type zfsSysctl string
|
|
|
|
type zfsSubsystemName string
|
|
|
|
|
|
|
|
const (
|
|
|
|
arc = zfsSubsystemName("zfsArc")
|
2017-01-23 19:45:36 +01:00
|
|
|
fm = zfsSubsystemName("zfsFm")
|
2017-01-23 19:19:51 +01:00
|
|
|
vdevCache = zfsSubsystemName("zfsVdevCache")
|
2017-01-23 19:33:35 +01:00
|
|
|
xuio = zfsSubsystemName("zfsXuio")
|
2017-01-23 17:39:32 +01:00
|
|
|
zfetch = zfsSubsystemName("zfsFetch")
|
2017-01-23 18:56:39 +01:00
|
|
|
zil = zfsSubsystemName("zfsZil")
|
2016-02-25 13:55:02 +01:00
|
|
|
zpoolSubsystem = zfsSubsystemName("zfsPool")
|
|
|
|
)
|
|
|
|
|
|
|
|
// Metrics
|
|
|
|
|
|
|
|
type zfsMetric struct {
|
|
|
|
subsystem zfsSubsystemName // The Prometheus subsystem name.
|
|
|
|
name string // The Prometheus name of the metric.
|
|
|
|
sysctl zfsSysctl // The sysctl of the ZFS metric.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collector
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Factories["zfs"] = NewZFSCollector
|
|
|
|
}
|
|
|
|
|
|
|
|
type zfsCollector struct {
|
|
|
|
zfsMetrics []zfsMetric
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewZFSCollector() (Collector, error) {
|
|
|
|
return &zfsCollector{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
2016-12-06 20:22:26 +01:00
|
|
|
// Arcstats
|
|
|
|
err = c.updateArcstats(ch)
|
2016-02-25 13:55:02 +01:00
|
|
|
switch {
|
|
|
|
case err == zfsNotAvailableError:
|
|
|
|
log.Debug(err)
|
|
|
|
return nil
|
|
|
|
case err != nil:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-23 17:39:32 +01:00
|
|
|
// Zfetchstats
|
|
|
|
err = c.updateZfetchstats(ch)
|
|
|
|
if err != nil { return err }
|
|
|
|
|
2017-01-23 18:56:39 +01:00
|
|
|
// Zil
|
|
|
|
err = c.updateZil(ch)
|
|
|
|
if err != nil { return err }
|
|
|
|
|
2017-01-23 19:19:51 +01:00
|
|
|
// VdevCacheStats
|
|
|
|
err = c.updateVdevCacheStats(ch)
|
|
|
|
if err != nil { return err }
|
|
|
|
|
2017-01-23 19:33:35 +01:00
|
|
|
// XuioStats
|
|
|
|
err = c.updateXuioStats(ch)
|
|
|
|
if err != nil { return err }
|
|
|
|
|
2017-01-23 19:45:36 +01:00
|
|
|
// Fm
|
|
|
|
err = c.updateFm(ch)
|
|
|
|
if err != nil { return err }
|
|
|
|
|
2016-02-25 13:55:02 +01:00
|
|
|
// Pool stats
|
|
|
|
return c.updatePoolStats(ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s zfsSysctl) metricName() string {
|
|
|
|
parts := strings.Split(string(s), ".")
|
|
|
|
return parts[len(parts)-1]
|
|
|
|
}
|
|
|
|
|
2016-12-06 20:22:26 +01:00
|
|
|
func (c *zfsCollector) constSysctlMetric(subsystem zfsSubsystemName, sysctl zfsSysctl, value zfsMetricValue) prometheus.Metric {
|
2016-02-25 13:55:02 +01:00
|
|
|
metricName := sysctl.metricName()
|
|
|
|
|
|
|
|
return prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName(Namespace, string(subsystem), metricName),
|
|
|
|
string(sysctl),
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
prometheus.UntypedValue,
|
|
|
|
float64(value),
|
|
|
|
)
|
|
|
|
}
|