Skip to content

Commit

Permalink
Merge pull request #75 from prometheus/remove-attribute-module
Browse files Browse the repository at this point in the history
Use flags instead of config and remove attributes
  • Loading branch information
juliusv committed May 21, 2015
2 parents 00ddf58 + 665b05e commit b539481
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 162 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Which collectors are used is controlled by the `--collectors.enabled` flag.

Name | Description
---------|------------
attributes | Exposes attributes from the configuration file. Deprecated, use textfile module instead.
diskstats | Exposes disk I/O statistics from `/proc/diskstats`.
filesystem | Exposes filesystem statistics, such as disk space used.
loadavg | Exposes load average.
Expand Down
46 changes: 0 additions & 46 deletions collector/attributes.go

This file was deleted.

2 changes: 1 addition & 1 deletion collector/bonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {

// NewBondingCollector returns a newly allocated bondingCollector.
// It exposes the number of configured and active slave of linux bonding interfaces.
func NewBondingCollector(config Config) (Collector, error) {
func NewBondingCollector() (Collector, error) {
return &bondingCollector{
slaves: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down
7 changes: 1 addition & 6 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const Namespace = "node"

var Factories = make(map[string]func(Config) (Collector, error))
var Factories = make(map[string]func() (Collector, error))

// Interface a collector has to implement.
type Collector interface {
Expand All @@ -20,8 +20,3 @@ type Collector interface {
// scraped. (However, for metric gathering that takes very long, it might
// actually be better to do them proactively before scraping to minimize scrape
// time.)

type Config struct {
Config map[string]string `json:"config"`
Attributes map[string]string `json:"attributes"`
}
7 changes: 3 additions & 4 deletions collector/diskstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
)

type diskstatsCollector struct {
config Config

ignoredDevicesPattern *regexp.Regexp
metrics []prometheus.Collector
}
Expand All @@ -35,13 +35,12 @@ func init() {
Factories["diskstats"] = NewDiskstatsCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// disk device stats.
func NewDiskstatsCollector(config Config) (Collector, error) {
func NewDiskstatsCollector() (Collector, error) {
var diskLabelNames = []string{"device"}

return &diskstatsCollector{
config: config,
ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices),
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt
metrics: []prometheus.Collector{
Expand Down
8 changes: 4 additions & 4 deletions collector/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
)

type filesystemCollector struct {
config Config

ignoredMountPointsPattern *regexp.Regexp

size, free, avail, files, filesFree *prometheus.GaugeVec
Expand All @@ -35,13 +35,13 @@ func init() {
Factories["filesystem"] = NewFilesystemCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// network device filesystems.
func NewFilesystemCollector(config Config) (Collector, error) {
func NewFilesystemCollector() (Collector, error) {
var filesystemLabelNames = []string{"filesystem"}

return &filesystemCollector{
config: config,

ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
size: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down
7 changes: 3 additions & 4 deletions collector/gmond.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (

type gmondCollector struct {
metrics map[string]*prometheus.GaugeVec
config Config

}

func init() {
Expand All @@ -34,10 +34,9 @@ func init() {

var illegalCharsRE = regexp.MustCompile(`[^a-zA-Z0-9_]`)

// Takes a config struct and prometheus registry and returns a new Collector scraping ganglia.
func NewGmondCollector(config Config) (Collector, error) {
// Takes a prometheus registry and returns a new Collector scraping ganglia.
func NewGmondCollector() (Collector, error) {
c := gmondCollector{
config: config,
metrics: map[string]*prometheus.GaugeVec{},
}

Expand Down
8 changes: 4 additions & 4 deletions collector/interrupts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ const (
)

type interruptsCollector struct {
config Config

metric *prometheus.CounterVec
}

func init() {
Factories["interrupts"] = NewInterruptsCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// interrupts stats
func NewInterruptsCollector(config Config) (Collector, error) {
func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{
config: config,

metric: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Expand Down
24 changes: 10 additions & 14 deletions collector/ipvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
package collector

import (
"flag"
"fmt"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/procfs"
)

var (
ipvsProcfsMountPoint = flag.String("collector.ipvs.procfs", procfs.DefaultMountPoint, "procfs mountpoint.")
)

type ipvsCollector struct {
Collector
fs procfs.FS
Expand All @@ -23,11 +28,11 @@ func init() {

// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
// "procfs" config parameter to override the default proc location (/proc).
func NewIPVSCollector(config Config) (Collector, error) {
return newIPVSCollector(config)
func NewIPVSCollector() (Collector, error) {
return newIPVSCollector()
}

func newIPVSCollector(config Config) (*ipvsCollector, error) {
func newIPVSCollector() (*ipvsCollector, error) {
var (
ipvsBackendLabelNames = []string{
"local_address",
Expand All @@ -37,23 +42,14 @@ func newIPVSCollector(config Config) (*ipvsCollector, error) {
"proto",
}
c ipvsCollector
subsystem string
err error
subsystem = "ipvs"
)

if p, ok := config.Config["procfs"]; !ok {
c.fs, err = procfs.NewFS(procfs.DefaultMountPoint)
} else {
c.fs, err = procfs.NewFS(p)
}
c.fs, err = procfs.NewFS(*ipvsProcfsMountPoint)
if err != nil {
return nil, err
}
if s, ok := config.Config["ipvs_subsystem"]; ok {
subsystem = s
} else {
subsystem = "ipvs"
}

c.connections = prometheus.NewCounter(
prometheus.CounterOpts{
Expand Down
12 changes: 10 additions & 2 deletions collector/ipvs_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package collector

import (
"flag"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -106,7 +107,10 @@ var (
)

func TestIPVSCollector(t *testing.T) {
collector, err := newIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}})
if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil {
t.Fatal(err)
}
collector, err := newIPVSCollector()
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -165,7 +169,10 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
}

func TestIPVSCollectorResponse(t *testing.T) {
collector, err := NewIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}})
if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil {
t.Fatal(err)
}
collector, err := NewIPVSCollector()
if err != nil {
t.Fatal(err)
}
Expand All @@ -183,6 +190,7 @@ func TestIPVSCollectorResponse(t *testing.T) {
wantLines := strings.Split(string(wantMetrics), "\n")
gotLines := strings.Split(string(rw.Body.String()), "\n")
gotLinesIdx := 0
t.Log(gotLines)

// Until the Prometheus Go client library offers better testability
// (https://github.com/prometheus/client_golang/issues/58), we simply compare
Expand Down
8 changes: 4 additions & 4 deletions collector/lastlogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import (
const lastLoginSubsystem = "last_login"

type lastLoginCollector struct {
config Config

metric prometheus.Gauge
}

func init() {
Factories["lastlogin"] = NewLastLoginCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// load, seconds since last login and a list of tags as specified by config.
func NewLastLoginCollector(config Config) (Collector, error) {
func NewLastLoginCollector() (Collector, error) {
return &lastLoginCollector{
config: config,

metric: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Subsystem: lastLoginSubsystem,
Expand Down
8 changes: 4 additions & 4 deletions collector/loadavg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const (
)

type loadavgCollector struct {
config Config

metric prometheus.Gauge
}

func init() {
Factories["loadavg"] = NewLoadavgCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// load, seconds since last login and a list of tags as specified by config.
func NewLoadavgCollector(config Config) (Collector, error) {
func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{
config: config,

metric: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "load1",
Expand Down
21 changes: 10 additions & 11 deletions collector/megacli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package collector

import (
"bufio"
"flag"
"io"
"os/exec"
"strconv"
Expand All @@ -17,9 +18,12 @@ const (
adapterHeaderSep = "================"
)

var (
megacliCommand = flag.String("collector.megacli.command", defaultMegaCli, "Command to run megacli.")
)

type megaCliCollector struct {
config Config
cli string
cli string

driveTemperature *prometheus.GaugeVec
driveCounters *prometheus.CounterVec
Expand All @@ -30,17 +34,12 @@ func init() {
Factories["megacli"] = NewMegaCliCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// RAID status through megacli.
func NewMegaCliCollector(config Config) (Collector, error) {
cli := defaultMegaCli
if config.Config["megacli_command"] != "" {
cli = config.Config["megacli_command"]
}

func NewMegaCliCollector() (Collector, error) {
return &megaCliCollector{
config: config,
cli: cli,

cli: *megacliCommand,
driveTemperature: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: Namespace,
Name: "megacli_drive_temperature_celsius",
Expand Down
7 changes: 3 additions & 4 deletions collector/meminfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ const (
)

type meminfoCollector struct {
config Config

metrics map[string]prometheus.Gauge
}

func init() {
Factories["meminfo"] = NewMeminfoCollector
}

// Takes a config struct and prometheus registry and returns a new Collector exposing
// Takes a prometheus registry and returns a new Collector exposing
// memory stats.
func NewMeminfoCollector(config Config) (Collector, error) {
func NewMeminfoCollector() (Collector, error) {
return &meminfoCollector{
config: config,
metrics: map[string]prometheus.Gauge{},
}, nil
}
Expand Down
Loading

0 comments on commit b539481

Please sign in to comment.