Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit 994dd80

Browse files
author
Murat Kabilov
committed
init
1 parent 2c3168d commit 994dd80

File tree

170 files changed

+48435
-4
lines changed

Some content is hidden

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

170 files changed

+48435
-4
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
# Output of the go coverage tool, specifically when used with LiteIDE
1111
*.out
1212

13-
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
14-
.glide/

Gopkg.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
branch = "master"
30+
name = "github.com/lib/pq"
31+
32+
[[constraint]]
33+
name = "github.com/prometheus/client_golang"
34+
version = "0.8.0"
35+
36+
[[constraint]]
37+
name = "gopkg.in/yaml.v2"
38+
version = "2.2.1"
39+
40+
[prune]
41+
go-tests = true
42+
unused-packages = true

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.PHONY: clean local
2+
3+
DIRS := cmd pkg
4+
PKG := `go list ./... | grep -v /vendor/`
5+
VERSION ?= $(shell git describe --tags --always --dirty)
6+
LDFLAGS ?= -X=main.version=$(VERSION)
7+
BINARY := pg-prometheus-exporter
8+
CGO_ENABLED ?= 0
9+
10+
clean:
11+
rm -f ${BINARY}
12+
13+
tools:
14+
@go get -u github.com/golang/dep/cmd/dep
15+
16+
fmt:
17+
@gofmt -l -w -s $(DIRS)
18+
19+
deps:
20+
@dep ensure -v
21+
22+
all:
23+
CGO_ENABLED=${CGO_ENABLED} go build -o ${BINARY} -ldflags "$(LDFLAGS)" main.go $^

README.md

Lines changed: 158 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,158 @@
1-
# pg-prometheus-exporter
2-
PostgreSQL Prometheus Exporter
1+
# PostgreSQL Metrics Exporter
2+
[![Go Report Card](https://goreportcard.com/badge/github.com/ikitiki/postgresql_exporter)](https://goreportcard.com/report/github.com/ikitiki/postgresql_exporter)
3+
4+
5+
Prometheus exporter for PostgreSQL metrics.<br>
6+
7+
## Features
8+
9+
- Use of multiple connections while fetching metrics
10+
- Statement timeouts to cancel long-running queries
11+
- Version-specific queries in the config file
12+
- Connection labels
13+
14+
## Getting and running
15+
16+
Get:
17+
```
18+
go get -u github.com/ikitiki/postgresql_exporter
19+
```
20+
21+
Run:
22+
```
23+
postgresql_exporter --config {path to config file}
24+
```
25+
26+
27+
## Config file
28+
```
29+
{connection name}:
30+
host: {host}
31+
port: {port}
32+
user: {username}
33+
dbname: {db name}
34+
sslmode: {ssl mode}
35+
workers: {number of parallel connections to use}
36+
statementTimeout: {pg statement_timeout value for each connection}
37+
labels:
38+
{labels added to each metric in the "queryFiles"}
39+
queryFiles:
40+
{use metric queries from files}
41+
```
42+
43+
sample:
44+
```
45+
pg10:
46+
host: localhost
47+
port: 5432
48+
user: postgres
49+
dbname: test
50+
sslmode: disable
51+
workers: 5
52+
labels:
53+
ver: 10
54+
queryFiles:
55+
- "basic.yaml"
56+
- "pertable.yaml"
57+
```
58+
59+
## Query file
60+
61+
sample:
62+
first query will be using for postgresql >=10
63+
the second query will be using for postgresql >=9.4 but <10
64+
```
65+
pg_slots:
66+
query:
67+
10-: >-
68+
select
69+
slot_name,
70+
slot_type,
71+
active,
72+
case when not pg_is_in_recovery() then pg_current_wal_lsn() - restart_lsn end as current_lag_bytes
73+
from pg_replication_slots s
74+
order by s.slot_name
75+
9.4-10: >-
76+
select
77+
slot_name,
78+
slot_type,
79+
active,
80+
case when not pg_is_in_recovery() then pg_current_xlog_location() - restart_lsn end as current_lag_bytes
81+
from pg_replication_slots s
82+
order by s.slot_name
83+
metrics:
84+
- slot_name:
85+
usage: "LABEL"
86+
description: "Slot name"
87+
- slot_type:
88+
usage: "LABEL"
89+
description: "Slot type"
90+
- active:
91+
usage: "LABEL"
92+
description: "Is slot active"
93+
- current_lag_bytes:
94+
usage: "GAUGE"
95+
description: "Lag in bytes"
96+
```
97+
98+
query will be used for all the postgresql versions:
99+
```
100+
relation_total_size:
101+
query: >-
102+
select
103+
n.nspname as schemaname,
104+
c.relname,
105+
pg_total_relation_size(c.oid) as inclusive_bytes,
106+
pg_relation_size(c.oid) as exclusive_bytes
107+
from pg_class c
108+
join pg_namespace n on c.relnamespace = n.oid
109+
where relkind = 'r'
110+
and n.nspname not in ('pg_toast', 'pg_catalog', 'information_schema')
111+
metrics:
112+
- schemaname:
113+
usage: "LABEL"
114+
description: "Schema of relation"
115+
- relname:
116+
usage: "LABEL"
117+
description: "Name of relation"
118+
- inclusive_bytes:
119+
usage: "GAUGE"
120+
description: "Size of table, including indexes and toast"
121+
- exclusive_bytes:
122+
usage: "GAUGE"
123+
description: "Size of table, excluding indexes and toast"
124+
```
125+
126+
127+
if you need to get metric names and values from the columns,
128+
specify them in the "nameColumn" and "valueColumn" accordingly:
129+
```
130+
pg_settings:
131+
query:
132+
8.0-9.5: >-
133+
select
134+
name,
135+
case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting
136+
from pg_settings
137+
where vartype IN ('bool', 'integer', 'real')
138+
9.5-: >-
139+
select
140+
name,
141+
case setting when 'off' then 0 when 'on' then 1 else setting::numeric end as setting,
142+
pending_restart
143+
from pg_settings
144+
where vartype IN ('bool', 'integer', 'real')
145+
nameColumn: "name"
146+
valueColumn: "setting"
147+
metrics:
148+
- pending_restart:
149+
usage: "LABEL"
150+
description: "if the value has been changed in the configuration file but needs a restart"
151+
- allow_system_table_mods:
152+
usage: "GAUGE"
153+
description: "Allows modifications of the structure of system tables"
154+
- archive_timeout:
155+
usage: "GAUGE"
156+
description: "Forces a switch to the next WAL file if a new file has not been started within N seconds"
157+
...
158+
```

0 commit comments

Comments
 (0)