snapshot

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package snapshot generates system reports and sends them to notifiarr.com. The reports include zfs data, cpu, memory, mdadm info, megaraid arrays, smart status, mounted volume (disk) usage, cpu temp, other temps, uptime, drive age/health, logged on user count, etc. Works across most platforms. These snapshots are posted to a user's Chatroom on request.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is used when one is not provided.

View Source
const SynologyConf = "/etc/synoinfo.conf"

SynologyConf is the path to the syno config file.

Variables

View Source
var (
	ErrPlatformUnsup = fmt.Errorf("the requested metric is not available on this platform, " +
		"if you know how to collect it, please open an issue on the github repo")
	ErrNonZeroExit = fmt.Errorf("cmd exited non-zero")
)

Errors this package generates.

View Source
var ErrNoDisks = fmt.Errorf("no disks found")

ErrNoDisks is returned when no disks are found.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout   cnfg.Duration `toml:"timeout" xml:"timeout"`                     // total run time allowed.
	Interval  cnfg.Duration `toml:"interval" xml:"interval"`                   // how often to send snaps (cron).
	ZFSPools  []string      `toml:"zfs_pools" xml:"zfs_pool"`                  // zfs pools to monitor.
	UseSudo   bool          `toml:"use_sudo" xml:"use_sudo"`                   // use sudo for smartctl commands.
	Raid      bool          `toml:"monitor_raid" xml:"monitor_raid"`           // include mdstat and/or megaraid.
	DriveData bool          `toml:"monitor_drives" xml:"monitor_drives"`       // smartctl commands.
	DiskUsage bool          `toml:"monitor_space" xml:"monitor_space"`         // get disk usage.
	Uptime    bool          `toml:"monitor_uptime" xml:"monitor_uptime"`       // all system stats.
	CPUMem    bool          `toml:"monitor_cpuMemory" xml:"monitor_cpuMemory"` // cpu perct and memory used/free.
	CPUTemp   bool          `toml:"monitor_cpuTemp" xml:"monitor_cpuTemp"`     // not everything supports temps.
	// contains filtered or unexported fields
}

Config determines which checks to run, etc.

func (*Config) GetSnapshot

func (c *Config) GetSnapshot() (*Snapshot, []error, []error)

GetSnapshot returns a system snapshot based on requested data in the config.

func (*Config) Validate

func (c *Config) Validate()

Validate makes sure the snapshot configuration is valid.

type Partition

type Partition struct {
	Device string `json:"name"`
	Total  uint64 `json:"total"`
	Free   uint64 `json:"free"`
}

Partition is used for ZFS pools as well as normal Disk arrays.

type RaidData

type RaidData struct {
	MDstat  string            `json:"mdstat,omitempty"`
	MegaCLI map[string]string `json:"megacli,omitempty"`
}

RaidData contains raid information from mdstat and/or megacli.

type Snapshot

type Snapshot struct {
	Version string
	Uptime  time.Duration
	System  struct {
		*host.InfoStat
		Username string             `json:"username"`
		CPU      float64            `json:"cpuPerc"`
		MemFree  uint64             `json:"memFree"`
		MemUsed  uint64             `json:"memUsed"`
		MemTotal uint64             `json:"memTotal"`
		Temps    map[string]float64 `json:"temperatures,omitempty"`
		Users    int                `json:"users"`
		*load.AvgStat
	} `json:"system"`
	Raid       *RaidData             `json:"raid,omitempty"`
	DriveAges  map[string]int        `json:"driveAges,omitempty"`
	DriveTemps map[string]int        `json:"driveTemps,omitempty"`
	DiskUsage  map[string]*Partition `json:"diskUsage,omitempty"`
	DiskHealth map[string]string     `json:"driveHealth,omitempty"`
	ZFSPool    map[string]*Partition `json:"zfsPools,omitempty"`
	// contains filtered or unexported fields
}

Snapshot is the output data sent to Notifiarr.

func (*Snapshot) GetCPUSample

func (s *Snapshot) GetCPUSample(ctx context.Context, run bool) error

GetCPUSample gets a CPU percentage sample.

func (*Snapshot) GetLocalData

func (s *Snapshot) GetLocalData(ctx context.Context, run bool) (errs []error)

GetLocalData collects current username, logged in user and host info.

func (*Snapshot) GetMemoryUsage

func (s *Snapshot) GetMemoryUsage(ctx context.Context, run bool) error

GetMemoryUsage returns current host memory consumption.

func (*Snapshot) GetSynology

func (s *Snapshot) GetSynology(run bool) error

GetSynology checks if the app is running on a Synology, and gets system info.

func (*Snapshot) GetUsers

func (s *Snapshot) GetUsers(ctx context.Context) error

GetUsers collects logged in users.

type Synology

type Synology struct {
	Build   string `json:"last_admin_login_build"` // 254263
	Manager string `json:"manager"`                // Synology DiskStation
	Vendor  string `json:"vender"`                 // Synology Inc.
	Model   string `json:"upnpmodelname"`          // DS1517+
	Version string `json:"udc_check_state"`        // 6.2.3
}

Synology is the data we care about from the config file.

Jump to

Keyboard shortcuts

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