Skip to content

Commit ce5826a

Browse files
authored
Merge branch 'master' into master
2 parents 491db5e + 81194c9 commit ce5826a

File tree

720 files changed

+277919
-156
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

720 files changed

+277919
-156
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ postgres_exporter_integration_test
88
*.iml
99
cover.out
1010
cover.*.out
11+
.coverage
1112
*.prom
13+
.metrics.*.*.prom

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
- docker
44
language: go
55
go:
6-
- '1.7.5'
6+
- '1.8'
77
# Make sure we have p2 and the postgres client.
88
before_install:
99
- go get -v github.com/mattn/goveralls
@@ -17,7 +17,7 @@ script:
1717
- make all
1818
- make docker
1919
- make test-integration
20-
- ./concatenate_coverage cover.out cover.test.out cover.integration.out
20+
- make cover.out
2121
- $HOME/gopath/bin/goveralls -coverprofile=cover.out -service=travis-ci
2222
after_success:
2323
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS

Makefile

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11

2-
GO_SRC := $(shell find -type f -name '*.go' ! -path '*/vendor/*')
2+
COVERDIR = .coverage
3+
TOOLDIR = tools
4+
5+
GO_SRC := $(shell find . -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' )
6+
GO_DIRS := $(shell find . -type d -name '*.go' ! -path '*/vendor/*' ! -path 'tools/*' )
7+
GO_PKGS := $(shell go list ./... | grep -v '/vendor/')
38

49
CONTAINER_NAME ?= wrouesnel/postgres_exporter:latest
510
VERSION ?= $(shell git describe --dirty)
611

7-
all: vet test postgres_exporter
12+
CONCURRENT_LINTERS ?= $(shell cat /proc/cpuinfo | grep processor | wc -l)
13+
LINTER_DEADLINE ?= 30s
14+
15+
export PATH := $(TOOLDIR)/bin:$(PATH)
16+
SHELL := env PATH=$(PATH) /bin/bash
17+
18+
all: style lint test postgres_exporter
819

920
# Cross compilation (e.g. if you are on a Mac)
1021
cross: docker-build docker
@@ -21,35 +32,48 @@ postgres_exporter_integration_test: $(GO_SRC)
2132
docker: postgres_exporter
2233
docker build -t $(CONTAINER_NAME) .
2334

24-
vet:
25-
go vet
35+
style: tools
36+
gometalinter --disable-all --enable=gofmt --vendor
2637

27-
# Check code conforms to go fmt
28-
style:
29-
! gofmt -s -l $(GO_SRC) 2>&1 | read 2>/dev/null
38+
lint: tools
39+
@echo Using $(CONCURRENT_LINTERS) processes
40+
gometalinter -j $(CONCURRENT_LINTERS) --deadline=$(LINTER_DEADLINE) --disable=gotype --disable=gocyclo $(GO_DIRS)
3041

31-
# Format the code
32-
fmt:
42+
fmt: tools
3343
gofmt -s -w $(GO_SRC)
3444

35-
test:
36-
go test -v -covermode count -coverprofile=cover.test.out
45+
test: tools
46+
@mkdir -p $(COVERDIR)
47+
@rm -f $(COVERDIR)/*
48+
for pkg in $(GO_PKGS) ; do \
49+
go test -v -covermode count -coverprofile=$(COVERDIR)/$$(echo $$pkg | tr '/' '-').out $$pkg ; \
50+
done
51+
gocovmerge $(shell find $(COVERDIR) -name '*.out') > cover.test.out
3752

3853
test-integration: postgres_exporter postgres_exporter_integration_test
3954
tests/test-smoke "$(shell pwd)/postgres_exporter" "$(shell pwd)/postgres_exporter_integration_test_script $(shell pwd)/postgres_exporter_integration_test $(shell pwd)/cover.integration.out"
4055

56+
cover.out: tools
57+
gocovmerge cover.*.out > cover.out
58+
4159
# Do a self-contained docker build - we pull the official upstream container
4260
# and do a self-contained build.
4361
docker-build:
4462
docker run -v $(shell pwd):/go/src/github.com/wrouesnel/postgres_exporter \
4563
-v $(shell pwd):/real_src \
4664
-e SHELL_UID=$(shell id -u) -e SHELL_GID=$(shell id -g) \
4765
-w /go/src/github.com/wrouesnel/postgres_exporter \
48-
golang:1.7-wheezy \
66+
golang:1.8-wheezy \
4967
/bin/bash -c "make >&2 && chown $$SHELL_UID:$$SHELL_GID ./postgres_exporter"
5068
docker build -t $(CONTAINER_NAME) .
5169

5270
push:
5371
docker push $(CONTAINER_NAME)
5472

55-
.PHONY: docker-build docker test vet push cross
73+
tools:
74+
$(MAKE) -C $(TOOLDIR)
75+
76+
clean:
77+
rm -f postgres_exporter postgres_exporter_integration_test
78+
79+
.PHONY: tools docker-build docker lint fmt test vet push cross clean

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
[![Coverage Status](https://coveralls.io/repos/github/wrouesnel/postgres_exporter/badge.svg?branch=master)](https://coveralls.io/github/wrouesnel/postgres_exporter?branch=master)
33
[![Go Report Card](https://goreportcard.com/badge/github.com/wrouesnel/postgres_exporter)](https://goreportcard.com/report/github.com/wrouesnel/postgres_exporter)
44

5-
# PostgresSQL Server Exporter
5+
# PostgreSQL Server Exporter
66

7-
Prometheus exporter for PostgresSQL server metrics.
7+
Prometheus exporter for PostgreSQL server metrics.
88
Supported Postgres versions: 9.1 and up.
99

1010
## Quick Start
@@ -44,7 +44,7 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
4444

4545
### Setting the Postgres server's data source name
4646

47-
The PostgresSQL server's [data source name](http://en.wikipedia.org/wiki/Data_source_name)
47+
The PostgreSQL server's [data source name](http://en.wikipedia.org/wiki/Data_source_name)
4848
must be set via the `DATA_SOURCE_NAME` environment variable.
4949

5050
For running it locally on a default Debian/Ubuntu install, this will work (transpose to init script as appropriate):
@@ -81,6 +81,8 @@ To be able to collect metrics from pg_stat_activity and pg_stat_replication as n
8181
CREATE USER postgres_exporter PASSWORD 'password';
8282
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
8383

84+
-- If deploying as non-superuser (for example in AWS RDS)
85+
-- GRANT postgres_exporter TO :MASTER_USER;
8486
CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;
8587

8688
CREATE FUNCTION postgres_exporter.f_select_pg_stat_activity()

concatenate_coverage

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

pg_setting.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func querySettings(ch chan<- prometheus.Metric, db *sql.DB) error {
2626
if err != nil {
2727
return errors.New(fmt.Sprintln("Error running query on database: ", namespace, err))
2828
}
29-
defer rows.Close()
29+
defer rows.Close() // nolint: errcheck
3030

3131
for rows.Next() {
3232
s := &pgSetting{}
@@ -51,7 +51,7 @@ func (s *pgSetting) metric() prometheus.Metric {
5151
var (
5252
err error
5353
name = strings.Replace(s.name, ".", "_", -1)
54-
unit = s.unit
54+
unit = s.unit // nolint: ineffassign
5555
shortDesc = s.shortDesc
5656
subsystem = "settings"
5757
val float64
@@ -85,7 +85,7 @@ func (s *pgSetting) metric() prometheus.Metric {
8585
func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
8686
val, err = strconv.ParseFloat(s.setting, 64)
8787
if err != nil {
88-
return val, unit, errors.New(fmt.Sprintf("Error converting setting %q value %q to float: %s", s.name, s.setting, err))
88+
return val, unit, fmt.Errorf("Error converting setting %q value %q to float: %s", s.name, s.setting, err)
8989
}
9090

9191
// Units defined in: https://www.postgresql.org/docs/current/static/config-setting.html
@@ -97,7 +97,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
9797
case "kB", "MB", "GB", "TB", "8kB", "16MB":
9898
unit = "bytes"
9999
default:
100-
err = errors.New(fmt.Sprintf("Unknown unit for runtime variable: %q", s.unit))
100+
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
101101
return
102102
}
103103

pg_setting_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type PgSettingSuite struct{}
1212
var _ = Suite(&PgSettingSuite{})
1313

1414
var fixtures = []fixture{
15-
fixture{
15+
{
1616
p: pgSetting{
1717
name: "seconds_fixture_metric",
1818
setting: "5",
@@ -28,7 +28,7 @@ var fixtures = []fixture{
2828
d: "Desc{fqName: \"pg_settings_seconds_fixture_metric_seconds\", help: \"Foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
2929
v: 5,
3030
},
31-
fixture{
31+
{
3232
p: pgSetting{
3333
name: "milliseconds_fixture_metric",
3434
setting: "5000",
@@ -44,7 +44,7 @@ var fixtures = []fixture{
4444
d: "Desc{fqName: \"pg_settings_milliseconds_fixture_metric_seconds\", help: \"Foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
4545
v: 5,
4646
},
47-
fixture{
47+
{
4848
p: pgSetting{
4949
name: "eight_kb_fixture_metric",
5050
setting: "17",
@@ -60,7 +60,7 @@ var fixtures = []fixture{
6060
d: "Desc{fqName: \"pg_settings_eight_kb_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}",
6161
v: 139264,
6262
},
63-
fixture{
63+
{
6464
p: pgSetting{
6565
name: "16_mb_real_fixture_metric",
6666
setting: "3.0",
@@ -76,7 +76,7 @@ var fixtures = []fixture{
7676
d: "Desc{fqName: \"pg_settings_16_mb_real_fixture_metric_bytes\", help: \"Foo foo foo [Units converted to bytes.]\", constLabels: {}, variableLabels: []}",
7777
v: 5.0331648e+07,
7878
},
79-
fixture{
79+
{
8080
p: pgSetting{
8181
name: "bool_on_fixture_metric",
8282
setting: "on",
@@ -92,7 +92,7 @@ var fixtures = []fixture{
9292
d: "Desc{fqName: \"pg_settings_bool_on_fixture_metric\", help: \"Foo foo foo\", constLabels: {}, variableLabels: []}",
9393
v: 1,
9494
},
95-
fixture{
95+
{
9696
p: pgSetting{
9797
name: "bool_off_fixture_metric",
9898
setting: "off",
@@ -108,7 +108,7 @@ var fixtures = []fixture{
108108
d: "Desc{fqName: \"pg_settings_bool_off_fixture_metric\", help: \"Foo foo foo\", constLabels: {}, variableLabels: []}",
109109
v: 0,
110110
},
111-
fixture{
111+
{
112112
p: pgSetting{
113113
name: "special_minus_one_value",
114114
setting: "-1",
@@ -124,7 +124,7 @@ var fixtures = []fixture{
124124
d: "Desc{fqName: \"pg_settings_special_minus_one_value_seconds\", help: \"foo foo foo [Units converted to seconds.]\", constLabels: {}, variableLabels: []}",
125125
v: -1,
126126
},
127-
fixture{
127+
{
128128
p: pgSetting{
129129
name: "rds.rds_superuser_reserved_connections",
130130
setting: "2",
@@ -140,7 +140,7 @@ var fixtures = []fixture{
140140
d: "Desc{fqName: \"pg_settings_rds_rds_superuser_reserved_connections\", help: \"Sets the number of connection slots reserved for rds_superusers.\", constLabels: {}, variableLabels: []}",
141141
v: 2,
142142
},
143-
fixture{
143+
{
144144
p: pgSetting{
145145
name: "unknown_unit",
146146
setting: "10",
@@ -186,7 +186,7 @@ func (s *PgSettingSuite) TestMetric(c *C) {
186186
for _, f := range fixtures {
187187
d := &dto.Metric{}
188188
m := f.p.metric()
189-
m.Write(d)
189+
m.Write(d) // nolint: errcheck
190190

191191
c.Check(m.Desc().String(), Equals, f.d)
192192
c.Check(d.GetGauge().GetValue(), Equals, f.v)

0 commit comments

Comments
 (0)