snapshot

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 33 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 = 45 * time.Second

DefaultTimeout is used when one is not provided.

Variables

View Source
var (
	ErrPlatformUnsup = errors.New("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 = errors.New("cmd exited non-zero")
)

Errors this package generates.

View Source
var ErrNoDisks = errors.New("no disks found")

ErrNoDisks is returned when no disks are found.

View Source
var ErrNotSynology = errors.New("the running host is not a Synology")

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout   cnfg.Duration `json:"timeout"       toml:"timeout"        xml:"timeout"`        // total run time allowed.
	Interval  cnfg.Duration `json:"interval"      toml:"interval"       xml:"interval"`       // how often to send snaps (cron).
	ZFSPools  []string      `json:"zfsPools"      toml:"zfs_pools"      xml:"zfs_pool"`       // zfs pools to monitor.
	UseSudo   bool          `json:"useSudo"       toml:"use_sudo"       xml:"use_sudo"`       // use sudo for smartctl commands.
	Raid      bool          `json:"monitorRaid"   toml:"monitor_raid"   xml:"monitor_raid"`   // include mdstat and/or megaraid.
	DriveData bool          `json:"monitorDrives" toml:"monitor_drives" xml:"monitor_drives"` // smartctl commands.
	DiskUsage bool          `json:"monitorSpace"  toml:"monitor_space"  xml:"monitor_space"`  // get disk usage.
	AllDrives bool          `json:"allDrives"     toml:"all_drives"     xml:"all_drives"`     // usage for all drives?
	Quotas    bool          `json:"quotas"        toml:"quotas"         xml:"quotas"`         // usage for user quotas?
	IOTop     int           `json:"ioTop"         toml:"iotop"          xml:"iotop"`          // number of processes to include from ioTop
	PSTop     int           `json:"psTop"         toml:"pstop"          xml:"pstop"`          // number of processes to include from top (cpu usage)
	MyTop     int           `json:"myTop"         toml:"mytop"          xml:"mytop"`          // number of processes to include from mysql servers.
	IPMI      bool          `json:"ipmi"          toml:"ipmi"           xml:"ipmi"`           // get ipmi sensor info.
	IPMISudo  bool          `json:"ipmiSudo"      toml:"ipmiSudo"       xml:"ipmiSudo"`       // use sudo to get ipmi sensor info.
	Plugins
}

Config determines which checks to run, etc.

func (*Config) GetSnapshot

