Skip to content

Commit b539481

Browse files
committed
Merge pull request #75 from prometheus/remove-attribute-module
Use flags instead of config and remove attributes
2 parents 00ddf58 + 665b05e commit b539481

23 files changed

+87
-162
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Which collectors are used is controlled by the `--collectors.enabled` flag.
3131

3232
Name | Description
3333
---------|------------
34-
attributes | Exposes attributes from the configuration file. Deprecated, use textfile module instead.
3534
diskstats | Exposes disk I/O statistics from `/proc/diskstats`.
3635
filesystem | Exposes filesystem statistics, such as disk space used.
3736
loadavg | Exposes load average.

collector/attributes.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

collector/bonding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func init() {
2626

2727
// NewBondingCollector returns a newly allocated bondingCollector.
2828
// It exposes the number of configured and active slave of linux bonding interfaces.
29-
func NewBondingCollector(config Config) (Collector, error) {
29+
func NewBondingCollector() (Collector, error) {
3030
return &bondingCollector{
3131
slaves: prometheus.NewGaugeVec(
3232
prometheus.GaugeOpts{

collector/collector.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
const Namespace = "node"
99

10-
var Factories = make(map[string]func(Config) (Collector, error))
10+
var Factories = make(map[string]func() (Collector, error))
1111

1212
// Interface a collector has to implement.
1313
type Collector interface {
@@ -20,8 +20,3 @@ type Collector interface {
2020
// scraped. (However, for metric gathering that takes very long, it might
2121
// actually be better to do them proactively before scraping to minimize scrape
2222
// time.)
23-
24-
type Config struct {
25-
Config map[string]string `json:"config"`
26-
Attributes map[string]string `json:"attributes"`
27-
}

collector/diskstats.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
)
2727

2828
type diskstatsCollector struct {
29-
config Config
29+
3030
ignoredDevicesPattern *regexp.Regexp
3131
metrics []prometheus.Collector
3232
}
@@ -35,13 +35,12 @@ func init() {
3535
Factories["diskstats"] = NewDiskstatsCollector
3636
}
3737

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

4343
return &diskstatsCollector{
44-
config: config,
4544
ignoredDevicesPattern: regexp.MustCompile(*ignoredDevices),
4645
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt
4746
metrics: []prometheus.Collector{

collector/filesystem.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var (
2525
)
2626

2727
type filesystemCollector struct {
28-
config Config
28+
2929
ignoredMountPointsPattern *regexp.Regexp
3030

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

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

4343
return &filesystemCollector{
44-
config: config,
44+
4545
ignoredMountPointsPattern: regexp.MustCompile(*ignoredMountPoints),
4646
size: prometheus.NewGaugeVec(
4747
prometheus.GaugeOpts{

collector/gmond.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525

2626
type gmondCollector struct {
2727
metrics map[string]*prometheus.GaugeVec
28-
config Config
28+
2929
}
3030

3131
func init() {
@@ -34,10 +34,9 @@ func init() {
3434

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

37-
// Takes a config struct and prometheus registry and returns a new Collector scraping ganglia.
38-
func NewGmondCollector(config Config) (Collector, error) {
37+
// Takes a prometheus registry and returns a new Collector scraping ganglia.
38+
func NewGmondCollector() (Collector, error) {
3939
c := gmondCollector{
40-
config: config,
4140
metrics: map[string]*prometheus.GaugeVec{},
4241
}
4342

collector/interrupts.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ const (
1818
)
1919

2020
type interruptsCollector struct {
21-
config Config
21+
2222
metric *prometheus.CounterVec
2323
}
2424

2525
func init() {
2626
Factories["interrupts"] = NewInterruptsCollector
2727
}
2828

29-
// Takes a config struct and prometheus registry and returns a new Collector exposing
29+
// Takes a prometheus registry and returns a new Collector exposing
3030
// interrupts stats
31-
func NewInterruptsCollector(config Config) (Collector, error) {
31+
func NewInterruptsCollector() (Collector, error) {
3232
return &interruptsCollector{
33-
config: config,
33+
3434
metric: prometheus.NewCounterVec(
3535
prometheus.CounterOpts{
3636
Namespace: Namespace,

collector/ipvs.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
package collector
44

55
import (
6+
"flag"
67
"fmt"
78
"strconv"
89

910
"github.com/prometheus/client_golang/prometheus"
1011
"github.com/prometheus/procfs"
1112
)
1213

14+
var (
15+
ipvsProcfsMountPoint = flag.String("collector.ipvs.procfs", procfs.DefaultMountPoint, "procfs mountpoint.")
16+
)
17+
1318
type ipvsCollector struct {
1419
Collector
1520
fs procfs.FS
@@ -23,11 +28,11 @@ func init() {
2328

2429
// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
2530
// "procfs" config parameter to override the default proc location (/proc).
26-
func NewIPVSCollector(config Config) (Collector, error) {
27-
return newIPVSCollector(config)
31+
func NewIPVSCollector() (Collector, error) {
32+
return newIPVSCollector()
2833
}
2934

30-
func newIPVSCollector(config Config) (*ipvsCollector, error) {
35+
func newIPVSCollector() (*ipvsCollector, error) {
3136
var (
3237
ipvsBackendLabelNames = []string{
3338
"local_address",
@@ -37,23 +42,14 @@ func newIPVSCollector(config Config) (*ipvsCollector, error) {
3742
"proto",
3843
}
3944
c ipvsCollector
40-
subsystem string
4145
err error
46+
subsystem = "ipvs"
4247
)
4348

44-
if p, ok := config.Config["procfs"]; !ok {
45-
c.fs, err = procfs.NewFS(procfs.DefaultMountPoint)
46-
} else {
47-
c.fs, err = procfs.NewFS(p)
48-
}
49+
c.fs, err = procfs.NewFS(*ipvsProcfsMountPoint)
4950
if err != nil {
5051
return nil, err
5152
}
52-
if s, ok := config.Config["ipvs_subsystem"]; ok {
53-
subsystem = s
54-
} else {
55-
subsystem = "ipvs"
56-
}
5753

5854
c.connections = prometheus.NewCounter(
5955
prometheus.CounterOpts{

collector/ipvs_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package collector
22

33
import (
4+
"flag"
45
"io/ioutil"
56
"net"
67
"net/http"
@@ -106,7 +107,10 @@ var (
106107
)
107108

108109
func TestIPVSCollector(t *testing.T) {
109-
collector, err := newIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}})
110+
if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil {
111+
t.Fatal(err)
112+
}
113+
collector, err := newIPVSCollector()
110114
if err != nil {
111115
t.Fatal(err)
112116
}
@@ -165,7 +169,10 @@ func (c miniCollector) Describe(ch chan<- *prometheus.Desc) {
165169
}
166170

167171
func TestIPVSCollectorResponse(t *testing.T) {
168-
collector, err := NewIPVSCollector(Config{Config: map[string]string{"procfs": "fixtures"}})
172+
if err := flag.Set("collector.ipvs.procfs", "fixtures"); err != nil {
173+
t.Fatal(err)
174+
}
175+
collector, err := NewIPVSCollector()
169176
if err != nil {
170177
t.Fatal(err)
171178
}
@@ -183,6 +190,7 @@ func TestIPVSCollectorResponse(t *testing.T) {
183190
wantLines := strings.Split(string(wantMetrics), "\n")
184191
gotLines := strings.Split(string(rw.Body.String()), "\n")
185192
gotLinesIdx := 0
193+
t.Log(gotLines)
186194

187195
// Until the Prometheus Go client library offers better testability
188196
// (https://github.com/prometheus/client_golang/issues/58), we simply compare

0 commit comments

Comments
 (0)