monitoring

package
v0.0.0-...-7578c0e Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LinkCPUPercent    = "cpu_usage_percent"
	LinkMemPercent    = "mem_usage_percent"
	LinkIOPercent     = "io_usage_percent"
	LinkNetPercentLan = "net_usage_percent_lan"
	LinkNetBPSLan     = "net_usage_bps_lan"
	LinkNetPercentWan = "net_usage_percent_wan"
	LinkNetBPSWan     = "net_usage_bps_wan"
)
View Source
const MaxDeletedEntries = 5000

MaxDeletedEntries to prevent "stop the world" after longer restart, when there is a lot of measurements to clean up clean them in chunks and this is the chunk size

Variables

View Source
var ClientGraphMetricsFields = map[string]map[string]bool{
	"graph-metrics": {
		"timestamp":            true,
		"cpu_usage_percent":    true,
		"memory_usage_percent": true,
		"io_usage_percent":     true,
	},
}
View Source
var ClientGraphMetricsFieldsDefault = map[string][]string{}
View Source
var ClientGraphMetricsFilterDefault = map[string][]string{}
View Source
var ClientGraphMetricsFilterFields = map[string]bool{
	"timestamp[gt]":    true,
	"timestamp[lt]":    true,
	"timestamp[since]": true,
	"timestamp[until]": true,
}
View Source
var ClientGraphMetricsSortDefault = map[string][]string{"sort": {"-timestamp"}}
View Source
var ClientGraphMetricsSortFields = map[string]bool{
	"timestamp": true,
}
View Source
var ClientGraphNameToAlias = map[string]string{
	"cpu_usage_percent":     "cpu_usage_percent",
	"mem_usage_percent":     "memory_usage_percent",
	"io_usage_percent":      "io_usage_percent",
	"net_usage_percent_lan": "net_usage_percent_lan_in",
	"net_usage_percent_wan": "net_usage_percent_wan_in",
	"net_usage_bps_lan":     "net_usage_bps_lan_in",
	"net_usage_bps_wan":     "net_usage_bps_wan_in",
}
View Source
var ClientGraphNameToField = map[string]string{
	"cpu_usage_percent":     "cpu_usage_percent",
	"mem_usage_percent":     "memory_usage_percent",
	"io_usage_percent":      "io_usage_percent",
	"net_usage_percent_lan": "net_lan_in",
	"net_usage_percent_wan": "net_wan_in",
	"net_usage_bps_lan":     "net_lan_in",
	"net_usage_bps_wan":     "net_wan_in",
}
View Source
var ClientMetricsFields = map[string]map[string]bool{
	"metrics": {
		"timestamp":            true,
		"cpu_usage_percent":    true,
		"memory_usage_percent": true,
		"io_usage_percent":     true,
	},
}
View Source
var ClientMetricsFieldsDefault = map[string][]string{"fields[metrics]": {"timestamp", "cpu_usage_percent", "memory_usage_percent", "io_usage_percent"}}
View Source
var ClientMetricsFilterDefault = map[string][]string{}
View Source
var ClientMetricsFilterFields = map[string]bool{
	"timestamp[gt]":    true,
	"timestamp[lt]":    true,
	"timestamp[since]": true,
	"timestamp[until]": true,
}
View Source
var ClientMetricsSortDefault = map[string][]string{"sort": {"-timestamp"}}
View Source
var ClientMetricsSortFields = map[string]bool{
	"timestamp": true,
}
View Source
var ClientMountpointsFields = map[string]map[string]bool{
	"mountpoints": {
		"timestamp":   true,
		"mountpoints": true,
	},
}
View Source
var ClientMountpointsFieldsDefault = map[string][]string{"fields[mountpoints]": {"timestamp", "mountpoints"}}
View Source
var ClientMountpointsFilterDefault = map[string][]string{}
View Source
var ClientMountpointsFilterFields = map[string]bool{
	"timestamp[gt]":    true,
	"timestamp[lt]":    true,
	"timestamp[since]": true,
	"timestamp[until]": true,
}
View Source
var ClientMountpointsSortDefault = map[string][]string{"sort": {"-timestamp"}}
View Source
var ClientMountpointsSortFields = map[string]bool{
	"timestamp": true,
}
View Source
var ClientProcessesFields = map[string]map[string]bool{
	"processes": {
		"timestamp": true,
		"processes": true,
	},
}
View Source
var ClientProcessesFieldsDefault = map[string][]string{"fields[processes]": {"timestamp", "processes"}}
View Source
var ClientProcessesFilterDefault = map[string][]string{}
View Source
var ClientProcessesFilterFields = map[string]bool{
	"timestamp[gt]":    true,
	"timestamp[lt]":    true,
	"timestamp[since]": true,
	"timestamp[until]": true,
}
View Source
var ClientProcessesSortDefault = map[string][]string{"sort": {"-timestamp"}}
View Source
var ClientProcessesSortFields = map[string]bool{
	"timestamp": true,
}