func (c *Config) GetSnapshot(ctx context.Context, debugf func(string, ...any)) (*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 IOTopData added in v0.2.1

type IOTopData struct {
	TotalRead  float64    `json:"totalRead"`
	TotalWrite float64    `json:"totalWrite"`
	CurrRead   float64    `json:"currentRead"`
	CurrWrite  float64    `json:"currentWrite"`
	Processes  IOTopProcs `json:"procs"`
}

IOTopData is the data structure for iotop output.

type IOTopProc added in v0.2.1

type IOTopProc struct {
	Pid       int     `json:"pid"`
	Priority  string  `json:"prio"`
	User      string  `json:"user"`
	DiskRead  float64 `json:"diskRead"`
	DiskWrite float64 `json:"diskWrite"`
	SwapIn    float64 `json:"swapIn"`
	IO        float64 `json:"io"`
	Command   string  `json:"command"`
}

IOTopProc is part of IOTopData.

type IOTopProcs added in v0.2.1

type IOTopProcs []*IOTopProc

IOTopProcs is part of IOTopData.

func (IOTopProcs) Len added in v0.2.1

func (s IOTopProcs) Len() int

Len allows us to sort IOTopProcs.

func (IOTopProcs) Less added in v0.2.1

func (s IOTopProcs) Less(i, j int) bool

Less allows us to sort IOTopProcs.

func (*IOTopProcs) Shrink added in v0.2.1

func (s *IOTopProcs) Shrink(size int)

Shrink a process list.

func (IOTopProcs) Swap added in v0.2.1

func (s IOTopProcs) Swap(i, j int)

Swap allows us to sort IOTopProcs.

type IPMISensor added in v0.5.0

type IPMISensor struct {
	Name  string  `json:"name"`
	Value float64 `json:"value"`
	Unit  string  `json:"unit"`
	State string  `json:"state"`
}

IPMISensor contains the data for one sensor.

type IoStatData added in v0.2.1

type IoStatData struct {
	Sysstat struct {
		Hosts []*IoStatHost `json:"hosts"`
	} `json:"sysstat"`
}

IoStatData is the data structure for iostat output.

type IoStatDisk added in v0.2.1

type IoStatDisk struct {
	DiskDevice string  `json:"disk_device"`
	RS         float64 `json:"r/s"`
	WS         float64 `json:"w/s"`
	DS         float64 `json:"d/s"`
	RkBS       float64 `json:"rkB/s"`
	WkBS       float64 `json:"wkB/s"`
	DkBS       float64 `json:"dkB/s"`
	RrqmS      float64 `json:"rrqm/s"`
	WrqmS      float64 `json:"wrqm/s"`
	DrqmS      float64 `json:"drqm/s"`
	Rrqm       float64 `json:"rrqm"`
	Wrqm       float64 `json:"wrqm"`
	Drqm       float64 `json:"drqm"`
	RAwait     float64 `json:"r_await"`
	WAwait     float64 `json:"w_await"`
	DAwait     float64 `json:"d_await"`
	RareqSz    float64 `json:"rareq-sz"`
	WareqSz    float64 `json:"wareq-sz"`
	DareqSz    float64 `json:"dareq-sz"`
	AquSz      float64 `json:"aqu-sz"`
	Util       float64 `json:"util"`
}

IoStatDisk is part of IoStatData.

type IoStatDisks added in v0.2.1

type IoStatDisks []*IoStatDisk

IoStatDisks is part of IoStatData.

type IoStatHost added in v0.2.1

type IoStatHost struct {
	Nodename     string `json:"nodename"`
	Sysname      string `json:"sysname"`
	Release      string `json:"release"`
	Machine      string `json:"machine"`
	NumberOfCpus int    `json:"number-of-cpus"`
	Date         string `json:"date"`
	Statistics   []struct {
		Disk IoStatDisks `json:"disk"`
	} `json:"statistics"`
}

IoStatHost is part of IoStatData.

type MegaCLI added in v0.3.2

type MegaCLI struct {
	Drive   string            `json:"drive"`
	Target  string            `json:"target"`
	Adapter string            `json:"adapter"`
	Data    map[string]string `json:"data"`
}

MegaCLI represents the megaraid cli output.

type MySQLConfig added in v0.2.1

type MySQLConfig struct {
	Name    string        `json:"name"    toml:"name"    xml:"name"`
	Host    string        `json:"host"    toml:"host"    xml:"host"`
	User    string        `json:"-"       toml:"user"    xml:"user"`
	Pass    string        `json:"-"       toml:"pass"    xml:"pass"`
	Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout"`
	// Only used by service checks, snapshot interval is used for mysql.
	Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval"`
}

MySQLConfig allows us to gather a process list for the snapshot.

type MySQLProcess added in v0.2.1

type MySQLProcess struct {
	ID       int64      `json:"id"`
	User     string     `json:"user"`
	Host     string     `json:"host"`
	DB       NullString `json:"db"`
	Cmd      string     `json:"command"`
	Time     int64      `json:"time"`
	State    string     `json:"state"`
	Info     NullString `json:"info"`
	Progress float64    `json:"progress"` // mariadb
}

MySQLProcess represents the data returned from SHOW PROCESS LIST.

type MySQLProcesses added in v0.2.1

type MySQLProcesses []*MySQLProcess

MySQLProcesses allows us to manipulate our list with methods.

func (MySQLProcesses) Len added in v0.2.1

func (s MySQLProcesses) Len() int

Len allows us to sort MySQLProcesses.

func (MySQLProcesses) Less added in v0.2.1

func (s MySQLProcesses) Less(i, j int) bool

Less allows us to sort MySQLProcesses.

func (*MySQLProcesses) Shrink added in v0.2.1

func (s *MySQLProcesses) Shrink(size int)

Shrink a process list.

func (MySQLProcesses) Swap added in v0.2.1

func (s MySQLProcesses) Swap(i, j int)

Swap allows us to sort MySQLProcesses.

type MySQLServerData added in v0.2.1

type MySQLServerData struct {
	Name      string         `json:"name"`
	Processes MySQLProcesses `json:"processes"`
	GStatus   MySQLStatus    `json:"globalstatus"`
}

type MySQLStatus added in v0.2.1

type MySQLStatus map[string]interface{}

type NullString added in v0.2.1

type NullString struct {
	sql.NullString
}

func (NullString) MarshalJSON added in v0.2.1

func (n NullString) MarshalJSON() ([]byte, error)

MarshalJSON makes the output from sql.NullString not suck.

type NvidiaConfig added in v0.3.2

type NvidiaConfig struct {
	SMIPath  string   `json:"smiPath"  toml:"smi_path" xml:"smi_path"`
	BusIDs   []string `json:"busIDs"   toml:"bus_ids"  xml:"bus_id"`
	Disabled bool     `json:"disabled" toml:"disabled" xml:"disabled"`
}

NvidiaConfig is our input data.

func (*NvidiaConfig) HasID added in v0.3.2

func (n *NvidiaConfig) HasID(busID string) bool

HasID returns true if the ID is requested, or no IDs are filtered.

type NvidiaOutput added in v0.3.2

type NvidiaOutput struct {
	Name        string `json:"name"`
	Driver      string `json:"driverVersion"`
	Pstate      string `json:"pState"`
	Vbios       string `json:"vBios"`
	BusID       string `json:"busId"`
	Temperature int    `json:"temperature"`
	Utilization int    `json:"utiliization"`
	MemTotal    int    `json:"memTotal"`
	MemFree     int    `json:"memFree"`
}

NvidiaOutput is what we send to the website.

type Partition

type Partition struct {
	Device   string   `json:"name"`
	Total    uint64   `json:"total"`
	Free     uint64   `json:"free"`
	Used     uint64   `json:"used"`
	FSType   string   `json:"fsType,omitempty"`
	ReadOnly bool     `json:"readOnly,omitempty"`
	Opts     []string `json:"opts,omitempty"`
}

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

type Plugins added in v0.2.1

type Plugins struct {
	Nvidia *NvidiaConfig  `json:"nvidia" toml:"nvidia" xml:"nvidia"`
	MySQL  []*MySQLConfig `json:"mysql"  toml:"mysql"  xml:"mysql"`
}

Plugins is optional configuration for "plugins".

type Process added in v0.2.1

type Process struct {
	Name       string  `json:"name"`
	Pid        int32   `json:"pid"`
	MemPercent float32 `json:"memPercent"`
	CPUPercent float64 `json:"cpuPercent"`
}

Process is a PID's basic info.

type Processes added in v0.2.1

type Processes []*Process

Processes allows us to sort a process list.

func (Processes) Len added in v0.2.1

func (s Processes) Len() int

Len allows us to sort Processes.

func (Processes) Less added in v0.2.1

func (s Processes) Less(i, j int) bool

Less allows us to sort Processes.

func (*Processes) Shrink added in v0.2.1

func (s *Processes) Shrink(size int)

Shrink a process list.

func (Processes) Swap added in v0.2.1

func (s Processes) Swap(i, j int)

Swap allows us to sort Processes.

type RaidData

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

RaidData contains raid information from mdstat and/or megacli.

type Snapshot

type Snapshot struct {
	Debug   func(string, ...any) `json:"-"`
	Version string               `json:"version"`
	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
		CPUTime cpu.TimesStat `json:"cpuTime"`
	} `json:"system"`
	Raid       *RaidData                      `json:"raid,omitempty"`
	DriveAges  map[string]int                 `json:"driveAges,omitempty"`
	DriveTemps map[string]int                 `json:"driveTemps,omitempty"`
	DiskHealth map[string]string              `json:"driveHealth,omitempty"`
	DiskUsage  map[string]*Partition          `json:"diskUsage,omitempty"`
	Quotas     map[string]*Partition          `json:"quotas,omitempty"`
	ZFSPool    map[string]*Partition          `json:"zfsPools,omitempty"`
	IOTop      *IOTopData                     `json:"ioTop,omitempty"`
	IOStat     *IoStatDisks                   `json:"ioStat,omitempty"`
	IOStat2    map[string]disk.IOCountersStat `json:"ioStat2,omitempty"`
	Processes  Processes                      `json:"processes,omitempty"`
	MySQL      map[string]*MySQLServerData    `json:"mysql,omitempty"`
	Nvidia     []*NvidiaOutput                `json:"nvidia,omitempty"`
	Sensors    []*IPMISensor                  `json:"ipmiSensors"`
	Synology   *Synology                      `json:"synology,omitempty"`
}

