Skip to content

Commit 1d3051e

Browse files
authored
Merge pull request #39 from sysdiglabs/master
Master fetch
2 parents 76a350d + a8735d3 commit 1d3051e

40 files changed

+1009
-384
lines changed

.circleci/config.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
version: 2.1
33

44
orbs:
5-
prometheus: prometheus/prometheus@0.11.0
5+
prometheus: prometheus/prometheus@0.16.0
66

77
executors:
88
# This must match .promu.yml.
99
golang:
1010
docker:
11-
- image: circleci/golang:1.16
11+
- image: cimg/go:1.18
1212

1313
jobs:
1414
test:
@@ -22,7 +22,7 @@ jobs:
2222

2323
integration:
2424
docker:
25-
- image: circleci/golang:1.16
25+
- image: cimg/go:1.18
2626
- image: << parameters.postgres_image >>
2727
environment:
2828
POSTGRES_DB: circle_test
@@ -56,13 +56,11 @@ workflows:
5656
matrix:
5757
parameters:
5858
postgres_image:
59-
- circleci/postgres:9.4
60-
- circleci/postgres:9.5
61-
- circleci/postgres:9.6
6259
- circleci/postgres:10
6360
- circleci/postgres:11
6461
- circleci/postgres:12
6562
- circleci/postgres:13
63+
- cimg/postgres:14.1
6664
- prometheus/build:
6765
name: build
6866
filters:

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ assignees: ''
3737
insert list of flags used here
3838
```
3939

40-
* PostgresSQL version:
40+
* PostgreSQL version:
4141

4242
insert PostgreSQL version here
4343

.github/workflows/golangci-lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
paths:
5+
- "go.sum"
6+
- "go.mod"
7+
- "**.go"
8+
- "scripts/errcheck_excludes.txt"
9+
- ".github/workflows/golangci-lint.yml"
10+
- ".golangci.yml"
11+
pull_request:
12+
13+
jobs:
14+
golangci:
15+
name: lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v3
20+
- name: install Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.18.x
24+
- name: Install snmp_exporter/generator dependencies
25+
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
26+
if: github.repository == 'prometheus/snmp_exporter'
27+
- name: Lint
28+
uses: golangci/[email protected]
29+
with:
30+
version: v1.45.2

.promu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
go:
22
# This must match .circle/config.yml.
3-
version: 1.16
3+
version: 1.18
44
repository:
55
path: github.com/prometheus-community/postgres_exporter
66
build:

.yamllint

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
braces:
6+
max-spaces-inside: 1
7+
level: error
8+
brackets:
9+
max-spaces-inside: 1
10+
level: error
11+
commas: disable
12+
comments: disable
13+
comments-indentation: disable
14+
document-start: disable
15+
indentation:
16+
spaces: consistent
17+
indent-sequences: consistent
18+
key-duplicates:
19+
ignore: |
20+
config/testdata/section_key_dup.bad.yml
21+
line-length: disable
22+
truthy:
23+
ignore: |
24+
.github/workflows/codeql-analysis.yml
25+
.github/workflows/funcbench.yml
26+
.github/workflows/fuzzing.yml
27+
.github/workflows/prombench.yml
28+
.github/workflows/golangci-lint.yml

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## master / unreleased
2+
3+
* [CHANGE] pg_stat_bgwriter counter metrics had the `_total` suffix added #556
4+
* [ENHANCEMENT] Add pg_database_size_bytes metric #613
5+
6+
## 0.10.1 / 2022-01-14
7+
8+
* [BUGFIX] Fix broken log-level for values other than debug. #560
9+
110
## 0.10.0 / 2021-07-08
211

312
* [ENHANCEMENT] Add ability to set included databases when autoDiscoverDatabases is enabled #499

CODE_OF_CONDUCT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## Prometheus Community Code of Conduct
1+
# Prometheus Community Code of Conduct
22

3-
Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
3+
Prometheus follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
* Ben Kochie <[email protected]> @SuperQ
22
* William Rouesnel <[email protected]> @wrouesnel
3+
* Joe Adams <[email protected]> @sysadmind

Makefile.common

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ ifneq ($(shell which gotestsum),)
7878
endif
7979
endif
8080

81-
PROMU_VERSION ?= 0.12.0
81+
PROMU_VERSION ?= 0.13.0
8282
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8383

8484
GOLANGCI_LINT :=
8585
GOLANGCI_LINT_OPTS ?=
86-
GOLANGCI_LINT_VERSION ?= v1.39.0
86+
GOLANGCI_LINT_VERSION ?= v1.45.2
8787
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8888
# windows isn't included here because of the path separator being different.
8989
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9090
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
91-
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
91+
# If we're in CI and there is an Actions file, that means the linter
92+
# is being run in Actions, so we don't need to run it here.
93+
ifeq (,$(CIRCLE_JOB))
94+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
95+
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
96+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
97+
endif
9298
endif
9399
endif
94100

@@ -118,7 +124,7 @@ endif
118124
%: common-% ;
119125

120126
.PHONY: common-all
121-
common-all: precheck style check_license lint unused build test
127+
common-all: precheck style check_license lint yamllint unused build test
122128

123129
.PHONY: common-style
124130
common-style:
@@ -154,7 +160,7 @@ endif
154160
update-go-deps:
155161
@echo ">> updating Go dependencies"
156162
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157-
$(GO) get $$m; \
163+
$(GO) get -d $$m; \
158164
done
159165
GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160166
ifneq (,$(wildcard vendor))
@@ -198,6 +204,15 @@ else
198204
endif
199205
endif
200206

207+
.PHONY: common-yamllint
208+
common-yamllint:
209+
@echo ">> running yamllint on all YAML files in the repository"
210+
ifeq (, $(shell which yamllint))
211+
@echo "yamllint not installed so skipping"
212+
else
213+
yamllint .
214+
endif
215+
201216
# For backward-compatibility.
202217
.PHONY: common-staticcheck
203218
common-staticcheck: lint

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Prometheus exporter for PostgreSQL server metrics.
99

10-
CI Tested PostgreSQL versions: `9.4`, `9.5`, `9.6`, `10`, `11`, `12`, `13`
10+
CI Tested PostgreSQL versions: `9.4`, `9.5`, `9.6`, `10`, `11`, `12`, `13`, `14`
1111

1212
## Quick Start
1313
This package is available for Docker:
@@ -41,20 +41,26 @@ This will build the docker image as `prometheuscommunity/postgres_exporter:${bra
4141
* `help`
4242
Show context-sensitive help (also try --help-long and --help-man).
4343

44+
* `collector.database`
45+
Enable the pg_database collector. Default is `enabled`
46+
47+
* `collector.bgwriter`
48+
Enable the pg_stat_bgwriter collector. Default is `enabled`
49+
4450
* `web.listen-address`
4551
Address to listen on for web interface and telemetry. Default is `:9187`.
4652

4753
* `web.telemetry-path`
4854
Path under which to expose metrics. Default is `/metrics`.
4955

5056
* `disable-default-metrics`
51-
Use only metrics supplied from `queries.yaml` via `--extend.query-path`.
57+
Use only metrics supplied from `queries.yaml` via `--extend.query-path`. Default is `false`.
5258

5359
* `disable-settings-metrics`
54-
Use the flag if you don't want to scrape `pg_settings`.
60+
Use the flag if you don't want to scrape `pg_settings`. Default is `false`.
5561

5662
* `auto-discover-databases`
57-
Whether to discover the databases on a server dynamically.
63+
Whether to discover the databases on a server dynamically. Default is `false`.
5864

5965
* `extend.query-path`
6066
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
@@ -186,8 +192,8 @@ The -extend.query-path command-line argument specifies a YAML file containing ad
186192
Some examples are provided in [queries.yaml](queries.yaml).
187193

188194
### Disabling default metrics
189-
To work with non-officially-supported postgres versions you can try disabling (e.g. 8.2.15)
190-
or a variant of postgres (e.g. Greenplum) you can disable the default metrics with the `--disable-default-metrics`
195+
To work with non-officially-supported postgres versions (e.g. 8.2.15),
196+
or variants of postgres (e.g. Greenplum), you can disable the default metrics with the `--disable-default-metrics`
191197
flag. This removes all built-in metrics, and uses only metrics defined by queries in the `queries.yaml` file you supply
192198
(so you must supply one, otherwise the exporter will return nothing but internal statuses and not your database).
193199

@@ -203,14 +209,10 @@ If you want to include only subset of databases, you can use option `--include-d
203209

204210
### Running as non-superuser
205211

206-
To be able to collect metrics from `pg_stat_activity` and `pg_stat_replication`
207-
as non-superuser you have to create functions and views as a superuser, and
208-
assign permissions separately to those.
209-
210-
In PostgreSQL, views run with the permissions of the user that created them so
211-
they can act as security barriers. Functions need to be created to share this
212-
data with the non-superuser. Only creating the views will leave out the most
213-
important bits of data.
212+
To be able to collect metrics from `pg_stat*` views as non-superuser in PostgreSQL
213+
server versions >= 10 you can grant the `pg_monitor` or `pg_read_all_stats` [built-in roles](https://www.postgresql.org/docs/current/predefined-roles.html) to the user. If
214+
you need to monitor older PostgreSQL servers, you will have to create functions
215+
and views as a superuser, and assign permissions separately to those.
214216

215217
```sql
216218
-- To use IF statements, hence to be able to check if the user exists before
@@ -239,9 +241,23 @@ ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
239241
-- If deploying as non-superuser (for example in AWS RDS), uncomment the GRANT
240242
-- line below and replace <MASTER_USER> with your root user.
241243
-- GRANT postgres_exporter TO <MASTER_USER>;
244+
245+
GRANT CONNECT ON DATABASE postgres TO postgres_exporter;
246+
```
247+
248+
Run following command if you use PostgreSQL versions >= 10
249+
```sql
250+
GRANT pg_monitor to postgres_exporter;
251+
```
252+
253+
Run following SQL commands only if you use PostgreSQL versions older than 10.
254+
In PostgreSQL, views run with the permissions of the user that created them so
255+
they can act as security barriers. Functions need to be created to share this
256+
data with the non-superuser. Only creating the views will leave out the most
257+
important bits of data.
258+
```sql
242259
CREATE SCHEMA IF NOT EXISTS postgres_exporter;
243260
GRANT USAGE ON SCHEMA postgres_exporter TO postgres_exporter;
244-
GRANT CONNECT ON DATABASE postgres TO postgres_exporter;
245261

246262
CREATE OR REPLACE FUNCTION get_pg_stat_activity() RETURNS SETOF pg_stat_activity AS
247263
$$ SELECT * FROM pg_catalog.pg_stat_activity; $$
@@ -267,6 +283,7 @@ AS
267283

268284
GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
269285

286+
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
270287
CREATE OR REPLACE FUNCTION get_pg_stat_statements() RETURNS SETOF pg_stat_statements AS
271288
$$ SELECT * FROM public.pg_stat_statements; $$
272289
LANGUAGE sql

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
The Prometheus security policy, including how to report vulnerabilities, can be
44
found here:
55

6-
https://prometheus.io/docs/operating/security/
6+
<https://prometheus.io/docs/operating/security/>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.0
1+
0.10.1

cmd/postgres_exporter/datasource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"regexp"
2222
"strings"
2323

24-
"github.com/go-kit/kit/log/level"
24+
"github.com/go-kit/log/level"
2525
"github.com/prometheus/client_golang/prometheus"
2626
)
2727

