diff --git a/README b/README index ee93a0b..5b3cfdc 100644 --- a/README +++ b/README @@ -7,8 +7,8 @@ This is appropriate for monitoring on a server in which you do not want to store You should add other monitoring tools to check consistency with other exporters. ## Features -- Metrics for the last transaction timestamp and number for each repository. -- Configurable via a JSON file. +- Metrics for the last transaction number for each repository. +- Configurable via a JSON file for multiple repos ## Usage @@ -23,11 +23,10 @@ You should add other monitoring tools to check consistency with other exporters. ``` 2. Run the exporter: ```bash - ./borgbackuptransactions_exporter --config=config.json + ./borgbackuptransactions_exporter -config=config.json ``` ### Metrics exposed -- `borgbackup_last_transaction_timestamp` - `borgbackup_last_transaction_number` ### How to scrape diff --git a/main.go b/main.go index a394d67..7d6a607 100644 --- a/main.go +++ b/main.go @@ -37,13 +37,6 @@ const ( ) var ( - lastTransactionTimestamp = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "borgbackup_last_transaction_timestamp", - Help: "Unix timestamp of the last transaction in the BorgBackup repository", - }, - []string{"repo"}, - ) lastTransactionNumber = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "borgbackup_last_transaction_number", @@ -54,7 +47,6 @@ var ( ) func init() { - prometheus.MustRegister(lastTransactionTimestamp) prometheus.MustRegister(lastTransactionNumber) } @@ -187,33 +179,26 @@ func updateRepoMetrics(repo string) { // instead of deferring as usual, close as soon as the file.Close() - transactionNumber, timestamp, err := parseTransactionLine(lastLine) + transactionNumber, err := parseTransactionLine(lastLine) if err != nil { log.Printf("Failed to parse transactions file for repo %s: %v", repo, err) return } - lastTransactionTimestamp.WithLabelValues(repo).Set(float64(timestamp)) lastTransactionNumber.WithLabelValues(repo).Set(float64(transactionNumber)) } -func parseTransactionLine(line string) (int, int64, error) { +func parseTransactionLine(line string) (int, error) { parts := strings.Split(line, ",") if len(parts) < 2 { - return 0, 0, fmt.Errorf("invalid line format: %s", line) + return 0, fmt.Errorf("invalid line format: %s", line) } numberStr := strings.TrimPrefix(parts[0], "transaction ") transactionNumber, err := strconv.Atoi(strings.TrimSpace(numberStr)) if err != nil { - return 0, 0, fmt.Errorf("failed to parse transaction number: %v", err) - } - - timeStr := strings.TrimSpace(strings.Replace(parts[1], "UTC time", "", -1)) - t, err := time.Parse("2006-01-02T15:04:05.000000", timeStr) - if err != nil { - return 0, 0, fmt.Errorf("failed to parse UTC time: %v", err) + return 0, fmt.Errorf("failed to parse transaction number: %v", err) } - return transactionNumber, t.Unix(), nil + return transactionNumber, nil } diff --git a/main_test.go b/main_test.go index f632a87..410f671 100644 --- a/main_test.go +++ b/main_test.go @@ -2,25 +2,25 @@ package main import ( "testing" - "time" ) func TestParseTransactionLine(t *testing.T) { line := "transaction 6374, UTC time 2024-11-30T11:45:36.870201" - number, timestamp, err := parseTransactionLine(line) + // number, timestamp, err := parseTransactionLine(line) + number, err := parseTransactionLine(line) if err != nil { t.Fatalf("Expected no error, got %v", err) } expectedNumber := 6374 - expectedTime := time.Date(2024, 11, 30, 11, 45, 36, 870201000, time.UTC).Unix() + // expectedTime := time.Date(2024, 11, 30, 11, 45, 36, 870201000, time.UTC).Unix() if number != expectedNumber { t.Errorf("Expected transaction number %d, got %d", expectedNumber, number) } - if timestamp != expectedTime { + /* if timestamp != expectedTime { t.Errorf("Expected timestamp %d, got %d", expectedTime, timestamp) - } + } */ }