collector

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: Apache-2.0 Imports: 27 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

func TagsFromGNMIPath added in v0.2.0

func TagsFromGNMIPath(p *gnmi.Path) (string, map[string]string)

TagsFromGNMIPath //

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(
	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) 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(ctx context.Context)

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(ctx context.Context, 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
	RetryTimer          time.Duration
}

Config is the collector config

type EventMsg added in v0.2.0

type EventMsg struct {
	Name      string                 `json:"name,omitempty"` // measurement name
	Timestamp int64                  `json:"timestamp,omitempty"`
	Tags      map[string]string      `json:"tags,omitempty"`
	Values    map[string]interface{} `json:"values,omitempty"`
	Deletes   []string               `json:"deletes,omitempty"`
}

EventMsg //

func ResponseToEventMsgs added in v0.2.0

func ResponseToEventMsgs(name string, rsp *gnmi.SubscribeResponse, meta map[string]string) ([]*EventMsg, error)

ResponseToEventMsgs //

type MarshalOptions added in v0.2.0

type MarshalOptions struct {
	Multiline bool // could get rid of this and deduct it from len(Indent)
	Indent    string
	Format    string
}

func (*MarshalOptions) FormatJSON added in v0.2.0

func (o *MarshalOptions) FormatJSON(m proto.Message, meta map[string]string) ([]byte, error)

FormatJSON formats a proto.Message and returns a []byte and an error

func (*MarshalOptions) Marshal added in v0.2.0

func (o *MarshalOptions) Marshal(msg proto.Message, meta map[string]string) ([]byte, error)

Marshal //

type NotificationRspMsg added in v0.2.0

type NotificationRspMsg struct {
	Meta             map[string]interface{} `json:"meta,omitempty"`
	Source           string                 `json:"source,omitempty"`
	SystemName       string                 `json:"system-name,omitempty"`
	SubscriptionName string                 `json:"subscription-name,omitempty"`
	Timestamp        int64                  `json:"timestamp,omitempty"`
	Time             *time.Time             `json:"time,omitempty"`
	Prefix           string                 `json:"prefix,omitempty"`
	Target           string                 `json:"target,omitempty"`
	Updates          []update               `json:"updates,omitempty"`
	Deletes          []string               `json:"deletes,omitempty"`
}

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 *TargetError
	// 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(rsp *gnmi.SubscribeResponse, 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"`
	RetryTimer    time.Duration `mapstructure:"retry,omitempty"`
}

TargetConfig //

func (*TargetConfig) String

func (tc *TargetConfig) String() string

type TargetError added in v0.2.3

type TargetError struct {
	SubscriptionName string
	Err              error
}

Jump to

Keyboard shortcuts

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