Functions

func NewGraphMetricsLink(requestInfo *query.RequestInfo, target string) *string

Types

type CPUUsagePercent

type CPUUsagePercent struct {
	Avg float64 `json:"avg,omitempty" db:"cpu_usage_percent_avg"`
	Min float64 `json:"min,omitempty" db:"cpu_usage_percent_min"`
	Max float64 `json:"max,omitempty" db:"cpu_usage_percent_max"`
}

type CleanupTask

type CleanupTask struct {
	// contains filtered or unexported fields
}

func NewCleanupTask

func NewCleanupTask(log *logger.Logger, service Service, duration time.Duration) *CleanupTask

NewCleanupTask returns a task to cleanup monitoring data after configured period

func (*CleanupTask) Run

func (t *CleanupTask) Run(ctx context.Context) error

type ClientGraphMetricsGraphPayload

type ClientGraphMetricsGraphPayload struct {
	Timestamp           time.Time `json:"timestamp,omitempty" db:"timestamp"`
	*CPUUsagePercent    `json:"cpu_usage_percent,omitempty"`
	*MemoryUsagePercent `json:"memory_usage_percent,omitempty"`
	*IOUsagePercent     `json:"io_usage_percent,omitempty"`
	*NetUsagePercentLan `json:"net_usage_percent_lan,omitempty"`
	*NetUsagePercentWan `json:"net_usage_percent_wan,omitempty"`
	*NetUsageBPSLan     `json:"net_usage_bps_lan,omitempty"`
	*NetUsageBPSWan     `json:"net_usage_bps_wan,omitempty"`
}

type ClientGraphMetricsPayload

type ClientGraphMetricsPayload struct {
	Timestamp          time.Time `json:"timestamp,omitempty" db:"timestamp"`
	CPUUsagePercent    `json:"cpu_usage_percent,omitempty"`
	MemoryUsagePercent `json:"memory_usage_percent,omitempty"`
	IOUsagePercent     `json:"io_usage_percent,omitempty"`
}

type ClientMetricsPayload

type ClientMetricsPayload struct {
	Timestamp          time.Time `json:"timestamp,omitempty" db:"timestamp"`
	CPUUsagePercent    float64   `json:"cpu_usage_percent" db:"cpu_usage_percent"`
	MemoryUsagePercent float64   `json:"memory_usage_percent" db:"memory_usage_percent"`
	IOUsagePercent     float64   `json:"io_usage_percent" db:"io_usage_percent"`
}

type ClientMountpointsPayload

type ClientMountpointsPayload struct {
	Timestamp   time.Time        `json:"timestamp" db:"timestamp"`
	Mountpoints types.JSONString `json:"mountpoints" db:"mountpoints"`
}

type ClientProcessesPayload

type ClientProcessesPayload struct {
	Timestamp time.Time        `json:"timestamp" db:"timestamp"`
	Processes types.JSONString `json:"processes" db:"processes"`
}

type DBProvider

type DBProvider interface {
	CreateMeasurement(ctx context.Context, measurement *models.Measurement) error
	DeleteMeasurementsBefore(ctx context.Context, compare time.Time) (int64, error)
	ListGraphByClientID(context.Context, string, float64, *query.ListOptions, string) ([]*ClientGraphMetricsGraphPayload, error)
	ListGraphMetricsByClientID(context.Context, string, float64, *query.ListOptions) ([]*ClientGraphMetricsPayload, error)
	ListMetricsByClientID(context.Context, string, *query.ListOptions) ([]*ClientMetricsPayload, error)
	ListMountpointsByClientID(context.Context, string, *query.ListOptions) ([]*ClientMountpointsPayload, error)
	ListProcessesByClientID(context.Context, string, *query.ListOptions) ([]*ClientProcessesPayload, error)
	CountByClientID(context.Context, string, *query.ListOptions) (int, error)
	Close() error
}

func NewSqliteProvider

func NewSqliteProvider(dbPath string, dataSourceOptions sqlite.DataSourceOptions, logger *logger.Logger) (DBProvider, error)

type DBProviderMock

type DBProviderMock struct {
	GraphMetricsListPayload      []*ClientGraphMetricsPayload
	GraphMetricsGraphListPayload []*ClientGraphMetricsGraphPayload
	MetricsListPayload           []*ClientMetricsPayload
	ProcessesListPayload         []*ClientProcessesPayload
	MountpointsListPayload       []*ClientMountpointsPayload
}

