rsyncprom

package module
v0.0.0-...-f3d9559 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

rsync-prom

Go Reference

An rsync wrapper (or output parser) that pushes metrics to prometheus.

This allows you to then build dashboards and alerting for your rsync batch jobs.

Installation

go install github.com/stapelberg/rsyncprom/cmd/rsync-prom@latest

Build

GOOS=linux GOARCH=amd64 go build -o rsync-prom-linux-amd64
GOOS=linux GOARCH=arm64 go build -o rsync-prom-linux-arm64

Setup example: crontab

9 9 * * * /home/michael/go/bin/rsync-prom --instance="sync-drive" -- /home/michael/sync-drive.sh

Setup example: systemd

[Service]
ExecStart=/home/michael/go/bin/rsync-prom --instance="sync-wiki" -- /usr/bin/rsync --exclude data/cache -av --checksum server:wiki/ /var/cache/wiki

Code example: SSH wrapper

Here’s an example for code which uses the x/crypto/ssh package to trigger rsync on a remote machine and parses the output:

https://github.com/stapelberg/zkj-nas-tools/blob/02d46d718df60c413844d9218f6dd702ad94e5f1/dornroeschen/sshutil.go#L134-L139

Documentation

Overview

Package rsyncprom implements a parser that extracts transfer details from rsync standard output output.

This package contains the parser, see cmd/rsync-prom for a wrapper program.

Rsync Requirements

Start rsync with --verbose (-v) or --stats to enable printing transfer totals.

Do not use the --human-readable (-h) flag in your rsync invocation, otherwise rsyncprom cannot parse the output!

Run rsync in the C.UTF-8 locale to prevent rsync from localizing decimal separators and fractional points in big numbers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapRsync

func WrapRsync(ctx context.Context, params *WrapParams, args []string, start func(context.Context, []string) (io.Reader, error), wait func() int) error

WrapRsync starts one rsync invocation and pushes prometheus metrics about the invocation to the Prometheus push gateway specified in the WrapParams.

This function is used by the cmd/rsync-prom wrapper tool, but you can also use it programmatically and start rsync remotely via SSH instead of wrapping the process, for example.

Types

type Stats

type Stats = rsyncparse.Stats

Stats contains all data found in rsync output.

func Parse

func Parse(r io.Reader) (*Stats, error)

Parse reads from the specified io.Reader and scans individual lines. rsync transfer totals are extracted when found, and returned in the Stats struct.

Example
stats, err := Parse(strings.NewReader(`

sent 1,192,097 bytes  received 1,039 bytes  795,424.00 bytes/sec
total size is 1,188,046  speedup is 1.00
`))
if err != nil {
	log.Fatal(err)
}
fmt.Printf("corpus is %d bytes big!\n", stats.TotalSize)
Output:

corpus is 1188046 bytes big!

type WrapParams

type WrapParams struct {
	// Address of a Prometheus push gateway. This is passed as url parameter to
	// https://pkg.go.dev/github.com/prometheus/client_golang/prometheus/push#New
	Pushgateway string
	// Prometheus instance label.
	Instance string
	// Prometheus job name.
	Job string
}

WrapParams is the configuration struct for the WrapRsync() function.

Directories

Path Synopsis
cmd
rsync-prom
Program rsync-prom is a wrapper for rsync which exports prometheus metrics to a prometheus push gateway.
Program rsync-prom is a wrapper for rsync which exports prometheus metrics to a prometheus push gateway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL