Files
nmon/internal/groups/service.go

58 lines
1.8 KiB
Go

package groups
import (
"context"
"time"
"github.com/v10networks/nmon/internal/clock"
"github.com/v10networks/nmon/internal/p95"
"github.com/v10networks/nmon/internal/store"
)
// Inventory is the part of the inventory database this package reads.
// store.Store implements it.
type Inventory interface {
GetGroup(ctx context.Context, id int64) (*store.GroupRef, error)
ListGroups(ctx context.Context) ([]store.Group, error)
GroupMembers(ctx context.Context, groupID int64, from, to time.Time) ([]store.GroupMember, error)
GetInterface(ctx context.Context, id string) (*store.Interface, error)
}
// Relation maps interface IDs to a related interface ID.
type Relation func(ctx context.Context, ifaceIDs []string) (map[string]string, error)
// Options configures a Service.
type Options struct {
Query p95.Querier
Inventory Inventory
// Zone is the timezone of group months. A group spans devices and so
// sites; it uses the site default, not a member's override.
Zone *time.Location
// LagParent maps a LAG member interface to its LAG interface. Nothing
// collects ifStackTable yet, so until discovery supplies this, nil means
// "no LAG relations known" and no member is ever dropped as a LAG duplicate.
LagParent Relation
// LinkPeer maps an interface to the interface at the other end of its
// link. LLDP neighbours are not in the inventory yet; nil means none known
// and no group is ever flagged as mixing both ends of a link.
LinkPeer Relation
Clock clock.Clock
}
// Service computes group traffic.
type Service struct {
o Options
rd *p95.Reader
}
// NewService returns a Service.
func NewService(o Options) *Service {
if o.Clock == nil {
o.Clock = clock.Real()
}
if o.Zone == nil {
o.Zone = time.UTC
}
return &Service{o: o, rd: p95.NewReader(o.Query)}
}