Snapshot is the output data sent to Notifiarr.

func (*Snapshot) GetCPUSample

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

GetCPUSample gets a CPU percentage sample, CPU Times and Load Average.

func (*Snapshot) GetIPMI added in v0.5.0

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

GetIPMI grans basic sensor info.

func (*Snapshot) GetLocalData

func (s *Snapshot) GetLocalData(ctx context.Context) []error

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

func (*Snapshot) GetMemoryUsage

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

GetMemoryUsage returns current host memory consumption.

func (*Snapshot) GetMySQL added in v0.2.1

func (s *Snapshot) GetMySQL(ctx context.Context, servers []*MySQLConfig, limit int) []error

GetMySQL grabs the process list from a bunch of servers.

func (*Snapshot) GetNvidia added in v0.3.2

func (s *Snapshot) GetNvidia(ctx context.Context, config *NvidiaConfig) error

GetNvidia requires nvidia-smi executable and Nvidia drivers.

func (*Snapshot) GetProcesses added in v0.2.1

func (s *Snapshot) GetProcesses(ctx context.Context, count int) error

GetProcesses collects 'count' processes by CPU usage.

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
	HA      map[string]string `json:"ha"`
}

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

func GetSynology added in v0.2.0

func GetSynology(snapshot bool) (*Synology, error)

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

func (*Synology) SetInfo added in v0.2.0

func (s *Synology) SetInfo(hostInfo *host.InfoStat)

SetInfo writes synology data INTO the provided InfoStat.

Jump to

Keyboard shortcuts

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