knx

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const GroupRead = ReadType("GroupRead")
View Source
const InvalidGroupAddress = GroupAddress(0)

InvalidGroupAddress defines the nil group address.

View Source
const InvalidPhysicalAddress = PhysicalAddress(0)
View Source
const Router = ConnectionType("Router")
View Source
const Tunnel = ConnectionType("Tunnel")
View Source
const WriteOther = ReadType("WriteOther")

Variables

This section is empty.

Functions

func ConvertGroupAddresses

func ConvertGroupAddresses(src string, target string) error

Types

type Config

type Config struct {
	Connection Connection `json:",omitempty"`
	// MetricsPrefix is a short prefix which will be added in front of the actual metric name.
	MetricsPrefix  string
	AddressConfigs GroupAddressConfigSet
	// ReadStartupInterval is the intervall to wait between read of group addresses after startup.
	ReadStartupInterval Duration `json:",omitempty"`
}

Config defines the structure of the configuration file which defines which KNX Group Addresses were mapped into prometheus metrics.

func ReadConfig added in v0.2.0

func ReadConfig(configFile string) (*Config, error)

ReadConfig reads the given configuration file and returns the parsed Config object.

func (*Config) NameFor

func (c *Config) NameFor(gaConfig *GroupAddressConfig) string

NameFor return s the full metric name for the given GroupAddressConfig.

func (*Config) NameForGa

func (c *Config) NameForGa(address GroupAddress) string

NameForGa returns the full metric name for the given GroupAddress.

type Connection

type Connection struct {
	// Type of the actual connection. Can be either Tunnel or Router
	Type ConnectionType
	// Endpoint defines the IP address or hostname and port to where it should connect.
	Endpoint string
	// PhysicalAddress defines how the knx-exporter should identify itself within the KNX system.
	PhysicalAddress PhysicalAddress
	// RouterConfig contains some the specific configurations if connection Type is Router
	RouterConfig RouterConfig
	// TunnelConfig contains some the specific configurations if connection Type is Tunnel
	TunnelConfig TunnelConfig
}

Connection contains the information about how to connect to the KNX system and how to identify itself.

type ConnectionType

type ConnectionType string

func (ConnectionType) MarshalJSON

func (t ConnectionType) MarshalJSON() ([]byte, error)

func (*ConnectionType) UnmarshalJSON

func (t *ConnectionType) UnmarshalJSON(data []byte) error

type DPT

type DPT interface {
	Pack() []byte
	Unpack(data []byte) error
	Unit() string
	String() string
}

DPT is wrapper interface for all types under github.com/vapourismo/knx-go/knx/dpt to simplifies working with them.

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

type GroupAddress

type GroupAddress cemi.GroupAddr

GroupAddress defines a single group address. It do not contain any additional information about purpose, data types or allowed telegram types.

func NewGroupAddress

func NewGroupAddress(str string) (GroupAddress, error)

NewGroupAddress creates a new GroupAddress by parsing the given string. It either returns the parsed GroupAddress or an error if it is not possible to parse the string.

func (GroupAddress) MarshalJSON

func (g GroupAddress) MarshalJSON() ([]byte, error)

func (GroupAddress) MarshalText

func (g GroupAddress) MarshalText() ([]byte, error)

func (GroupAddress) String

func (g GroupAddress) String() string

func (*GroupAddress) UnmarshalJSON

func (g *GroupAddress) UnmarshalJSON(data []byte) error

func (*GroupAddress) UnmarshalText

func (g *GroupAddress) UnmarshalText(data []byte) error

type GroupAddressConfig

type GroupAddressConfig struct {
	// Name defines the prometheus metric name without the MetricsPrefix.
	Name string
	// Comment to identify the group address.
	Comment string `json:",omitempty"`
	// DPT defines the DPT at the knx bus. This is required to parse the values correctly.
	DPT string
	// MetricType is the type that prometheus uses when exporting it. i.e. gauge or counter
	MetricType string
	// Export the metric to prometheus
	Export bool
	// ReadStartup allows the exporter to actively send `GroupValueRead` telegrams to actively read the value at startup instead waiting for it.
	ReadStartup bool `json:",omitempty"`
	// ReadActive allows the exporter to actively send `GroupValueRead` telegrams to actively poll the value instead waiting for it.
	ReadActive bool `json:",omitempty"`
	// ReadType defines the type how to trigger the read request. Possible Values are GroupRead and WriteOther.
	ReadType ReadType `json:",omitempty"`
	// ReadAddress defines the group address to which address a GroupWrite request should be sent to initiate sending the data if ReadType is set to WriteOther.
	ReadAddress GroupAddress `json:",omitempty"`
	// ReadBody is a byte array with the content to sent to ReadAddress if ReadType is set to WriteOther.
	ReadBody []byte `json:",omitempty"`
	// MaxAge of a value until it will actively send a `GroupValueRead` telegram to read the value if ReadActive is set to true.
	MaxAge Duration `json:",omitempty"`
	// Labels defines static labels that should be set when exporting the metric using prometheus.
	Labels map[string]string `json:",omitempty"`
}

GroupAddressConfig defines all information to map a KNX group address to a prometheus metric.

type GroupAddressConfigSet

type GroupAddressConfigSet map[GroupAddress]*GroupAddressConfig

GroupAddressConfigSet is a shortcut type for the group address config map.

type GroupClient

type GroupClient interface {
	Send(event knx.GroupEvent) error
	Inbound() <-chan knx.GroupEvent
	Close()
}

GroupClient is a super interface for the knx.GroupClient interface to also export the Close() function.

type Listener added in v0.2.0

type Listener interface {
	Run()
	IsActive() bool
}

func NewListener added in v0.2.0

func NewListener(config *Config, inbound <-chan knx.GroupEvent, metricsChan chan *Snapshot, messageCounter *prometheus.CounterVec) Listener

type MetricSnapshotHandler added in v0.2.0

type MetricSnapshotHandler interface {
	// AddSnapshot adds a new snapshot that should be exported as metric.
	AddSnapshot(snapshot *Snapshot)
	// FindSnapshot finds a given snapshot by the snapshots key.
	FindSnapshot(key SnapshotKey) (*Snapshot, error)
	// FindYoungestSnapshot finds the youngest snapshot with the given metric name.
	// It don't matter from which device the snapshot was received.
	FindYoungestSnapshot(name string) *Snapshot
	// GetValueFunc returns a function that returns the current value for the given snapshot key.
	GetValueFunc(key SnapshotKey) func() float64
	// Run let the MetricSnapshotHandler listen for new snapshots on the Snapshot channel.
	Run()
	// GetMetricsChannel returns the channel to send new snapshots to this MetricSnapshotHandler.
	GetMetricsChannel() chan *Snapshot
	// Close stops listening for new Snapshots and closes the Snapshot channel.
	Close()
	// IsActive indicates that this handler is active and waits for new metric snapshots
	IsActive() bool
}

MetricSnapshotHandler holds and manages all the snapshots of metrics.

func NewMetricsSnapshotHandler added in v0.2.0

func NewMetricsSnapshotHandler(registerer prometheus.Registerer) MetricSnapshotHandler

type MetricsExporter

type MetricsExporter interface {
	Run() error
	Close()
	IsAlive() error
}

func NewMetricsExporter

func NewMetricsExporter(configFile string, registerer prometheus.Registerer) (MetricsExporter, error)

type PhysicalAddress

type PhysicalAddress cemi.IndividualAddr

PhysicalAddress defines an individual address of a knx device.

func NewPhysicalAddress

func NewPhysicalAddress(str string) (PhysicalAddress, error)

NewPhysicalAddress creates a new knx device PhysicalAddress by parsing the given string. It either returns the parsed PhysicalAddress or an error if it is not possible to parse the string.

func (PhysicalAddress) MarshalJSON

func (g PhysicalAddress) MarshalJSON() ([]byte, error)

func (PhysicalAddress) MarshalText

func (g PhysicalAddress) MarshalText() ([]byte, error)

func (PhysicalAddress) String

func (g PhysicalAddress) String() string

func (*PhysicalAddress) UnmarshalJSON

func (g *PhysicalAddress) UnmarshalJSON(data []byte) error

func (*PhysicalAddress) UnmarshalText

func (g *PhysicalAddress) UnmarshalText(data []byte) error

type Poller

type Poller interface {
	// Run starts the polling.
	Run()
	// Close stops the polling.
	Close()
}

Poller defines the interface for active polling for metrics values against the knx system.

func NewPoller

func NewPoller(config *Config, client GroupClient, metricsHandler MetricSnapshotHandler, messageCounter *prometheus.CounterVec) Poller

NewPoller creates a new Poller instance using the given MetricsExporter for connection handling and metrics observing.

type ReadType added in v1.1.0

type ReadType string

func (ReadType) MarshalJSON added in v1.1.0

func (t ReadType) MarshalJSON() ([]byte, error)

func (*ReadType) UnmarshalJSON added in v1.1.0

func (t *ReadType) UnmarshalJSON(data []byte) error

type RouterConfig added in v1.0.0

type RouterConfig struct {
	// RetainCount specifies how many sent messages to retain. This is important for when a router indicates that it has
	// lost some messages. If you do not expect to saturate the router, keep this low.
	RetainCount uint
	// Interface specifies the network interface used to send and receive KNXnet/IP packets. If the interface is nil, the
	// system-assigned multicast interface is used.
	Interface string
	// MulticastLoopbackEnabled specifies if Multicast Loopback should be enabled.
	MulticastLoopbackEnabled bool
	// PostSendPauseDuration specifies the pause duration after sending. 0 means disabled. According to the specification,
	// we may choose to always pause for 20 ms after transmitting, but we should always pause for at least 5 ms on a
	// multicast address.
	PostSendPauseDuration time.Duration
}

type Snapshot added in v0.2.0

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

Snapshot stores all information about a single metric snapshot.

func (*Snapshot) GetKey added in v0.2.0

func (s *Snapshot) GetKey() SnapshotKey

type SnapshotKey added in v0.2.0

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

SnapshotKey identifies all the snapshots that were received from a specific device and exported with the specific name.

type StartupReader added in v1.0.0

type StartupReader interface {
	// Run starts the startup reading.
	Run()
	// Close stops the startup reading.
	Close()
}

StartupReader defines the interface for active polling for metrics values against the knx system at startup.

func NewStartupReader added in v1.0.0

func NewStartupReader(config *Config, client GroupClient, metricsHandler MetricSnapshotHandler, messageCounter *prometheus.CounterVec) StartupReader

NewStartupReader creates a new StartupReader instance using the given MetricsExporter for connection handling and metrics observing.

type TunnelConfig added in v1.0.0

type TunnelConfig struct {
	// ResendInterval is the interval with which requests will be resent if no response is received.
	ResendInterval time.Duration

	// HeartbeatInterval specifies the time interval which triggers a heartbeat check.
	HeartbeatInterval time.Duration

	// ResponseTimeout specifies how long to wait for a response.
	ResponseTimeout time.Duration

	// SendLocalAddress specifies if local address should be sent on connection request.
	SendLocalAddress bool

	// UseTCP configures whether to connect to the gateway using TCP.
	UseTCP bool
}

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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