stats

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatabaseName is the name of the sqlite3 database used for storage of some statistics
	DatabaseName = "stats.db"

	// StatisticsPath is the path where the stats will be saved.
	StatisticsPath = "./statistics/"
)

Variables

View Source
var Current = struct {
	TasksStats     TasksStats
	RaspberryStats RaspberryStats
	sync.RWMutex
}{}

Current is the variable that holds the different statistics of the tasks's execution and the Raspberry Pi running PiWorker.

View Source
var DB *sql.DB

DB is the instance of the stats SQLite3 database.

View Source
var ErrBadCPULoadParse = errors.New(
	"Falied CPU load parsing: can't locate the values",
)

ErrBadCPULoadParse is the error used when the CPU load can't be parsed.

View Source
var ErrBadFreeStorageParse = errors.New(
	"Falied Free Storage parsing:  can't locate the value",
)

ErrBadFreeStorageParse is the error used when the Free Storage can't be parsed.

View Source
var ErrBadRAMUsageParse = errors.New(
	"Falied RAM usage parsing: can't locate the value",
)

ErrBadRAMUsageParse is the error used whem the RAM usage can't be parsed.

View Source
var ErrBadTemperatureParse = errors.New(
	"Failed temperature parsing: can't locate the temperature",
)

ErrBadTemperatureParse is the error used when the temperature of the Raspberry Pi can't be parsed.

View Source
var ErrNilDB = errors.New(
	"Database error: database is nil",
)

ErrNilDB is the error used when the database returns nil

View Source
var WSConns = struct {
	N uint8
	sync.RWMutex
}{}

WSConns (WebSocket connections) contains a real-time counter of the amount of users with an active websocket connection.

Functions

func CreateTable

func CreateTable() error

CreateTable is the function used to create the default tables into the SQLite3 database.

func Init

func Init()

Init initializes the directory where the statistics will be stored (if not exists).

func InitDB

func InitDB(filepath string) (*sql.DB, error)

InitDB is the function used to initialize the sqlite3 database.

func ReadStatsByDate

func ReadStatsByDate(date string) (*[]TasksStats, *[]RaspberryStats, error)

ReadStatsByDate returns the statistics of a specific date.

func ReadStatsByHour

func ReadStatsByHour(date, hour string) (*[]TasksStats, *[]RaspberryStats, error)

ReadStatsByHour returns the statistics of a specific date and hour.

func StartLoop

func StartLoop(stopSignal chan struct{})

StartLoop is the function used to start the loop used to work with the statistics generated by PiWorker and the Raspberry Pi where it's running. Returns the instance of the database with the purpose of be closed properly.

func StoreRStats

func StoreRStats(rs *RaspberryStats) error

StoreRStats stores a instance of the struct `RaspberryStats` into the table `RaspberryStats` of the SQLite3 database.

func StoreTStats

func StoreTStats(ts *TasksStats) error

StoreTStats stores a instance of the struct `TasksStats` into the table `TasksStats` of the SQLite3 database.

func UpdateRPiStats

func UpdateRPiStats() error

UpdateRPiStats is a function update the statistics related with the host (usually a Raspberry Pi), on the variable `Current`.

Types

type HostStats

type HostStats struct {
	BootTime    uint64  `json:"bootTime"`
	UpTime      uint64  `json:"uptime"`
	Temperature float64 `json:"temperature"`
}

HostStats is the struct used to parse some additional statistics about the Host.

type RAMStats

type RAMStats struct {
	Total     uint64 `json:"total"`
	Available uint64 `json:"available"`
	Used      uint64 `json:"used"`
}

RAMStats is the struct used to parse the statistics related with the RAM of the Host.

type RaspberryStats

type RaspberryStats struct {
	Host      HostStats    `json:"hostStats"`
	CPULoad   float64      `json:"cpuLoad"`
	Storage   StorageStats `json:"storage"`
	RAM       RAMStats     `json:"ram"`
	Timestamp time.Time    `json:"timestamp"`
}

RaspberryStats is the struct that contains the statistics related with the Host (generally it will be a Raspberry Pi).

type StorageStats

type StorageStats struct {
	Total       uint64  `json:"total"`
	Free        uint64  `json:"free"`
	Used        uint64  `json:"used"`
	UsedPercent float64 `json:"usedPercent"`
}

StorageStats is the struct used to parse storage stats of the Host.

type TasksStats

type TasksStats struct {
	// PiWorker stats
	ActiveTasks          uint16        `json:"activeTasks"`
	InactiveTasks        uint16        `json:"inactiveTasks"`
	OnExecutionTasks     uint8         `json:"onExecutionTasks"`
	FailedTasks          uint8         `json:"failedTasks"`
	AverageExecutionTime time.Duration `json:"averageExecutionTime"`
	BackupLoopState      bool          `json:"backupLoopState"`
	Timestamp            time.Time     `json:"timestamp"`
	// contains filtered or unexported fields
}

TasksStats is the struct used to parse each statistic related with the tasks.

func (*TasksStats) NewAvgObs

func (s *TasksStats) NewAvgObs(duration time.Duration) time.Duration

NewAvgObs is a method with the purpose of add new data to be calculated into the `Statistic.AverageExecutionTime` field.

Jump to

Keyboard shortcuts

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