Documentation ¶
Index ¶
- Variables
- func HandleAllNames(c *gin.Context, db *DB)
- func HandleAllReadings(c *gin.Context, db *DB)
- func HandleName(c *gin.Context, db *DB)
- func HandleReadings(c *gin.Context, db *DB)
- func HandleStoreReading(c *gin.Context, db *DB)
- func PrometheusHandler() gin.HandlerFunc
- type DB
- func (db *DB) Close() error
- func (db *DB) GetAllReadingsSince(since time.Time) (map[string][]Reading, error)
- func (db *DB) GetDistinctStations() ([]string, error)
- func (db *DB) GetReadingsSince(since time.Time, stationid string) ([]Reading, error)
- func (db *DB) GetStationNames() (map[string]string, error)
- func (db *DB) SaveReading(temperature float64, humidity float64, stationid string) error
- func (db *DB) UpdateName(station *Station) error
- type Reading
- type Station
Constants ¶
This section is empty.
Variables ¶
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 HandleAllReadings ¶
func HandleName ¶
func HandleReadings ¶
func HandleStoreReading ¶
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 (*DB) GetAllReadingsSince ¶
func (*DB) GetDistinctStations ¶
GetDistinctStations returns all distinct station ids as a slice of strings
func (*DB) GetReadingsSince ¶
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 ¶
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 ¶
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 ¶
UpdateName inserts or updates a Station struct