Skip to content

Commit a610404

Browse files
kmoppelpashagolub
andauthored
[+] add a SystemD service template (#704)
* Add a SystemD service template to DEB / RPM / Tar * move samples to a special `contrib` folder * fix tests * fix linter warnings --------- Co-authored-by: Pavlo Golub <pavlo.golub@gmail.com>
1 parent 0fb6465 commit a610404

File tree

6 files changed

+41
-28
lines changed

6 files changed

+41
-28
lines changed

.goreleaser.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ archives:
2828
- goos: windows
2929
formats: ['zip']
3030
files:
31-
- ./grafana/**/*
32-
- ./README.md
33-
- src: ./internal/sources/sample.sources.yaml
34-
dst: sample.sources.yaml
35-
- src: ./internal/metrics/metrics.yaml
36-
dst: metrics.yaml
31+
- "./grafana/**/*"
32+
- "./README.md"
33+
- src: "./internal/metrics/metrics.yaml"
34+
dst: "metrics.yaml"
35+
- src: "./contrib/sample.sources.yaml"
36+
dst: "sample.sources.yaml"
37+
- src: "./contrib/sample.systemd.service"
38+
dst: "/etc/pgwatch/sample.systemd.service"
3739

3840

3941
checksum:
@@ -63,9 +65,11 @@ nfpms:
6365
contents:
6466
- src: "./grafana/*"
6567
dst: "/etc/pgwatch/grafana"
66-
- src: "./internal/sources/sample.sources.yaml"
68+
- src: "./contrib/sample.sources.yaml"
6769
dst: "/etc/pgwatch/sample.sources.yaml"
6870
- src: "./internal/metrics/metrics.yaml"
6971
dst: "/etc/pgwatch/metrics.yaml"
7072
- src: "./README.md"
7173
dst: "/etc/pgwatch/README.md"
74+
- src: "./contrib/sample.systemd.service"
75+
dst: "/etc/pgwatch/sample.systemd.service"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- name: test1 # An arbitrary unique name for the monitored source
2-
conn_str: postgresql://pgwatch:pgwatchadmin@somehost/mydb
2+
conn_str: postgresql://postgres@localhost/postgres
33
kind: postgres # One of the:
44
# - postgres
55
# - postgres-continuous-discovery

contrib/sample.systemd.service

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This is an example of a systemD config file for pgwatch.
2+
# You can copy it to "/etc/systemd/system/pgwatch.service", adjust as necessary and then call
3+
# systemctl daemon-reload && systemctl start pgwatch && systemctl enable pgwatch
4+
# to start and also enable auto-start after reboot.
5+
6+
[Unit]
7+
Description=Pgwatch Gathering Daemon
8+
After=network-online.target
9+
# When on the monitored node then it's a good idea to only launch after Postgres
10+
# After=postgresql
11+
12+
[Service]
13+
User=postgres
14+
Type=simple
15+
ExecStart=/usr/bin/pgwatch --sources /etc/pgwatch/sample.sources.yaml --sink=prometheus://0.0.0.0:9187
16+
Restart=on-failure
17+
TimeoutStartSec=0
18+
19+
[Install]
20+
WantedBy=multi-user.target

docs/concept/installation_options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The default Docker demo image `cybertecpostgresql/pgwatch-demo` uses this approa
2323
One can deploy the gatherer daemon(s) decentralized with
2424
*sources to be monitored* defined in simple YAML files. In that case there
2525
is no need for the central Postgres configuration database. See the
26-
[sample.sources.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/sources/sample.sources.yaml)
26+
[sample.sources.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/contrib/sample.sources.yaml)
2727
config file for an example.
2828

2929
!!! Note

docs/reference/advanced_features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ config (for Config DB based setups) looks like:
3434
```
3535

3636
For YAML based setups an example can be found from the
37-
[instances.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/sources/sample.sources.yaml#L21)
37+
[instances.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/contrib/sample.sources.yaml#L21)
3838
file.
3939

4040
If Patroni is powered by *etcd*, then also username, password, ca_file,
@@ -65,7 +65,7 @@ the whole instance. The metric name to enable log parsing is
6565
destination / setting to work, the monitoring user needs superuser /
6666
pg_monitor privileges - if this is not possible then log settings need
6767
to be specified manually under "Host config" as seen for example
68-
[here](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/sources/sample.sources.yaml#L25).
68+
[here](https://github.com/cybertec-postgresql/pgwatch/blob/master/contrib/sample.sources.yaml#L25).
6969

7070
**Sample configuration if not using CSVLOG logging:**
7171

internal/sources/yaml_test.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sources_test
33
import (
44
"os"
55
"path/filepath"
6-
"runtime"
76
"testing"
87

98
"github.com/stretchr/testify/assert"
@@ -14,24 +13,14 @@ import (
1413
// the number of entries in the sample.sources.yaml file
1514
const sampleEntriesNumber = 4
1615

17-
var (
18-
currentDir string
19-
sampleFile string
16+
const (
17+
contribDir = "../../contrib/"
18+
sampleFile = "../../contrib/sample.sources.yaml"
2019
)
2120

22-
func init() {
23-
// setup the test environment
24-
_, filename, _, ok := runtime.Caller(0)
25-
if !ok {
26-
panic("Cannot get the current file path")
27-
}
28-
currentDir = filepath.Dir(filename)
29-
sampleFile = filepath.Join(currentDir, "sample.sources.yaml")
30-
}
31-
3221
func TestNewYAMLSourcesReaderWriter(t *testing.T) {
3322
a := assert.New(t)
34-
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, "../sample.sources.yaml")
23+
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, sampleFile)
3524
a.NoError(err)
3625
a.NotNil(t, yamlrw)
3726
}
@@ -49,7 +38,7 @@ func TestYAMLGetMonitoredDatabases(t *testing.T) {
4938
})
5039

5140
t.Run("folder with yaml files", func(*testing.T) {
52-
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, currentDir)
41+
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, contribDir)
5342
a.NoError(err)
5443

5544
dbs, err := yamlrw.GetSources()
@@ -66,7 +55,7 @@ func TestYAMLGetMonitoredDatabases(t *testing.T) {
6655
})
6756

6857
t.Run("garbage file", func(*testing.T) {
69-
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, filepath.Join(currentDir, "yaml.go"))
58+
yamlrw, err := sources.NewYAMLSourcesReaderWriter(ctx, filepath.Join(contribDir, "yaml.go"))
7059
a.NoError(err)
7160
dbs, err := yamlrw.GetSources()
7261
a.Error(err)

0 commit comments

Comments
 (0)