func (*DBProviderMock) Close

func (p *DBProviderMock) Close() error

func (*DBProviderMock) CountByClientID

func (p *DBProviderMock) CountByClientID(ctx context.Context, clientID string, fo *query.ListOptions) (int, error)

func (*DBProviderMock) CreateMeasurement

func (p *DBProviderMock) CreateMeasurement(ctx context.Context, measurement *models.Measurement) error

func (*DBProviderMock) DB

func (p *DBProviderMock) DB() *sqlx.DB

func (*DBProviderMock) DeleteMeasurementsBefore

func (p *DBProviderMock) DeleteMeasurementsBefore(ctx context.Context, compare time.Time) (int64, error)

func (*DBProviderMock) ListGraphMetricsByClientID

func (p *DBProviderMock) ListGraphMetricsByClientID(ctx context.Context, clientID string, hours float64, o *query.ListOptions) ([]*ClientGraphMetricsPayload, error)

func (*DBProviderMock) ListMetricsByClientID

func (p *DBProviderMock) ListMetricsByClientID(ctx context.Context, clientID string, o *query.ListOptions) ([]*ClientMetricsPayload, error)

func (*DBProviderMock) ListMountpointsByClientID

func (p *DBProviderMock) ListMountpointsByClientID(ctx context.Context, clientID string, o *query.ListOptions) ([]*ClientMountpointsPayload, error)

func (*DBProviderMock) ListProcessesByClientID

func (p *DBProviderMock) ListProcessesByClientID(ctx context.Context, clientID string, fo *query.ListOptions) ([]*ClientProcessesPayload, error)

type GraphMetricsLinksPayload

type GraphMetricsLinksPayload struct {
	CPUUsagePercent    *string `json:"cpu_usage_percent,omitempty"`
	MemUsagePercent    *string `json:"mem_usage_percent,omitempty"`
	IOUsagePercent     *string `json:"io_usage_percent,omitempty"`
	NetLanUsagePercent *string `json:"net_usage_percent_lan,omitempty"`
	NetWanUsagePercent *string `json:"net_usage_percent_wan,omitempty"`
	NetLanUsageBPS     *string `json:"net_usage_bps_lan,omitempty"`
	NetWanUsageBPS     *string `json:"net_usage_bps_wan,omitempty"`
}

type IOUsagePercent

type IOUsagePercent struct {
	Avg float64 `json:"avg,omitempty" db:"io_usage_percent_avg"`
	Min float64 `json:"min,omitempty" db:"io_usage_percent_min"`
	Max float64 `json:"max,omitempty" db:"io_usage_percent_max"`
}

type MeasurementSaver

type MeasurementSaver interface {
	Notify(models.Measurement) bool
	Close() error
}

func NewMeasurementQueuing

func NewMeasurementQueuing(logger *logger.Logger, saver saver, queueSize int) MeasurementSaver

type MemoryUsagePercent

type MemoryUsagePercent struct {
	Avg float64 `json:"avg,omitempty" db:"memory_usage_percent_avg"`
	Min float64 `json:"min,omitempty" db:"memory_usage_percent_min"`
	Max float64 `json:"max,omitempty" db:"memory_usage_percent_max"`
}

type NetUsageBPSLan

type NetUsageBPSLan struct {
	InAvg  *float64 `json:"in_avg,omitempty" db:"net_usage_bps_lan_in_avg"`
	InMin  *float64 `json:"in_min,omitempty" db:"net_usage_bps_lan_in_min"`
	InMax  *float64 `json:"in_max,omitempty" db:"net_usage_bps_lan_in_max"`
	OutAvg *float64 `json:"out_avg,omitempty" db:"net_usage_bps_lan_out_avg"`
	OutMin *float64 `json:"out_min,omitempty" db:"net_usage_bps_lan_out_min"`
	OutMax *float64 `json:"out_max,omitempty" db:"net_usage_bps_lan_out_max"`
}

type NetUsageBPSWan

type NetUsageBPSWan struct {
	InAvg  *float64 `json:"in_avg,omitempty" db:"net_usage_bps_wan_in_avg"`
	InMin  *float64 `json:"in_min,omitempty" db:"net_usage_bps_wan_in_min"`
	InMax  *float64 `json:"in_max,omitempty" db:"net_usage_bps_wan_in_max"`
	OutAvg *float64 `json:"out_avg,omitempty" db:"net_usage_bps_wan_out_avg"`
	OutMin *float64 `json:"out_min,omitempty" db:"net_usage_bps_wan_out_min"`
	OutMax *float64 `json:"out_max,omitempty" db:"net_usage_bps_wan_out_max"`
}

