config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModbusProtocolTCPIP represents modbus via TCP/IP.
	ModbusProtocolTCPIP = "tcp/ip"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Modules []Module `yaml:"modules"`
}

Config represents the configuration of the modbus exporter.

func LoadConfig

func LoadConfig(pathToTargets string) (Config, error)

LoadConfig unmarshals the targets configuration file.

func (*Config) GetModule

func (c *Config) GetModule(n string) *Module

GetModule returns the module matching the given string or nil if none was found.

func (*Config) HasModule

func (c *Config) HasModule(n string) bool

HasModule returns whether the given config has a module with the given name.

type EndiannessType

type EndiannessType string

EndiannessType is an Enum, representing the possible endianness types a register value can have.

const (
	// EndiannessBigEndian (1 2 3 4)
	EndiannessBigEndian EndiannessType = "big"
	// EndiannessLittleEndian (4 3 2 1)
	EndiannessLittleEndian EndiannessType = "little"
	// EndiannessMixedEndian (2 1 4 3)
	EndiannessMixedEndian EndiannessType = "mixed"
	// EndiannessYolo (3 4 1 2)
	EndiannessYolo EndiannessType = "yolo"
)

type ListTargets

type ListTargets map[string]*Module

ListTargets is the list of configurations of the targets from the configuration file.

type MetricDef

type MetricDef struct {
	// Name of the metric in the Prometheus output format.
	Name string `yaml:"name"`

	// Help text of the metric in the Prometheus output format.
	Help string `yaml:"help"`

	// Labels to be applied to the metric in the Prometheus output format.
	Labels map[string]string `yaml:"labels"`

	Address RegisterAddr `yaml:"address"`

	DataType ModbusDataType `yaml:"dataType"`

	Endianness EndiannessType `yaml:"endianness,omitempty"`

	// Bit offset within the input register to parse. Only valid for boolean data
	// type. The two bytes of a register are interpreted in network order (big
	// endianness). Boolean is determined via `register&(1<<offset)>0`.
	BitOffset *int `yaml:"bitOffset,omitempty"`

	MetricType MetricType `yaml:"metricType"`

	// Scaling factor
	Factor *float64 `yaml:"factor,omitempty"`
}

MetricDef defines how to construct Prometheus metrics based on one or more Modbus registers.

type MetricType

type MetricType string

MetricType specifies the Prometheus metric type, see https://prometheus.io/docs/concepts/metric_types/ for details.

const (
	MetricTypeGauge   MetricType = "gauge"
	MetricTypeCounter MetricType = "counter"
)

type ModbusDataType

type ModbusDataType string

ModbusDataType is an Enum, representing the possible data types a register value can be interpreted as.

const (
	ModbusBool    ModbusDataType = "bool"
	ModbusFloat16 ModbusDataType = "float16"
	ModbusInt16   ModbusDataType = "int16"
	ModbusUInt16  ModbusDataType = "uint16"
	ModbusInt32   ModbusDataType = "int32"
	ModbusUInt32  ModbusDataType = "uint32"
	ModbusFloat32 ModbusDataType = "float32"
	ModbusInt64   ModbusDataType = "int64"
	ModbusUInt64  ModbusDataType = "uint64"
	ModbusFloat64 ModbusDataType = "float64"
)

type ModbusProtocol

type ModbusProtocol string

ModbusProtocol specifies the protocol used to retrieve modbus data.

type ModbusProtocolValidationError

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

ModbusProtocolValidationError is returned on invalid or unsupported modbus protocol specifications.

func (*ModbusProtocolValidationError) Error

Error implements the Golang error interface.

type Module

type Module struct {
	Name     string         `yaml:"name"`
	Protocol ModbusProtocol `yaml:"protocol"`
	Timeout  int            `yaml:"timeout"`
	Baudrate int            `yaml:"baudrate"`
	Databits int            `yaml:"databits"`
	Stopbits int            `yaml:"stopbits"`
	Parity   string         `yaml:"parity"`
	Metrics  []MetricDef    `yaml:"metrics"`
}

Module defines the configuration parameters of a modbus module.

type RegisterAddr

type RegisterAddr uint32

RegisterAddr specifies the register in the possible output of _digital output_, _digital input, _ananlog input, _analog output_.

Jump to

Keyboard shortcuts

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