collector

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePrefix

func CreatePrefix(prefix, target string) (*gnmi.Path, error)

CreatePrefix //

func ParsePath

func ParsePath(p string) (*gnmi.Path, error)

ParsePath creates a gnmi.Path out of a p string, check if the first element is prefixed by an origin, removes it from the xpath and adds it to the returned gnmiPath

Types

type Collector

type Collector struct {
	Config        *Config
	Subscriptions map[string]*SubscriptionConfig
	Outputs       map[string][]outputs.Output
	DialOpts      []grpc.DialOption

	Targets map[string]*Target
	Logger  *log.Logger
	// contains filtered or unexported fields
}

Collector //

func NewCollector

func NewCollector(ctx context.Context,
	config *Config,
	targetConfigs map[string]*TargetConfig,
	subscriptions map[string]*SubscriptionConfig,
	outputs map[string][]outputs.Output,
	dialOpts []grpc.DialOption,
	logger *log.Logger,
) *Collector

NewCollector //

func (*Collector) FormatMsg

func (c *Collector) FormatMsg(meta map[string]interface{}, rsp *gnmi.SubscribeResponse) ([]byte, error)

FormatMsg formats the gnmi.SubscribeResponse and returns a []byte and an error

func (*Collector) InitTarget

func (c *Collector) InitTarget(tc *TargetConfig)

InitTarget initializes a target based on *TargetConfig

func (*Collector) PolledSubscriptionsTargets

func (c *Collector) PolledSubscriptionsTargets() map[string][]string

PolledSubscriptionsTargets returns a map of target name to a list of subscription names that have Mode == POLL

func (*Collector) Start

func (c *Collector) Start()

Start start the prometheus server as well as a goroutine per target selecting on the response chan, the error chan and the ctx.Done() chan

func (*Collector) Subscribe

func (c *Collector) Subscribe(tName string) error

Subscribe //

func (*Collector) TargetPoll

func (c *Collector) TargetPoll(targetName, subscriptionName string) (*gnmi.SubscribeResponse, error)

TargetPoll sends a gnmi.SubscribeRequest_Poll to targetName and returns the response and an error, it uses the targetName and the subscriptionName strings to find the gnmi.GNMI_SubscribeClient

type Config

type Config struct {
	PrometheusAddress   string
	Debug               bool
	Format              string
	TargetReceiveBuffer uint
}

Config is the collector config

type SubscribeResponse

type SubscribeResponse struct {
	SubscriptionName string
	Response         *gnmi.SubscribeResponse
}

SubscribeResponse //

type SubscriptionConfig

type SubscriptionConfig struct {
	Name              string         `mapstructure:"name,omitempty"`
	Models            []string       `mapstructure:"models,omitempty"`
	Prefix            string         `mapstructure:"prefix,omitempty"`
	Target            string         `mapstructure:"target,omitempty"`
	Paths             []string       `mapstructure:"paths,omitempty"`
	Mode              string         `mapstructure:"mode,omitempty"`
	StreamMode        string         `mapstructure:"stream-mode,omitempty"`
	Encoding          string         `mapstructure:"encoding,omitempty"`
	Qos               *uint32        `mapstructure:"qos,omitempty"`
	SampleInterval    *time.Duration `mapstructure:"sample-interval,omitempty"`
	HeartbeatInterval *time.Duration `mapstructure:"heartbeat-interval,omitempty"`
	SuppressRedundant bool           `mapstructure:"suppress-redundant,omitempty"`
	UpdatesOnly       bool           `mapstructure:"updates-only,omitempty"`
}

SubscriptionConfig //

func (*SubscriptionConfig) CreateSubscribeRequest

func (sc *SubscriptionConfig) CreateSubscribeRequest() (*gnmi.SubscribeRequest, error)

CreateSubscribeRequest validates the SubscriptionConfig and creates gnmi.SubscribeRequest

func (*SubscriptionConfig) String

func (sc *SubscriptionConfig) String() string

String //

type Target

type Target struct {
	Config        *TargetConfig
	Subscriptions []*SubscriptionConfig
	Outputs       []outputs.Output

	Client             gnmi.GNMIClient
	SubscribeClients   map[string]gnmi.GNMI_SubscribeClient // subscription name to subscribeClient
	PollChan           chan string                          // subscription name to be polled
	SubscribeResponses chan *SubscribeResponse
	Errors             chan error
	// contains filtered or unexported fields
}

Target represents a gNMI enabled box

func NewTarget

func NewTarget(c *TargetConfig) *Target

NewTarget //

func (*Target) Capabilities

func (t *Target) Capabilities(ctx context.Context, ext ...*gnmi_ext.Extension) (*gnmi.CapabilityResponse, error)

Capabilities sends a gnmi.CapabilitiesRequest to the target *t and returns a gnmi.CapabilitiesResponse and an error

func (*Target) CreateGNMIClient

func (t *Target) CreateGNMIClient(ctx context.Context, opts ...grpc.DialOption) error

CreateGNMIClient //

func (*Target) Export

func (t *Target) Export(msg []byte, m outputs.Meta)

Export //

func (*Target) Get

func (t *Target) Get(ctx context.Context, req *gnmi.GetRequest) (*gnmi.GetResponse, error)

Get sends a gnmi.GetRequest to the target *t and returns a gnmi.GetResponse and an error

func (*Target) Set

func (t *Target) Set(ctx context.Context, req *gnmi.SetRequest) (*gnmi.SetResponse, error)

Set sends a gnmi.SetRequest to the target *t and returns a gnmi.SetResponse and an error

func (*Target) Subscribe

func (t *Target) Subscribe(ctx context.Context, req *gnmi.SubscribeRequest, subscriptionName string)

Subscribe sends a gnmi.SubscribeRequest to the target *t, responses and error are sent to the target channels

type TargetConfig

type TargetConfig struct {
	Name          string        `mapstructure:"name,omitempty"`
	Address       string        `mapstructure:"address,omitempty"`
	Username      *string       `mapstructure:"username,omitempty"`
	Password      *string       `mapstructure:"password,omitempty"`
	Timeout       time.Duration `mapstructure:"timeout,omitempty"`
	Insecure      *bool         `mapstructure:"insecure,omitempty"`
	TLSCA         *string       `mapstructure:"tls-ca,omitempty"`
	TLSCert       *string       `mapstructure:"tls-cert,omitempty"`
	TLSKey        *string       `mapstructure:"tls-key,omitempty"`
	SkipVerify    *bool         `mapstructure:"skip-verify,omitempty"`
	Subscriptions []string      `mapstructure:"subscriptions,omitempty"`
	Outputs       []string      `mapstructure:"outputs,omitempty"`
	BufferSize    uint          `mapstructure:"buffer-size,omitempty"`
}

TargetConfig //

func (*TargetConfig) String

func (tc *TargetConfig) String() string

Jump to

Keyboard shortcuts

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