type NetUsagePercentLan

type NetUsagePercentLan struct {
	InAvg  *float64 `json:"in_avg,omitempty" db:"net_usage_percent_lan_in_avg"`
	InMin  *float64 `json:"in_min,omitempty" db:"net_usage_percent_lan_in_min"`
	InMax  *float64 `json:"in_max,omitempty" db:"net_usage_percent_lan_in_max"`
	OutAvg *float64 `json:"out_avg,omitempty" db:"net_usage_percent_lan_out_avg"`
	OutMin *float64 `json:"out_min,omitempty" db:"net_usage_percent_lan_out_min"`
	OutMax *float64 `json:"out_max,omitempty" db:"net_usage_percent_lan_out_max"`
}

type NetUsagePercentWan

type NetUsagePercentWan struct {
	InAvg  *float64 `json:"in_avg,omitempty" db:"net_usage_percent_wan_in_avg"`
	InMin  *float64 `json:"in_min,omitempty" db:"net_usage_percent_wan_in_min"`
	InMax  *float64 `json:"in_max,omitempty" db:"net_usage_percent_wan_in_max"`
	OutAvg *float64 `json:"out_avg,omitempty" db:"net_usage_percent_wan_out_avg"`
	OutMin *float64 `json:"out_min,omitempty" db:"net_usage_percent_wan_out_min"`
	OutMax *float64 `json:"out_max,omitempty" db:"net_usage_percent_wan_out_max"`
}

type Service

type Service interface {
	SaveMeasurementUpdateTimestamp(ctx context.Context, measurement *models.Measurement) error
	SaveMeasurement(ctx context.Context, measurement *models.Measurement) error
	DeleteMeasurementsOlderThan(ctx context.Context, period time.Duration) (int64, error)
	ListClientMetrics(context.Context, string, *query.ListOptions) (*api.SuccessPayload, error)
	ListClientGraph(context.Context, string, *query.ListOptions, string, *models.NetworkCard, *models.NetworkCard) (*api.SuccessPayload, error)
	ListClientGraphMetrics(context.Context, string, *query.ListOptions, *query.RequestInfo, bool, bool) (*api.SuccessPayload, error)
	ListClientMountpoints(context.Context, string, *query.ListOptions) (*api.SuccessPayload, error)
	ListClientProcesses(context.Context, string, *query.ListOptions) (*api.SuccessPayload, error)
}

func NewService

func NewService(dbProvider DBProvider, l *logger.Logger) Service

type SqliteProvider

type SqliteProvider struct {
	// contains filtered or unexported fields
}

func (*SqliteProvider) Close

func (p *SqliteProvider) Close() error

func (*SqliteProvider) CountByClientID

func (p *SqliteProvider) CountByClientID(ctx context.Context, clientID string, options *query.ListOptions) (int, error)

func (*SqliteProvider) CreateMeasurement

func (p *SqliteProvider) CreateMeasurement(ctx context.Context, measurement *models.Measurement) error

func (*SqliteProvider) DeleteMeasurementsBefore

func (p *SqliteProvider) DeleteMeasurementsBefore(ctx context.Context, compare time.Time) (int64, error)

DeleteMeasurementsBefore deletes entries in chunks of MaxDeletedEntries to clean all you can run in loop as long as there are more than 0 rows affected

func (*SqliteProvider) ListGraphByClientID

func (p *SqliteProvider) ListGraphByClientID(ctx context.Context, clientID string, hours float64, lo *query.ListOptions, graph string) ([]*ClientGraphMetricsGraphPayload, error)

func (*SqliteProvider) ListGraphMetricsByClientID

func (p *SqliteProvider) ListGraphMetricsByClientID(ctx context.Context, clientID string, hours float64, lo *query.ListOptions) ([]*ClientGraphMetricsPayload, error)

func (*SqliteProvider) ListMetricsByClientID

func (p *SqliteProvider) ListMetricsByClientID(ctx context.Context, clientID string, o *query.ListOptions) ([]*ClientMetricsPayload, error)

func (*SqliteProvider) ListMountpointsByClientID

func (p *SqliteProvider) ListMountpointsByClientID(ctx context.Context, clientID string, o *query.ListOptions) ([]*ClientMountpointsPayload, error)

func (*SqliteProvider) ListProcessesByClientID

func (p *SqliteProvider) ListProcessesByClientID(ctx context.Context, clientID string, o *query.ListOptions) ([]*ClientProcessesPayload, error)

Jump to

Keyboard shortcuts

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