add exporter name
This commit is contained in:
parent
aabf024abc
commit
6efd4fbbca
16
proxy.go
16
proxy.go
@ -26,6 +26,7 @@ var (
|
|||||||
//shellyAuthUser = flagset.String("shellyplug-auth-username", "", "Shellyplug authentication username (also via SHELLYPLUG_AUTH_USERNAME)")
|
//shellyAuthUser = flagset.String("shellyplug-auth-username", "", "Shellyplug authentication username (also via SHELLYPLUG_AUTH_USERNAME)")
|
||||||
//shellyAuthPass = flagset.String("shellyplug-auth-password", "", "Shellyplug authentication username (also via SHELLYPLUG_AUTH_PASSWORD)")
|
//shellyAuthPass = flagset.String("shellyplug-auth-password", "", "Shellyplug authentication username (also via SHELLYPLUG_AUTH_PASSWORD)")
|
||||||
exporterPort = flagset.Int("exporter-port", 5000, "Exporter port (also via EXPORTER_PORT)")
|
exporterPort = flagset.Int("exporter-port", 5000, "Exporter port (also via EXPORTER_PORT)")
|
||||||
|
exporterName = flagset.String("exporter-name", "shelly_plug", "Exporter name (also via EXPORTER_NAME)")
|
||||||
|
|
||||||
// additional flags
|
// additional flags
|
||||||
_ = flagset.String("config", "", "Path to config file (ini format)")
|
_ = flagset.String("config", "", "Path to config file (ini format)")
|
||||||
@ -159,7 +160,8 @@ func (s *ShellyStatus) Fetch() {
|
|||||||
func GetMetrics(c *gin.Context) {
|
func GetMetrics(c *gin.Context) {
|
||||||
switch ss.Version {
|
switch ss.Version {
|
||||||
case 1:
|
case 1:
|
||||||
c.String(http.StatusOK, `# HELP shellyplug_power Current power drawn in watts
|
c.String(http.StatusOK, `shellyplug_name %s
|
||||||
|
# HELP shellyplug_power Current power drawn in watts
|
||||||
# TYPE shellyplug_power gauge
|
# TYPE shellyplug_power gauge
|
||||||
shellyplug_power %.2f
|
shellyplug_power %.2f
|
||||||
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
||||||
@ -174,9 +176,10 @@ shellyplug_temperature %.2f
|
|||||||
# HELP shellyplug_uptime Plug uptime in seconds
|
# HELP shellyplug_uptime Plug uptime in seconds
|
||||||
# TYPE shellyplug_uptime gauge
|
# TYPE shellyplug_uptime gauge
|
||||||
shellyplug_uptime %d
|
shellyplug_uptime %d
|
||||||
`, ss.Status1.Meters[0].Counters[0], float32(0), 0, ss.Status1.Temperature, ss.Status1.Uptime)
|
`, exporterName, ss.Status1.Meters[0].Counters[0], float32(0), 0, ss.Status1.Temperature, ss.Status1.Uptime)
|
||||||
case 2:
|
case 2:
|
||||||
c.String(http.StatusOK, `# HELP shellyplug_power Current power drawn in watts
|
c.String(http.StatusOK, `shellyplug_name %s
|
||||||
|
# HELP shellyplug_power Current power drawn in watts
|
||||||
# TYPE shellyplug_power gauge
|
# TYPE shellyplug_power gauge
|
||||||
shellyplug_power %.2f
|
shellyplug_power %.2f
|
||||||
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
||||||
@ -191,9 +194,10 @@ shellyplug_temperature %.2f
|
|||||||
# HELP shellyplug_uptime Plug uptime in seconds
|
# HELP shellyplug_uptime Plug uptime in seconds
|
||||||
# TYPE shellyplug_uptime gauge
|
# TYPE shellyplug_uptime gauge
|
||||||
shellyplug_uptime %d
|
shellyplug_uptime %d
|
||||||
`, ss.Status2.Switch.Power, float32(0), 0, ss.Status2.Switch.Temperature.Celsius, ss.Status2.Sys.Uptime)
|
`, exporterName, ss.Status2.Switch.Power, float32(0), 0, ss.Status2.Switch.Temperature.Celsius, ss.Status2.Sys.Uptime)
|
||||||
default:
|
default:
|
||||||
c.String(http.StatusOK, `# HELP shellyplug_power Current power drawn in watts
|
c.String(http.StatusOK, `shellyplug_name %s
|
||||||
|
# HELP shellyplug_power Current power drawn in watts
|
||||||
# TYPE shellyplug_power gauge
|
# TYPE shellyplug_power gauge
|
||||||
shellyplug_power %.2f
|
shellyplug_power %.2f
|
||||||
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
# HELP shellyplug_overpower Overpower drawn in watts/minute
|
||||||
@ -208,7 +212,7 @@ shellyplug_temperature %.2f
|
|||||||
# HELP shellyplug_uptime Plug uptime in seconds
|
# HELP shellyplug_uptime Plug uptime in seconds
|
||||||
# TYPE shellyplug_uptime gauge
|
# TYPE shellyplug_uptime gauge
|
||||||
shellyplug_uptime %d
|
shellyplug_uptime %d
|
||||||
`, float32(0), float32(0), 0, float32(0), 0)
|
`, exporterName, float32(0), float32(0), 0, float32(0), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user