collector

package
v0.0.0-...-633801e Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Temperature = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "htcollector",
		Subsystem: "readings",
		Name:      "temperature",
		Help:      "The current temperature reading",
	}, []string{"stationid"})

	Humidity = promauto.NewGaugeVec(prometheus.GaugeOpts{
		Namespace: "htcollector",
		Subsystem: "readings",
		Name:      "humidity",
		Help:      "The current humidity reading",
	}, []string{"stationid"})
)

Functions

func HandleAllNames

func HandleAllNames(c *gin.Context, db *DB)

func HandleAllReadings

func HandleAllReadings(c *gin.Context, db *DB)

func HandleName

func HandleName(c *gin.Context, db *DB)

func HandleReadings

func HandleReadings(c *gin.Context, db *DB)

func HandleStoreReading

func HandleStoreReading(c *gin.Context, db *DB)

Store a reading from a ShellyHT note that this does *not* follow gin's regular parameter syntax

func PrometheusHandler

func PrometheusHandler() gin.HandlerFunc

Types

type DB

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

func MustInitDB

func MustInitDB(dataSourceName string) *DB

func (*DB) Close

func (db *DB) Close() error

func (*DB) GetAllReadingsSince

func (db *DB) GetAllReadingsSince(since time.Time) (map[string][]Reading, error)

func (*DB) GetDistinctStations

func (db *DB) GetDistinctStations() ([]string, error)

GetDistinctStations returns all distinct station ids as a slice of strings

func (*DB) GetReadingsSince

func (db *DB) GetReadingsSince(since time.Time, stationid string) ([]Reading, error)

GetReadingsSince retrieves all the readings for a given station since a certain time. It accepts two arguments, since as a time.Time and stationid as a string. It returns a slice of Reading structs and an error if it fails to retrieve the readings.

func (*DB) GetStationNames

func (db *DB) GetStationNames() (map[string]string, error)

GetStationNames returns a map of stationids to names for all stationids for which there are readings. if no name is associated with a stationid, the name is listed as "Unknown"

func (*DB) SaveReading

func (db *DB) SaveReading(temperature float64, humidity float64, stationid string) error

SaveReading saves the temperature, humidity and stationid for a reading to a database. It accepts three arguments, temperature and humidity as float64 and stationid as a string. It returns an error if it is not able to save the reading to the database. It is save to run in concurrent go routines

func (*DB) UpdateName

func (db *DB) UpdateName(station *Station) error

UpdateName inserts or updates a Station struct

type Reading

type Reading struct {
	StationId   string
	Temperature float64
	Humidity    float64
	Timestamp   time.Time
}

type Station

type Station struct {
	StationId string `form:"stationid"`
	Name      string `form:"name"`
}

Jump to

Keyboard shortcuts

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