Documentation
¶
Index ¶
- Constants
- Variables
- func CreateTable() error
- func Init()
- func InitDB(filepath string) (*sql.DB, error)
- func ReadStatsByDate(date string) (*[]TasksStats, *[]RaspberryStats, error)
- func ReadStatsByHour(date, hour string) (*[]TasksStats, *[]RaspberryStats, error)
- func StartLoop(stopSignal chan struct{})
- func StoreRStats(rs *RaspberryStats) error
- func StoreTStats(ts *TasksStats) error
- func UpdateRPiStats() error
- type HostStats
- type RAMStats
- type RaspberryStats
- type StorageStats
- type TasksStats
Constants ¶
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 ¶
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.
var DB *sql.DB
DB is the instance of the stats SQLite3 database.
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.
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.
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.
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.
var ErrNilDB = errors.New(
"Database error: database is nil",
)
ErrNilDB is the error used when the database returns nil
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 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.