telemetry

package
v0.0.0-...-9604f65 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const AdafruitIOTokenStoredPlaceholder = "<stored>"
View Source
const CurrentLimit = 24 * 60
View Source
const DBKey = "telemetry"
View Source
const HealthStatsKey = "health_stats"
View Source
const HistoricalLimit = 24 * 30
View Source
const PasswordStoredPlaceholder = "<stored>"

TODO: translate these TODO: this is a bit of a hack in that it means someone can't have their

actual token/password be the string "<stored>", but that seems rare
enough a reasonable trade-off for a quick fix to unsaveable form bugs

Variables

View Source
var DefaultMQTTConfig = MQTTConfig{
	Server:   "tcp://127.0.0.1:1883",
	QoS:      0,
	Retained: false,
	Username: "",
	Password: "",
	ClientID: "reef-pi.local",
	Prefix:   "reef-pi",
}
View Source
var DefaultTelemetryConfig = TelemetryConfig{
	Mailer:          GMailMailer,
	Throttle:        10,
	CurrentLimit:    CurrentLimit,
	HistoricalLimit: HistoricalLimit,
	MQTT:            DefaultMQTTConfig,
}
View Source
var GMailMailer = MailerConfig{
	Server: "smtp.gmail.com",
	Port:   587,
	To:     []string{},
}

Functions

func NewTelemetry

func NewTelemetry(name, bucket string, store storage.Store, config TelemetryConfig, lr ErrorLogger) *telemetry

func SanitizeAdafruitIOFeedName

func SanitizeAdafruitIOFeedName(name string) string

func SanitizePrometheusMetricName

func SanitizePrometheusMetricName(name string) string

func TestTelemetry

func TestTelemetry(store storage.Store) *telemetry

Types

type AdafruitIO

type AdafruitIO struct {
	Enable bool   `json:"enable"`
	Token  string `json:"token"`
	User   string `json:"user"`
	Prefix string `json:"prefix"`
}

type AlertStats

type AlertStats struct {
	Count        int       `json:"count"`
	FirstTrigger time.Time `json:"first_trigger"`
}

type ErrorLogger

type ErrorLogger func(string, string) error

type Factory

type Factory func(ctx context.Context, name string, arg ...string) Runner

type HealthChecker

type HealthChecker interface {
	Check()
	Start()
	Stop()
	GetStats(http.ResponseWriter, *http.Request)
}

type HealthMetric

type HealthMetric struct {
	Load5      float64  `json:"cpu"`
	UsedMemory float64  `json:"memory"`
	Time       TeleTime `json:"time"`

	UnderVoltage float64 `json:"throttle"`
	// contains filtered or unexported fields
}

func (HealthMetric) Before

func (m1 HealthMetric) Before(mx Metric) bool

func (HealthMetric) Rollup

func (m1 HealthMetric) Rollup(mx Metric) (Metric, bool)

type MQTTClient

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

func NewMQTTClient

func NewMQTTClient(conf MQTTConfig) (*MQTTClient, error)

func (*MQTTClient) Publish

func (m *MQTTClient) Publish(topic, msg string) error

type MQTTConfig

type MQTTConfig struct {
	Enable   bool   `json:"enable"`
	Server   string `json:"server"`
	Username string `json:"username"`
	ClientID string `json:"client_id"`
	Password string `json:"password"`
	QoS      int    `json:"qos"`
	Retained bool   `json:"retained"`
	Prefix   string `json:"prefix"`
}

type Mailer

type Mailer interface {
	Email(subject, body string) error
}

type MailerConfig

type MailerConfig struct {
	Server   string   `json:"server"`
	Port     int      `json:"port"`
	From     string   `json:"from"`
	Username string   `json:"username"`
	Password string   `json:"password"`
	To       []string `json:"to"`
}

func (*MailerConfig) Mailer

func (c *MailerConfig) Mailer(opts ...MailerCustomizer) Mailer

type MailerCustomizer

type MailerCustomizer func(m *mailer)

type Metric

type Metric interface {
	Rollup(Metric) (Metric, bool)
	Before(Metric) bool
}

type NoopMailer

type NoopMailer struct{}

func (*NoopMailer) Email

func (n *NoopMailer) Email(s, _ string) error

type Runner

type Runner func() ([]byte, error)

func ExecFactory

func ExecFactory(ctx context.Context, name string, arg ...string) Runner

type Stats

type Stats struct {
	Current    *ring.Ring
	Historical *ring.Ring
}

type StatsManager

type StatsManager interface {
	Get(string) (StatsResponse, error)
	IsLoaded(string) bool
	Initialize(string) error
	Load(string, func(json.RawMessage) interface{}) error
	Save(string) error
	Update(string, Metric)
	Delete(string) error
}

type StatsOnDisk

type StatsOnDisk struct {
	Current    []json.RawMessage `json:"current"`
	Historical []json.RawMessage `json:"historical"`
}

type StatsResponse

type StatsResponse struct {
	Current    []Metric `json:"current"`
	Historical []Metric `json:"historical"`
}

swagger:model statsResponse

type TeleTime

type TeleTime time.Time

func (TeleTime) Before

func (t TeleTime) Before(t2 TeleTime) bool

func (TeleTime) Day

func (t TeleTime) Day() int

func (TeleTime) Hour

func (t TeleTime) Hour() int

func (TeleTime) MarshalJSON

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

func (*TeleTime) UnmarshalJSON

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

type Telemetry

type Telemetry interface {
	Alert(string, string) (bool, error)
	Mail(string, string) (bool, error)
	EmitMetric(string, string, float64)
	CreateFeedIfNotExist(string)
	DeleteFeedIfExist(string)
	NewStatsManager(string) StatsManager
	SendTestMessage(http.ResponseWriter, *http.Request)
	GetConfig(http.ResponseWriter, *http.Request)
	UpdateConfig(http.ResponseWriter, *http.Request)
	LogError(string, string) error
}

func Initialize

func Initialize(name, bucket string, store storage.Store, logError ErrorLogger, prom bool) Telemetry

type TelemetryConfig

type TelemetryConfig struct {
	AdafruitIO      AdafruitIO   `json:"adafruitio"`
	MQTT            MQTTConfig   `json:"mqtt"`
	Mailer          MailerConfig `json:"mailer"`
	Notify          bool         `json:"notify"`
	Prometheus      bool         `json:"prometheus"`
	Throttle        int          `json:"throttle"`
	HistoricalLimit int          `json:"historical_limit"`
	CurrentLimit    int          `json:"current_limit"`
}

type ThrottleType

type ThrottleType uint64
const (
	UnderVoltage                  ThrottleType = 0 //0x5000
	ARMFrequencyCapped            ThrottleType = 1
	CurrentlyThrottled            ThrottleType = 2
	SoftcoreTempLimit             ThrottleType = 3
	UnderVoltageHasOccurred       ThrottleType = 16
	ARMFrequencyCappedHasOccurred ThrottleType = 17
	ThrottlingHasOccurred         ThrottleType = 18
	SoftcoreTmpLimitHasOccurred   ThrottleType = 19
)

func GetThrottleTypes

func GetThrottleTypes(v int) (tTypes []ThrottleType)

func GetThrottled

func GetThrottled(ctx context.Context, cf Factory) ([]ThrottleType, error)

func VcgencmdGetThrottled

func VcgencmdGetThrottled() ([]ThrottleType, error)

func (*ThrottleType) String

func (t *ThrottleType) String() string

Jump to

Keyboard shortcuts

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