metrics

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metrics emits Prometheus-compatible metrics written to a textfile collector directory for node_exporter to scrape. Backup operations record last-success timestamps, duration, bytes, and verify results.

Package metrics — license.go emits Prometheus metrics for license grace period monitoring. Metrics are written as textfile collector .prom files for node_exporter to scrape.

Metrics:

  • nself_license_grace_days_remaining (gauge)
  • nself_license_offline_seconds (gauge)

Package metrics — stripe.go emits Prometheus metrics for Stripe webhook processing. These metrics enable alerting on webhook failures, latency, outbox depth, and signature attacks.

Metrics (spec G-31-11):

  • nself_stripe_event_received_total{type,result} (counter)
  • nself_stripe_event_duration_seconds{type} (histogram via gauge of last)
  • nself_stripe_outbox_depth (gauge)
  • nself_stripe_signature_failures_total (counter)

Index

Constants

View Source
const DefaultTextfileDir = "/var/lib/node_exporter/textfile_collector"

DefaultTextfileDir is the node_exporter textfile collector directory.

Variables

This section is empty.

Functions

func EmitBackup

func EmitBackup(r BackupRecord) error

EmitBackup writes a .prom file named `nself_backup_{type}.prom` atomically. The file is replaced each run, not appended, so gauges reflect the latest result only. Counters are cumulative and read-back before rewrite.

func EmitLicense

func EmitLicense(r LicenseRecord) error

EmitLicense writes license grace metrics to nself_license.prom.

func EmitStripeEvent

func EmitStripeEvent(r StripeEventRecord) error

EmitStripeEvent writes stripe event processing metrics.

func EmitStripeOutbox

func EmitStripeOutbox(r StripeOutboxRecord) error

EmitStripeOutbox writes the current outbox depth gauge.

func EmitStripeSignatureFailure

func EmitStripeSignatureFailure(r StripeSignatureRecord) error

EmitStripeSignatureFailure increments the signature failure counter.

func EmitVerify

func EmitVerify(r VerifyRecord) error

EmitVerify writes the restore-test verify result to its own .prom file.

Types

type BackupRecord

type BackupRecord struct {
	Env         string    // prod, staging, dev
	Type        string    // full, wal, metadata, minio
	Success     bool      // completion result
	DurationSec float64   // total wall-clock seconds
	Bytes       int64     // archive size on disk
	Encrypted   bool      // whether age encryption was applied
	Timestamp   time.Time // completion time
	TextfileDir string    // overrides DefaultTextfileDir when non-empty
}

BackupRecord is the signal set emitted on every nself backup create exit.

type LicenseRecord

type LicenseRecord struct {
	Host               string  // hostname label (e.g., "nclaw-prod")
	Env                string  // prod, staging, dev
	GraceDaysRemaining float64 // days until hard stop; negative if past
	OfflineSeconds     float64 // seconds since last successful validation
	GraceState         string  // valid, grace_soft, grace_hard, expired
	Tier               string  // license tier
	TextfileDir        string  // overrides DefaultTextfileDir when non-empty
}

LicenseRecord captures the current license grace state for metric emission.

type StripeEventRecord

type StripeEventRecord struct {
	EventType   string  // e.g., "customer.subscription.created"
	Result      string  // "ok" or "error"
	DurationSec float64 // processing time in seconds
	TextfileDir string  // overrides DefaultTextfileDir when non-empty
}

StripeEventRecord captures a single Stripe webhook event for metric emission.

type StripeOutboxRecord

type StripeOutboxRecord struct {
	Depth       int    // number of events waiting in outbox
	TextfileDir string // overrides DefaultTextfileDir when non-empty
}

StripeOutboxRecord captures the current outbox state.

type StripeSignatureRecord

type StripeSignatureRecord struct {
	TextfileDir string // overrides DefaultTextfileDir when non-empty
}

StripeSignatureRecord captures a signature verification failure.

type VerifyRecord

type VerifyRecord struct {
	Env         string
	Success     bool
	DurationSec float64
	Timestamp   time.Time
	TextfileDir string
}

VerifyRecord is emitted by the weekly restore-test verify cycle.

Jump to

Keyboard shortcuts

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