Browse Source

Fix all open go lint and vet issues

pull/479/head
Tobias Schmidt 8 years ago
parent
commit
c703435790
  1. 6
      collector/collector.go
  2. 3
      collector/conntrack_linux.go
  3. 3
      collector/diskstats_linux.go
  4. 3
      collector/edac_linux.go
  5. 9
      collector/entropy_linux.go
  6. 3
      collector/filesystem_common.go
  7. 8
      collector/filesystem_freebsd.go
  8. 6
      collector/filesystem_linux.go
  9. 8
      collector/ganglia/format.go
  10. 2
      collector/gmond.go
  11. 8
      collector/hwmon_linux.go
  12. 1
      collector/infiniband_linux.go
  13. 4
      collector/infiniband_linux_test.go
  14. 3
      collector/interrupts_common.go
  15. 5
      collector/ksmd_linux.go
  16. 2
      collector/loadavg.go
  17. 15
      collector/logind_linux.go
  18. 16
      collector/logind_linux_test.go
  19. 12
      collector/mdadm_linux.go
  20. 4
      collector/megacli.go
  21. 3
      collector/meminfo_numa_linux.go
  22. 3
      collector/mountstats_linux.go
  23. 13
      collector/nfs_linux.go
  24. 4
      collector/ntp.go
  25. 1
      collector/runit.go
  26. 3
      collector/stat_linux.go
  27. 1
      collector/supervisord.go
  28. 3
      collector/systemd_linux.go
  29. 69
      collector/tcpstat_linux.go
  30. 4
      collector/tcpstat_linux_test.go
  31. 6
      collector/textfile.go
  32. 4
      collector/time.go
  33. 3
      collector/vmstat_linux.go
  34. 1
      collector/wifi_linux.go
  35. 20
      collector/zfs.go
  36. 4
      collector/zfs_linux.go
  37. 2
      node_exporter.go

