snapshot

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 31 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.

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.

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

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout   cnfg.Duration `toml:"timeout" xml:"timeout" json:"timeout"`                           // total run time allowed.
	Interval  cnfg.Duration `toml:"interval" xml:"interval" json:"interval"`                        // how often to send snaps (cron).
	ZFSPools  []string      `toml:"zfs_pools" xml:"zfs_pool" json:"zfsPools"`                       // zfs pools to monitor.
	UseSudo   bool          `toml:"use_sudo" xml:"use_sudo" json:"useSudo"`                         // use sudo for smartctl commands.
	Raid      bool          `toml:"monitor_raid" xml:"monitor_raid" json:"monitorRaid"`             // include mdstat and/or megaraid.
	DriveData bool          `toml:"monitor_drives" xml:"monitor_drives" json:"monitorDrives"`       // smartctl commands.
	DiskUsage bool          `toml:"monitor_space" xml:"monitor_space" json:"monitorSpace"`          // get disk usage.
	AllDrives bool          `toml:"all_drives" xml:"all_drives" json:"allDrives"`                   // usage for all drives?
	Uptime    bool          `toml:"monitor_uptime" xml:"monitor_uptime" json:"monitorUptime"`       // all system stats.
	CPUMem    bool          `toml:"monitor_cpuMemory" xml:"monitor_cpuMemory" json:"monitorCpuMem"` // cpu perct and memory used/free.
	CPUTemp   bool          `toml:"monitor_cpuTemp" xml:"monitor_cpuTemp" json:"monitorCpuTemp"`    // not everything supports temps.
	IOTop     int           `toml:"iotop" xml:"iotop" json:"ioTop"`                                 // number of processes to include from ioTop
	PSTop     int           `toml:"pstop" xml:"pstop" json:"psTop"`                                 // number of processes to include from top (cpu usage)
	MyTop     int           `toml:"mytop" xml:"mytop" json:"myTop"`                                 // number of processes to include from mysql servers.
	*Plugins
}

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 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 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 MySQLConfig added in v0.2.1

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

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"`
}

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 Partition

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

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

type Plugins added in v0.2.1

type Plugins struct {
	MySQL []*MySQLConfig `toml:"mysql" xml:"mysql" json:"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 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
		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"`
	DiskUsage  map[string]*Partition          `json:"diskUsage,omitempty"`
	DiskHealth map[string]string              `json:"driveHealth,omitempty"`
	IOTop      *IOTopData                     `json:"ioTop,omitempty"`
	IOStat     *IoStatDisks                   `json:"ioStat,omitempty"`
	IOStat2    map[string]disk.IOCountersStat `json:"ioStat2,omitempty"`
	Processes  Processes                      `json:"processes,omitempty"`
	ZFSPool    map[string]*Partition          `json:"zfsPools,omitempty"`
	MySQL      map[string]*MySQLServerData    `json:"mysql,omitempty"`
}

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, CPU Times and Load Average.

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) GetMySQL added in v0.2.1

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

GetMySQL grabs the process list from a bunch of servers.

func (*Snapshot) GetProcesses added in v0.2.1

func (s *Snapshot) GetProcesses(ctx context.Context, count int) (errs []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
}

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

func GetSynology added in v0.2.0

func GetSynology(run 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(hi *host.InfoStat)

Jump to

Keyboard shortcuts

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