cmd/postgres_exporter/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
"net/http"
1818
"os"
1919

20-
"github.com/go-kit/kit/log"
21-
"github.com/go-kit/kit/log/level"
20+
"github.com/go-kit/log"
21+
"github.com/go-kit/log/level"
22+
"github.com/prometheus-community/postgres_exporter/collector"
2223
"github.com/prometheus/client_golang/prometheus"
2324
"github.com/prometheus/client_golang/prometheus/promhttp"
2425
"github.com/prometheus/common/promlog"
@@ -114,6 +115,17 @@ func main() {
114115

115116
prometheus.MustRegister(exporter)
116117

118+
pe, err := collector.NewPostgresCollector(
119+
logger,
120+
dsn,
121+
[]string{},
122+
)
123+
if err != nil {
124+
level.Error(logger).Log("msg", "Failed to create PostgresCollector", "err", err.Error())
125+
os.Exit(1)
126+
}
127+
prometheus.MustRegister(pe)
128+
117129
http.Handle(*metricPath, promhttp.Handler())
118130
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
119131
w.Header().Set("Content-Type", "text/html; charset=UTF-8") // nolint: errcheck

cmd/postgres_exporter/namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121

2222
"github.com/blang/semver"
23-
"github.com/go-kit/kit/log/level"
23+
"github.com/go-kit/log/level"
2424
"github.com/lib/pq"
2525
"github.com/prometheus/client_golang/prometheus"
2626
)

0 commit comments

Comments
 (0)