Skip to content

Commit e6389f7

Browse files
docs: add monitoring chapter for status & prometheus (#505)
1 parent 43b6c84 commit e6389f7

File tree

9 files changed

+82
-50
lines changed

9 files changed

+82
-50
lines changed

config/profile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func (i *InitSection) resolve(_ *Profile) {
136136
i.FromRepository.setValue(fixPath(i.FromRepository.Value(), expandEnv, expandUserHome))
137137
}
138138

139-
func (i *InitSection) setRootPath(_ *Profile, rootPath string) {
139+
func (i *InitSection) setRootPath(p *Profile, rootPath string) {
140+
i.GenericSection.setRootPath(p, rootPath)
141+
140142
i.FromRepositoryFile = fixPath(i.FromRepositoryFile, expandEnv, expandUserHome, absolutePrefix(rootPath))
141143
i.FromPasswordFile = fixPath(i.FromPasswordFile, expandEnv, expandUserHome, absolutePrefix(rootPath))
142144
}

docs/content/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ With resticprofile:
2323
* Check for [enough memory]({{% relref "/usage/memory" %}}) before starting a backup
2424
* Generate cryptographically secure random keys for a restic [key file]({{% relref "/usage/keyfile" %}})
2525
* Easily [schedule]({{% relref "/schedules" %}}) backups, retentions, and checks (supports *systemd*, *crond*, *launchd*, and *Windows Task Scheduler*)
26-
* Generate a simple [status file]({{% relref "/status" %}}) for monitoring software to ensure backups are running smoothly
26+
* Generate a simple [status file]({{% relref "/monitoring/status" %}}) for monitoring software to ensure backups are running smoothly
2727
* Use [template syntax]({{% relref "/configuration/templates" %}}) in your configuration file
2828
* Automatically clear [stale locks]({{% relref "/usage/locks" %}})
29-
* Export a [prometheus]({{% relref "/status/prometheus" %}}) file after a backup or send the report to a push gateway
29+
* Export a [prometheus]({{% relref "/monitoring/prometheus" %}}) file after a backup or send the report to a push gateway
3030
* Run shell commands in the background when non-fatal errors are detected
3131
* Send messages to [HTTP hooks]({{% relref "/configuration/http_hooks" %}}) before, after a successful or failed job (backup, forget, check, prune, copy)
3232
* Automatically [initialize the secondary repository]({{% relref "/configuration/copy" %}}) using the `copy-chunker-params` flag

docs/content/configuration/http_hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "HTTP Hooks"
33
weight: 22
4+
tags: [ "monitoring", "healthchecks.io" ]
45
---
56

67

docs/content/configuration/run_hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Command Hooks"
33
weight: 20
4+
tags: [ "monitoring" ]
45
---
56

67

docs/content/monitoring/_index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
archetype: "chapter"
3+
pre: "<b>5. </b>"
4+
title: "Monitoring"
5+
weight: 5
6+
---
7+
8+
{{% children %}}
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
---
22
title: "Prometheus"
3-
weight: 5
3+
slug: prometheus
4+
weight: 10
5+
tags: [ "monitoring" ]
46
---
57

6-
7-
8-
resticprofile can generate a prometheus file, or send the report to a push gateway. For now, only a `backup` command will generate a report.
9-
Here's a configuration example with both options to generate a file and send to a push gateway:
8+
Resticprofile can generate a Prometheus file or send the report to a Pushgateway. Currently, only the `backup` command generates a report. Below is a configuration example for generating a file and sending it to a Pushgateway:
109

1110
{{< tabs groupid="config-with-json" >}}
1211
{{% tab title="toml" %}}
@@ -80,66 +79,69 @@ root:
8079
{{< /tabs >}}
8180

8281
{{% notice style="note" %}}
83-
Please note you need to set `extended-status` to `true` if you want all the available metrics. See [Extended status]({{% relref "/status/index.html#-extended-status" %}}) for more information.
82+
Set `extended-status` to `true` to access all available metrics. For details, see [Extended status]({{% relref "/monitoring/status/index.html#-extended-status" %}}).
8483
{{% /notice %}}
8584

86-
Here's an example of the generated prometheus file:
85+
Here's an example of a generated prometheus file:
8786

8887
```
88+
# HELP restic_build_info restic build information.
89+
# TYPE restic_build_info gauge
90+
restic_build_info{profile="prom",version="0.18.0"} 1
8991
# HELP resticprofile_backup_added_bytes Total number of bytes added to the repository.
9092
# TYPE resticprofile_backup_added_bytes gauge
91-
resticprofile_backup_added_bytes{profile="prom"} 9.83610983e+08
93+
resticprofile_backup_added_bytes{profile="prom"} 96167
9294
# HELP resticprofile_backup_dir_changed Number of directories with changes.
9395
# TYPE resticprofile_backup_dir_changed gauge
94-
resticprofile_backup_dir_changed{profile="prom"} 0
96+
resticprofile_backup_dir_changed{profile="prom"} 8
9597
# HELP resticprofile_backup_dir_new Number of new directories added to the backup.
9698
# TYPE resticprofile_backup_dir_new gauge
97-
resticprofile_backup_dir_new{profile="prom"} 847
99+
resticprofile_backup_dir_new{profile="prom"} 0
98100
# HELP resticprofile_backup_dir_unmodified Number of directories unmodified since last backup.
99101
# TYPE resticprofile_backup_dir_unmodified gauge
100-
resticprofile_backup_dir_unmodified{profile="prom"} 0
102+
resticprofile_backup_dir_unmodified{profile="prom"} 1060
101103
# HELP resticprofile_backup_duration_seconds The backup duration (in seconds).
102104
# TYPE resticprofile_backup_duration_seconds gauge
103-
resticprofile_backup_duration_seconds{profile="prom"} 4.453124672
105+
resticprofile_backup_duration_seconds{profile="prom"} 0.986296416
104106
# HELP resticprofile_backup_files_changed Number of files with changes.
105107
# TYPE resticprofile_backup_files_changed gauge
106-
resticprofile_backup_files_changed{profile="prom"} 0
108+
resticprofile_backup_files_changed{profile="prom"} 2
107109
# HELP resticprofile_backup_files_new Number of new files added to the backup.
108110
# TYPE resticprofile_backup_files_new gauge
109-
resticprofile_backup_files_new{profile="prom"} 6006
111+
resticprofile_backup_files_new{profile="prom"} 0
110112
# HELP resticprofile_backup_files_processed Total number of files scanned by the backup for changes.
111113
# TYPE resticprofile_backup_files_processed gauge
112-
resticprofile_backup_files_processed{profile="prom"} 6006
114+
resticprofile_backup_files_processed{profile="prom"} 7723
113115
# HELP resticprofile_backup_files_unmodified Number of files unmodified since last backup.
114116
# TYPE resticprofile_backup_files_unmodified gauge
115-
resticprofile_backup_files_unmodified{profile="prom"} 0
117+
resticprofile_backup_files_unmodified{profile="prom"} 7721
116118
# HELP resticprofile_backup_processed_bytes Total number of bytes scanned for changes.
117119
# TYPE resticprofile_backup_processed_bytes gauge
118-
resticprofile_backup_processed_bytes{profile="prom"} 1.016520315e+09
120+
resticprofile_backup_processed_bytes{profile="prom"} 2.935621558e+09
119121
# HELP resticprofile_backup_status Backup status: 0=fail, 1=warning, 2=success.
120122
# TYPE resticprofile_backup_status gauge
121123
resticprofile_backup_status{profile="prom"} 2
122124
# HELP resticprofile_backup_time_seconds Last backup run (unixtime).
123125
# TYPE resticprofile_backup_time_seconds gauge
124-
resticprofile_backup_time_seconds{profile="prom"} 1.707863748e+09
126+
resticprofile_backup_time_seconds{profile="prom"} 1.747673785e+09
125127
# HELP resticprofile_build_info resticprofile build information.
126128
# TYPE resticprofile_build_info gauge
127-
resticprofile_build_info{goversion="go1.22.0",profile="prom",version="0.26.0"} 1
129+
resticprofile_build_info{goversion="go1.24.3",profile="prom",version="0.31.0"} 1
130+
128131
129132
```
130133

131134
## Prometheus Pushgateway
132135

133-
Prometheus Pushgateway uses the job label as a grouping key. All metrics with the same grouping key get replaced when pushed. To prevent metrics from multiple profiles getting overwritten by each other, the default job label is set to `<profile_name>.<command>` (e.g. `root.backup`).
136+
Prometheus Pushgateway uses the job label as a grouping key. Metrics with the same grouping key are replaced when pushed. To prevent overwriting metrics from different profiles, the default job label is set to `<profile_name>.<command>` (e.g., `root.backup`).
134137

135-
If you need more control over the job label, you can use the `prometheus-push-job` property. This property can contain the `$command` placeholder, which is replaced with the name of the executed command.
138+
For more control over the job label, use the `prometheus-push-job` property. This property supports the `$command` placeholder, which is replaced with the executed command's name.
136139

137-
Additionally, the request format can be specified with `prometheus-push-format`. The default is `text`, but it can also be set to `protobuf` (see [compatibility with Prometheus](https://prometheus.io/docs/instrumenting/exposition_formats/#exposition-formats)).
140+
You can specify the request format using `prometheus-push-format`. The default is `text`, but it can also be set to `protobuf` (see [compatibility with Prometheus](https://prometheus.io/docs/instrumenting/exposition_formats/#exposition-formats)).
138141

139-
## User defined labels
142+
## User-Defined Labels
140143

141-
You can add your own prometheus labels. Please note they will be applied to **all** the metrics.
142-
Here's an example:
144+
You can add custom Prometheus labels, which will apply to **all** metrics. Example:
143145

144146
{{< tabs groupid="config-with-json" >}}
145147
{{% tab title="toml" %}}
@@ -227,4 +229,4 @@ root:
227229
{{< /tabs >}}
228230

229231

230-
which will add the `host` label to all your metrics.
232+
This adds the `host` label to all your metrics.
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
+++
2-
archetype = "chapter"
3-
pre = "<b>5. </b>"
4-
title = "Status file"
5-
weight = 5
6-
+++
1+
---
2+
title: "Status file"
3+
slug: status
4+
weight: 5
5+
tags: [ "monitoring" ]
6+
aliases:
7+
- /status
8+
---
79

10+
If you need to send your backup results to a monitoring system, use the `run-after` and `run-after-fail` scripts.
811

9-
If you need to escalate the result of your backup to a monitoring system, you can definitely use the `run-after` and `run-after-fail` scripting.
12+
For simpler needs, resticprofile can generate a JSON file with details of the latest backup, forget, or check command. For example, I use a Zabbix agent to [check this file](https://github.com/creativeprojects/resticprofile/tree/master/contrib/zabbix) daily. Any monitoring system that reads JSON files can be integrated.
1013

11-
But sometimes we just need something simple that a monitoring system can regularly check. For that matter, resticprofile can generate a simple JSON file with the details of the latest backup/forget/check command. For example I have a Zabbix agent [checking this file](https://github.com/creativeprojects/resticprofile/tree/master/contrib/zabbix) once a day, and so you can hook up any monitoring system that can interpret a JSON file.
12-
13-
In your profile, you simply need to add a new parameter, which is the location of your status file
14+
To enable this, add the status file location as a parameter in your profile.
1415

1516
{{< tabs groupid="config-with-json" >}}
1617
{{% tab title="toml" %}}
@@ -57,7 +58,7 @@ profile:
5758
{{< /tabs >}}
5859

5960

60-
Here's an example of a generated file, where you can see that the last `check` failed, whereas the last `backup` succeeded:
61+
Here is an example of a generated file showing the last `check` failed, while the last `backup` succeeded:
6162

6263
```json
6364
{
@@ -93,18 +94,18 @@ Here's an example of a generated file, where you can see that the last `check` f
9394

9495
## ⚠️ Extended status
9596

96-
In the backup section above you can see some fields like `files_new`, `files_total`, etc. This information is only available when resticprofile's output is either *not* sent to the terminal (e.g. redirected) or when you add the flag `extended-status` to your backup configuration.
97+
In the backup section above, you can see fields like `files_new` and `files_total`. This information is available only when resticprofile's output is redirected or when the `extended-status` flag is added to your backup configuration.
9798

98-
This is a technical limitation to ensure restic displays terminal output correctly.
99+
This limitation ensures restic displays terminal output correctly.
99100

100-
`extended-status` or stdout redirection is **not needed** for these fields:
101+
The following fields do **not** require `extended-status` or stdout redirection:
101102
- success
102103
- time
103104
- error
104105
- stderr
105106
- duration
106107

107-
`extended-status` is **not set by default because it hides any output from restic**
108+
The `extended-status` flag is **disabled by default because it suppresses restic's output**.
108109

109110
{{< tabs groupid="config-with-json" >}}
110111
{{% tab title="toml" %}}

docs/hugo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ publishdir = "../public/"
4040
main = false
4141
type = 'menu'
4242

43-
# [[menu.shortcuts]]
44-
# name = "<i class='fas fa-tags'></i> Tags"
45-
# url = "/tags"
46-
# weight = 10
43+
[[menu.shortcuts]]
44+
name = "<i class='fas fa-tags'></i> Tags"
45+
url = "/tags"
46+
weight = 10
4747

4848
[[menu.shortcuts]]
4949
name = "<i class='fab fa-fw fa-github'></i> GitHub repo"

examples/dev.yaml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ self:
129129
schedule:
130130
- "*:05,10,15,20,25,35"
131131
schedule-permission: user
132+
run-before:
133+
- "echo Check started"
134+
run-after:
135+
- "echo Check done"
136+
send-before:
137+
- url: "https://httpbin.org/status/400"
138+
send-after:
139+
- url: "https://httpbin.org/status/400"
140+
init:
141+
run-before:
142+
- "echo Init started"
143+
run-after:
144+
- "echo Init done"
145+
send-before:
146+
- url: "https://httpbin.org/status/400"
147+
send-after:
148+
- url: "https://httpbin.org/status/400"
132149
retention:
133150
after-backup: true
134151
keep-last: 30
@@ -173,8 +190,8 @@ prom:
173190
inherit: default
174191
prometheus-save-to-file: "self.prom"
175192
prometheus-push: "http://localhost:9091/"
176-
prometheus-labels:
177-
host: "{{ .Hostname }}"
193+
# prometheus-labels:
194+
# host: "{{ .Hostname }}"
178195
status-file: /Volumes/RAMDisk/status.json
179196
backup:
180197
check-after: true

0 commit comments

Comments
 (0)