6
collector/collector.go

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Exporter is a prometheus exporter using multiple Factories to collect and export system metrics.
// Package collector includes all individual collectors to gather and export system metrics.
package collector
import (
@ -19,15 +19,17 @@ import (
"github.com/prometheus/common/log"
)
// Namespace defines the common namespace to be used by all metrics.
const Namespace = "node"
// Factories contains the list of all available collectors.
var Factories = make(map[string]func() (Collector, error))
func warnDeprecated(collector string) {
log.Warnf("The %s collector is deprecated and will be removed in the future!", collector)
}
// Interface a collector has to implement.
// Collector is the interface a collector has to implement.
type Collector interface {
// Get new metrics and expose them via prometheus registry.
Update(ch chan<- prometheus.Metric) (err error)

3
collector/conntrack_linux.go

@ -28,8 +28,7 @@ func init() {
Factories["conntrack"] = NewConntrackCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// conntrack stats
// NewConntrackCollector returns a new Collector exposing conntrack stats.
func NewConntrackCollector() (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(

3
collector/diskstats_linux.go

@ -47,8 +47,7 @@ func init() {
Factories["diskstats"] = NewDiskstatsCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// disk device stats.
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector() (Collector, error) {
var diskLabelNames = []string{"device"}

3
collector/edac_linux.go

@ -52,8 +52,7 @@ func init() {
Factories["edac"] = NewEdacCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// edac stats.
// NewEdacCollector returns a new Collector exposing edac stats.
func NewEdacCollector() (Collector, error) {
return &edacCollector{
ceCount: prometheus.NewDesc(

9
collector/entropy_linux.go

@ -22,18 +22,17 @@ import (
)
type entropyCollector struct {
entropy_avail *prometheus.Desc
entropyAvail *prometheus.Desc
}
func init() {
Factories["entropy"] = NewEntropyCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// entropy stats
// NewEntropyCollector returns a new Collector exposing entropy stats.
func NewEntropyCollector() (Collector, error) {
return &entropyCollector{
entropy_avail: prometheus.NewDesc(
entropyAvail: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "entropy_available_bits"),
"Bits of available entropy.",
nil, nil,
@ -47,7 +46,7 @@ func (c *entropyCollector) Update(ch chan<- prometheus.Metric) (err error) {
return fmt.Errorf("couldn't get entropy_avail: %s", err)
}
ch <- prometheus.MustNewConstMetric(
c.entropy_avail, prometheus.GaugeValue, float64(value))
c.entropyAvail, prometheus.GaugeValue, float64(value))
return nil
}

3
collector/filesystem_common.go

@ -64,8 +64,7 @@ func init() {
Factories["filesystem"] = NewFilesystemCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// Filesystems stats.
// NewFilesystemCollector returns a new Collector exposing filesystems stats.
func NewFilesystemCollector() (Collector, error) {
subsystem := "filesystem"
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)

8
collector/filesystem_freebsd.go

@ -26,8 +26,8 @@ import (
const (
defIgnoredMountPoints = "^/(dev)($|/)"
defIgnoredFSTypes = "^devfs$"
MNT_RDONLY = 0x1
MNT_NOWAIT = 0x2
readOnly = 0x1 // MNT_RDONLY
noWait = 0x2 // MNT_NOWAIT
)
func gostring(b []int8) string {
@ -43,7 +43,7 @@ func gostring(b []int8) string {
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
buf := make([]unix.Statfs_t, 16)
for {
n, err := unix.Getfsstat(buf, MNT_NOWAIT)
n, err := unix.Getfsstat(buf, noWait)
if err != nil {
return nil, err
}
@ -69,7 +69,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
}
var ro float64
if (fs.Flags & MNT_RDONLY) != 0 {
if (fs.Flags & readOnly) != 0 {
ro = 1
}

6
collector/filesystem_linux.go

@ -27,10 +27,10 @@ import (
const (
defIgnoredMountPoints = "^/(sys|proc|dev)($|/)"
defIgnoredFSTypes = "^(sys|proc|auto)fs$"
ST_RDONLY = 0x1
readOnly = 0x1 // ST_RDONLY
)
// Expose filesystem fullness.
// GetStats returns filesystem stats.
func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
mps, err := mountPointDetails()
if err != nil {
@ -57,7 +57,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
}
var ro float64
if buf.Flags&ST_RDONLY != 0 {
if (buf.Flags & readOnly) != 0 {
ro = 1
}

8
collector/ganglia/format.go

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Types for unmarshalling gmond's XML output.
// Package ganglia provides types for unmarshalling gmond's XML output.
//
// Not used elements in gmond's XML output are commented.
// In case you want to use them, please change the names so that one
@ -20,15 +20,18 @@ package ganglia
import "encoding/xml"
// ExtraElement describes EXTRA_ELEMENT elements.
type ExtraElement struct {
Name string `xml:"NAME,attr"`
Val string `xml:"VAL,attr"`
}
// ExtraData describes EXTRA_DATA elements.
type ExtraData struct {
ExtraElements []ExtraElement `xml:"EXTRA_ELEMENT"`
}
// Metric describes METRIC elements.
type Metric struct {
Name string `xml:"NAME,attr"`
Value float64 `xml:"VAL,attr"`
@ -42,6 +45,7 @@ type Metric struct {
ExtraData ExtraData `xml:"EXTRA_DATA"`
}
// Host describes HOST elements.
type Host struct {
Name string `xml:"NAME,attr"`
/*
@ -57,6 +61,7 @@ type Host struct {
Metrics []Metric `xml:"METRIC"`
}
// Cluster describes CLUSTER elements.
type Cluster struct {
Name string `xml:"NAME,attr"`
/*
@ -68,6 +73,7 @@ type Cluster struct {
Hosts []Host `xml:"HOST"`
}
// Ganglia describes the top-level XML structure.
type Ganglia struct {
XMLNAME xml.Name `xml:"GANGLIA_XML"`
Clusters []Cluster `xml:"CLUSTER"`

2
collector/gmond.go

@ -46,7 +46,7 @@ func init() {
var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)
// Takes a prometheus registry and returns a new Collector scraping ganglia.
// NewGmondCollector returns a new Collector scraping ganglia.
func NewGmondCollector() (Collector, error) {
warnDeprecated("gmond")
c := gmondCollector{

8
collector/hwmon_linux.go

@ -51,8 +51,8 @@ func init() {
type hwMonCollector struct{}
// Takes a prometheus registry and returns a new Collector exposing
// /sys/class/hwmon stats (similar to lm-sensors).
// NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats
// (similar to lm-sensors).
func NewHwMonCollector() (Collector, error) {
return &hwMonCollector{}, nil
}
@ -78,7 +78,7 @@ func addValueFile(data map[string]map[string]string, sensor string, prop string,
data[sensor][prop] = value
}
// Split a sensor name into <type><num>_<property>
// explodeSensorFilename splits a sensor name into <type><num>_<property>.
func explodeSensorFilename(filename string) (ok bool, sensorType string, sensorNum int, sensorProperty string) {
matches := hwmonFilenameFormat.FindStringSubmatch(filename)
if len(matches) == 0 {
@ -164,7 +164,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) (e
)
}
// format all sensors
// Format all sensors.
for sensor, sensorData := range data {
_, sensorType, _, _ := explodeSensorFilename(sensor)

1
collector/infiniband_linux.go

@ -45,6 +45,7 @@ func init() {
Factories["infiniband"] = NewInfiniBandCollector
}
// NewInfiniBandCollector returns a new Collector exposing InfiniBand stats.
func NewInfiniBandCollector() (Collector, error) {
var i infinibandCollector

4
collector/infiniband_linux_test.go

@ -24,7 +24,7 @@ func TestInfiniBandDevices(t *testing.T) {
}
if l := len(devices); l != 1 {
t.Fatal("Retrieved an unexpected number of InfiniBand devices: %d", l)
t.Fatalf("Retrieved an unexpected number of InfiniBand devices: %d", l)
}
}
@ -35,6 +35,6 @@ func TestInfiniBandPorts(t *testing.T) {
}
if l := len(ports); l != 2 {
t.Fatal("Retrieved an unexpected number of InfiniBand ports: %d", l)
t.Fatalf("Retrieved an unexpected number of InfiniBand ports: %d", l)
}
}

3
collector/interrupts_common.go

@ -26,8 +26,7 @@ func init() {
Factories["interrupts"] = NewInterruptsCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// interrupts stats
// NewInterruptsCollector returns a new Collector exposing interrupts stats.
func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{
desc: typedDesc{prometheus.NewDesc(

5
collector/ksmd_linux.go

@ -46,8 +46,7 @@ func getCanonicalMetricName(filename string) string {
}
}
// Takes a prometheus registry and returns a new Collector exposing
// kernel/system statistics.
// NewKsmdCollector returns a new Collector exposing kernel/system statistics.
func NewKsmdCollector() (Collector, error) {
subsystem := "ksmd"
descs := make(map[string]*prometheus.Desc)
@ -60,7 +59,7 @@ func NewKsmdCollector() (Collector, error) {
return &ksmdCollector{descs}, nil
}
// Expose kernel and system statistics.
// Update implements Collector and exposes kernel and system statistics.
func (c *ksmdCollector) Update(ch chan<- prometheus.Metric) (err error) {
for _, n := range ksmdFiles {
val, err := readUintFromFile(sysFilePath(path.Join("kernel/mm/ksm", n)))

2
collector/loadavg.go

@ -31,7 +31,7 @@ func init() {
Factories["loadavg"] = NewLoadavgCollector
}
// Take a prometheus registry and return a new Collector exposing load average.
// NewLoadavgCollector returns a new Collector exposing load average stats.
func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{
metric: []typedDesc{

15
collector/logind_linux.go

@ -65,15 +65,15 @@ type logindSession struct {
// Struct elements must be public for the reflection magic of godbus to work.
type logindSessionEntry struct {
SessionId string
UserId uint32
SessionID string
UserID uint32
UserName string
SeatId string
SeatID string
SessionObjectPath dbus.ObjectPath
}
type logindSeatEntry struct {
SeatId string
SeatID string
SeatObjectPath dbus.ObjectPath
}
@ -81,8 +81,7 @@ func init() {
Factories["logind"] = NewLogindCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// logind statistics.
// NewLogindCollector returns a new Collector exposing logind statistics.
func NewLogindCollector() (Collector, error) {
return &logindCollector{}, nil
}
@ -197,7 +196,7 @@ func (c *logindDbus) listSeats() ([]string, error) {
ret := make([]string, len(seats)+1)
for i := range seats {
ret[i] = seats[i].SeatId
ret[i] = seats[i].SeatID
}
// Always add the empty seat, which is used for remote sessions like SSH
ret[len(seats)] = ""
@ -260,7 +259,7 @@ func (c *logindDbus) getSession(session logindSessionEntry) *logindSession {
}
return &logindSession{
seat: session.SeatId,
seat: session.SeatID,
remote: remote.String(),
sessionType: knownStringOrOther(sessionTypeStr, attrTypeValues),
class: knownStringOrOther(classStr, attrClassValues),

16
collector/logind_linux_test.go

@ -31,17 +31,17 @@ func (c *testLogindInterface) listSeats() ([]string, error) {
func (c *testLogindInterface) listSessions() ([]logindSessionEntry, error) {
return []logindSessionEntry{
{
SessionId: "1",
UserId: 0,
SessionID: "1",
UserID: 0,
UserName: "",
SeatId: "",
SeatID: "",
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/1"),
},
{
SessionId: "2",
UserId: 0,
SessionID: "2",
UserID: 0,
UserName: "",
SeatId: "seat0",
SeatID: "seat0",
SessionObjectPath: dbus.ObjectPath("/org/freedesktop/login1/session/2"),
},
}, nil
@ -50,13 +50,13 @@ func (c *testLogindInterface) listSessions() ([]logindSessionEntry, error) {
func (c *testLogindInterface) getSession(session logindSessionEntry) *logindSession {
sessions := map[dbus.ObjectPath]*logindSession{
dbus.ObjectPath("/org/freedesktop/login1/session/1"): {
seat: session.SeatId,
seat: session.SeatID,
remote: "true",
sessionType: knownStringOrOther("tty", attrTypeValues),
class: knownStringOrOther("user", attrClassValues),
},
dbus.ObjectPath("/org/freedesktop/login1/session/2"): {
seat: session.SeatId,
seat: session.SeatID,
remote: "false",
sessionType: knownStringOrOther("x11", attrTypeValues),
class: knownStringOrOther("greeter", attrClassValues),

12
collector/mdadm_linux.go

@ -56,10 +56,8 @@ func evalStatusline(statusline string) (active, total, size int64, err error) {
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].
if len(matches) < 3+1 {
return 0, 0, 0, fmt.Errorf("too few matches found in statusline: %s", statusline)
} else {
if len(matches) > 3+1 {
return 0, 0, 0, fmt.Errorf("too many matches found in statusline: %s", statusline)
}
} else if len(matches) > 3+1 {
return 0, 0, 0, fmt.Errorf("too many matches found in statusline: %s", statusline)
}
size, err = strconv.ParseInt(matches[1], 10, 64)
@ -109,7 +107,7 @@ func evalUnknownPersonalitylineRE(statusline string) (size int64, err error) {
return size, nil
}
// Gets the size that has already been synced out of the sync-line.
// evalBuildline gets the size that has already been synced out of the sync-line.
func evalBuildline(buildline string) (int64, error) {
matches := buildlineRE.FindStringSubmatch(buildline)
@ -131,7 +129,7 @@ func evalBuildline(buildline string) (int64, error) {
return syncedSize, nil
}
// Parses an mdstat-file and returns a struct with the relevant infos.
// parseMdstat parses an mdstat-file and returns a struct with the relevant infos.
func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
content, err := ioutil.ReadFile(mdStatusFilePath)
if err != nil {
@ -234,7 +232,7 @@ func parseMdstat(mdStatusFilePath string) ([]mdStatus, error) {
return mdStates, nil
}
// Just returns the pointer to an empty struct as we only use throwaway-metrics.
// NewMdadmCollector returns a new Collector exposing raid statistics.
func NewMdadmCollector() (Collector, error) {
return &mdadmCollector{}, nil
}

4
collector/megacli.go

@ -47,8 +47,8 @@ func init() {
Factories["megacli"] = NewMegaCliCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// RAID status through megacli.
// NewMegaCliCollector returns a new Collector exposing RAID status through
// megacli.
func NewMegaCliCollector() (Collector, error) {
warnDeprecated("megacli")
return &megaCliCollector{

3
collector/meminfo_numa_linux.go

@ -50,8 +50,7 @@ func init() {
Factories["meminfo_numa"] = NewMeminfoNumaCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// memory stats.
// NewMeminfoNumaCollector returns a new Collector exposing memory stats.
func NewMeminfoNumaCollector() (Collector, error) {
return &meminfoNumaCollector{
metricDescs: map[string]*prometheus.Desc{},

3
collector/mountstats_linux.go

@ -93,6 +93,7 @@ func init() {
Factories["mountstats"] = NewMountStatsCollector
}
// NewMountStatsCollector returns a new Collector exposing NFS statistics.
func NewMountStatsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
@ -105,7 +106,7 @@ func NewMountStatsCollector() (Collector, error) {
}
const (
// For the time being, only NFS statistics are available via this mechanism
// For the time being, only NFS statistics are available via this mechanism.
subsystem = "mountstats_nfs"
)

13
collector/nfs_linux.go

@ -78,19 +78,19 @@ var (
nil,
)
nfsRpcOperationsDesc = prometheus.NewDesc(
nfsRPCOperationsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_operations"),
"Number of RPCs performed.",
nil,
nil,
)
nfsRpcRetransmissionsDesc = prometheus.NewDesc(
nfsRPCRetransmissionsDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_retransmissions"),
"Number of RPC transmissions performed.",
nil,
nil,
)
nfsRpcAuthenticationRefreshesDesc = prometheus.NewDesc(
nfsRPCAuthenticationRefreshesDesc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "nfs", "rpc_authentication_refreshes"),
"Number of RPC authentication refreshes performed.",
nil,
@ -111,6 +111,7 @@ func init() {
Factories["nfs"] = NewNfsCollector
}
// NewNfsCollector returns a new Collector exposing NFS statistics.
func NewNfsCollector() (Collector, error) {
return &nfsCollector{}, nil
}
@ -145,17 +146,17 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
} else if fields := rpcLineRE.FindStringSubmatch(line); fields != nil {
value, _ := strconv.ParseFloat(fields[1], 64)
ch <- prometheus.MustNewConstMetric(
nfsRpcOperationsDesc,
nfsRPCOperationsDesc,
prometheus.CounterValue, value)
value, _ = strconv.ParseFloat(fields[2], 64)
ch <- prometheus.MustNewConstMetric(
nfsRpcRetransmissionsDesc,
nfsRPCRetransmissionsDesc,
prometheus.CounterValue, value)
value, _ = strconv.ParseFloat(fields[3], 64)
ch <- prometheus.MustNewConstMetric(
nfsRpcAuthenticationRefreshesDesc,
nfsRPCAuthenticationRefreshesDesc,
prometheus.CounterValue, value)
} else if fields := procLineRE.FindStringSubmatch(line); fields != nil {
version := fields[1]

4
collector/ntp.go

@ -37,8 +37,8 @@ func init() {
Factories["ntp"] = NewNtpCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// the offset between ntp and the current system time.
// NewNtpCollector returns a new Collector exposing the offset between ntp and
// the current system time.
func NewNtpCollector() (Collector, error) {
warnDeprecated("ntp")
if *ntpServer == "" {

1
collector/runit.go

@ -36,6 +36,7 @@ func init() {
Factories["runit"] = NewRunitCollector
}
// NewRunitCollector returns a new Collector exposing runit statistics.
func NewRunitCollector() (Collector, error) {
var (
subsystem = "service"

3
collector/stat_linux.go

@ -42,8 +42,7 @@ func init() {
Factories["stat"] = NewStatCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// kernel/system statistics.
// NewStatCollector returns a new Collector exposing kernel/system statistics.
func NewStatCollector() (Collector, error) {
return &statCollector{
cpu: prometheus.NewDesc(

1
collector/supervisord.go

@ -39,6 +39,7 @@ func init() {
Factories["supervisord"] = NewSupervisordCollector
}
// NewSupervisordCollector returns a new Collector exposing supervisord statistics.
func NewSupervisordCollector() (Collector, error) {
client, err := xmlrpc.NewClient(*supervisordURL, nil)
if err != nil {

3
collector/systemd_linux.go

@ -51,8 +51,7 @@ func init() {
Factories["systemd"] = NewSystemdCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// systemd statistics.
// NewSystemdCollector returns a new Collector exposing systemd statistics.
func NewSystemdCollector() (Collector, error) {
const subsystem = "systemd"

69
collector/tcpstat_linux.go

@ -26,20 +26,31 @@ import (
"github.com/prometheus/client_golang/prometheus"
)
type TCPConnectionState int
type tcpConnectionState int
const (
TCP_ESTABLISHED TCPConnectionState = iota + 1
TCP_SYN_SENT
TCP_SYN_RECV
TCP_FIN_WAIT1
TCP_FIN_WAIT2
TCP_TIME_WAIT
TCP_CLOSE
TCP_CLOSE_WAIT
TCP_LAST_ACK
TCP_LISTEN
TCP_CLOSING
// TCP_ESTABLISHED
tcpEstablished tcpConnectionState = iota + 1
// TCP_SYN_SENT
tcpSynSent
// TCP_SYN_RECV
tcpSynRecv
// TCP_FIN_WAIT1
tcpFinWait1
// TCP_FIN_WAIT2
tcpFinWait2
// TCP_TIME_WAIT
tcpTimeWait
// TCP_CLOSE
tcpClose
// TCP_CLOSE_WAIT
tcpCloseWait
// TCP_LAST_ACK
tcpLastAck
// TCP_LISTEN
tcpListen
// TCP_CLOSING
tcpClosing
)
type tcpStatCollector struct {
@ -84,10 +95,10 @@ func (c *tcpStatCollector) Update(ch chan<- prometheus.Metric) (err error) {
for st, value := range tcpStats {
ch <- c.desc.mustNewConstMetric(value, st.String())
}
return err
return nil
}
func getTCPStats(statsFile string) (map[TCPConnectionState]float64, error) {
func getTCPStats(statsFile string) (map[tcpConnectionState]float64, error) {
file, err := os.Open(statsFile)
if err != nil {
return nil, err
@ -97,9 +108,9 @@ func getTCPStats(statsFile string) (map[TCPConnectionState]float64, error) {
return parseTCPStats(file)
}
func parseTCPStats(r io.Reader) (map[TCPConnectionState]float64, error) {
func parseTCPStats(r io.Reader) (map[tcpConnectionState]float64, error) {
var (
tcpStats = map[TCPConnectionState]float64{}
tcpStats = map[tcpConnectionState]float64{}
scanner = bufio.NewScanner(r)
)
@ -116,35 +127,35 @@ func parseTCPStats(r io.Reader) (map[TCPConnectionState]float64, error) {
return nil, err
}
tcpStats[TCPConnectionState(st)]++
tcpStats[tcpConnectionState(st)]++
}
return tcpStats, nil
}
func (st TCPConnectionState) String() string {
func (st tcpConnectionState) String() string {
switch st {
case TCP_ESTABLISHED:
case tcpEstablished:
return "established"
case TCP_SYN_SENT:
case tcpSynSent:
return "syn_sent"
case TCP_SYN_RECV:
case tcpSynRecv:
return "syn_recv"
case TCP_FIN_WAIT1:
case tcpFinWait1:
return "fin_wait1"
case TCP_FIN_WAIT2:
case tcpFinWait2:
return "fin_wait2"
case TCP_TIME_WAIT:
case tcpTimeWait:
return "time_wait"
case TCP_CLOSE:
case tcpClose:
return "close"
case TCP_CLOSE_WAIT:
case tcpCloseWait:
return "close_wait"
case TCP_LAST_ACK:
case tcpLastAck:
return "last_ack"
case TCP_LISTEN:
case tcpListen:
return "listen"
case TCP_CLOSING:
case tcpClosing:
return "closing"
default:
return "unknown"

4
collector/tcpstat_linux_test.go

@ -30,11 +30,11 @@ func TestTCPStat(t *testing.T) {
t.Fatal(err)
}
if want, got := 1, int(tcpStats[TCP_ESTABLISHED]); want != got {
if want, got := 1, int(tcpStats[tcpEstablished]); want != got {
t.Errorf("want tcpstat number of established state %d, got %d", want, got)
}
if want, got := 1, int(tcpStats[TCP_LISTEN]); want != got {
if want, got := 1, int(tcpStats[tcpListen]); want != got {
t.Errorf("want tcpstat number of listen state %d, got %d", want, got)
}
}

6
collector/textfile.go

@ -44,8 +44,8 @@ func init() {
Factories["textfile"] = NewTextFileCollector
}
// Takes a registers a
// SetMetricFamilyInjectionHook.
// NewTextFileCollector returns a new Collector exposing metrics read from files
// in the given textfile directory.
func NewTextFileCollector() (Collector, error) {
c := &textFileCollector{
path: *textFileDirectory,
@ -65,7 +65,7 @@ func NewTextFileCollector() (Collector, error) {
return c, nil
}
// textFile collector works via SetMetricFamilyInjectionHook in parseTextFiles.
// Update implements the Collector interface.
func (c *textFileCollector) Update(ch chan<- prometheus.Metric) (err error) {
return nil
}

4
collector/time.go

@ -30,8 +30,8 @@ func init() {
Factories["time"] = NewTimeCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// the current system time in seconds since epoch.
// NewTimeCollector returns a new Collector exposing the current system time in
// seconds since epoch.
func NewTimeCollector() (Collector, error) {
return &timeCollector{
desc: prometheus.NewDesc(

3
collector/vmstat_linux.go

@ -35,8 +35,7 @@ func init() {
Factories["vmstat"] = NewvmStatCollector
}
// Takes a prometheus registry and returns a new Collector exposing
// vmstat stats.
// NewvmStatCollector returns a new Collector exposing vmstat stats.
func NewvmStatCollector() (Collector, error) {
return &vmStatCollector{}, nil
}

1
collector/wifi_linux.go

@ -56,6 +56,7 @@ type wifiStater interface {
StationInfo(ifi *wifi.Interface) (*wifi.StationInfo, error)
}
// NewWifiCollector returns a new Collector exposing Wifi statistics.
func NewWifiCollector() (Collector, error) {
const (
subsystem = "wifi"

20
collector/zfs.go

@ -24,20 +24,16 @@ import (
"github.com/prometheus/common/log"
)
var zfsNotAvailableError = errors.New("ZFS / ZFS statistics are not available")
var errZFSNotAvailable = errors.New("ZFS / ZFS statistics are not available")
type zfsSysctl string
// Metrics
type zfsMetric struct {
subsystem string // 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
}
@ -49,6 +45,7 @@ type zfsCollector struct {
linuxPathMap map[string]string
}
// NewZFSCollector returns a new Collector exposing ZFS statistics.
func NewZFSCollector() (Collector, error) {
var z zfsCollector
z.linuxProcpathBase = "spl/kstat/zfs"
@ -65,14 +62,13 @@ func NewZFSCollector() (Collector, error) {
return &z, nil
}
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) {
func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
for subsystem := range c.linuxPathMap {
err = c.updateZfsStats(subsystem, ch)
switch {
case err == zfsNotAvailableError:
log.Debug(err)
return nil
case err != nil:
if err := c.updateZfsStats(subsystem, ch); err != nil {
if err == errZFSNotAvailable {
log.Debug(err)
return nil
}
return err
}
}

4
collector/zfs_linux.go

@ -30,7 +30,7 @@ func (c *zfsCollector) openProcFile(path string) (file *os.File, err error) {
file, err = os.Open(procFilePath(path))
if err != nil {
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", procFilePath(path))
err = zfsNotAvailableError
err = errZFSNotAvailable
}
return
}
@ -61,7 +61,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) (err error)
file, err := os.Open(zpoolPath)
if err != nil {
log.Debugf("Cannot open %q for reading. Is the kernel module loaded?", zpoolPath)
return zfsNotAvailableError
return errZFSNotAvailable
}
err = c.parsePoolProcfsFile(file, zpoolPath, func(poolName string, s zfsSysctl, v int) {

2
node_exporter.go

@ -72,7 +72,7 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
}
func filterAvailableCollectors(collectors string) string {
availableCollectors := make([]string, 0)
var availableCollectors []string
for _, c := range strings.Split(collectors, ",") {
_, ok := collector.Factories[c]
if ok {

Loading…
Cancel
Save