mqtt2prom

package module
v0.0.0-...-09f41e5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 18 Imported by: 0

README

mqtt2prom

subscribe mqtt topics and push them to prometheus metrics.

usage:

USAGE:
   mqtt2prom [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value, -c value  specify config file (default: "config.yaml")
   --help, -h                show help

config:

# mqtt broker url
mqtt_broker_url: mqtt://localhost:1883

# mqtt client id
mqtt_client_id: test_mqtt2prom

# subscribe topics/topic patterns
topics:
  # normal topic
  - "test_topic"
  # topic pattern, I've tested it on mosquitto
  - "/env/#"

# ignore topics, which wont push to prom push gateway
# MUST list one by one, no pattern
ignore_topics:
  - "/env/debug"

# prom pushgateway url
pushgateway_url: http://localhost:9091

# prom push job name
push_job_name: "mqtt2prom"

# prom push job interval
push_interval: 10s

# prom clean job interval
clean_interval: 1m

# clean job will delete metrics which is no data in this duration.
clean_duration: 1h

# log level
log_level: DEBUG

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOrUpdate

func AddOrUpdate(topic string, val float64)

func NewApp

func NewApp() (app *cli.App)

func StartMQTT

func StartMQTT(ctx context.Context, cfg *Config) error

func StartProm

func StartProm(cfg *Config) error

Types

type Config

type Config struct {
	Broker        string        `yaml:"mqtt_broker_url"`
	ClientID      string        `yaml:"mqtt_client_id"`
	Topics        []string      `yaml:"topics"`
	Ignores       []string      `yaml:"ignore_topics"`
	PushGateway   string        `yaml:"pushgateway_url"`
	PushJob       string        `yaml:"push_job_name"`
	PushInterval  time.Duration `yaml:"push_interval"`
	CleanInterval time.Duration `yaml:"clean_interval"`
	CleanDur      time.Duration `yaml:"clean_duration"`
	LogLevel      string        `yaml:"log_level"`

	IgnoredTopics map[string]struct{} `yaml:"-"`
}

func NewConfig

func NewConfig(filename string) (c *Config, err error)

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

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