adds identifier

This commit is contained in:
Jake Keeys
2020-01-26 13:23:26 +00:00
parent f5de88e5bb
commit 542060a14b
3 changed files with 61 additions and 54 deletions

View File

@@ -20,11 +20,11 @@ type MetricsCollector struct {
dslMetricsCollector dslMetricsCollector dslMetricsCollector dslMetricsCollector
} }
func New(client hg612.Client, host string, collectIntervalSeconds int) Collector { func New(client hg612.Client, host string, identifier string, collectIntervalSeconds int) Collector {
return MetricsCollector{ return MetricsCollector{
collectIntervalSeconds: collectIntervalSeconds, collectIntervalSeconds: collectIntervalSeconds,
ctx: context.Background(), ctx: context.Background(),
dslMetricsCollector: newDSLMetricsCollector(client, host), dslMetricsCollector: newDSLMetricsCollector(client, host, identifier),
} }
} }

View File

@@ -10,6 +10,7 @@ import (
type dslMetricsCollector struct { type dslMetricsCollector struct {
client hg612.Client client hg612.Client
host string host string
identifier string
status *prometheus.GaugeVec status *prometheus.GaugeVec
@@ -40,13 +41,13 @@ type dslMetricsCollector struct {
upFEC2 *prometheus.GaugeVec upFEC2 *prometheus.GaugeVec
} }
func newDSLMetricsCollector(client hg612.Client, host string) dslMetricsCollector { func newDSLMetricsCollector(client hg612.Client, host string, identifier string) dslMetricsCollector {
status := promauto.NewGaugeVec( status := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "status", Name: "status",
}, },
[]string{"host", "status", "modulation", "dataPath"}, []string{"host", "identifier", "status", "modulation", "dataPath"},
) )
upCurrRate := promauto.NewGaugeVec( upCurrRate := promauto.NewGaugeVec(
@@ -54,84 +55,84 @@ func newDSLMetricsCollector(client hg612.Client, host string) dslMetricsCollecto
Namespace: "dsl", Namespace: "dsl",
Name: "up_current_rate", Name: "up_current_rate",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downCurrRate := promauto.NewGaugeVec( downCurrRate := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_current_rate", Name: "down_current_rate",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upCurrRate2 := promauto.NewGaugeVec( upCurrRate2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_current_rate_2", Name: "up_current_rate_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downCurrRate2 := promauto.NewGaugeVec( downCurrRate2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_current_rate_2", Name: "down_current_rate_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upMaxRate := promauto.NewGaugeVec( upMaxRate := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_max_rate", Name: "up_max_rate",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downMaxRate := promauto.NewGaugeVec( downMaxRate := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_max_rate", Name: "down_max_rate",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upSNR := promauto.NewGaugeVec( upSNR := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_snr", Name: "up_snr",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downSNR := promauto.NewGaugeVec( downSNR := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_snr", Name: "down_snr",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upAttenuation := promauto.NewGaugeVec( upAttenuation := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_attenuation", Name: "up_attenuation",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downAttenuation := promauto.NewGaugeVec( downAttenuation := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_attenuation", Name: "down_attenuation",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upPower := promauto.NewGaugeVec( upPower := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_power", Name: "up_power",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downPower := promauto.NewGaugeVec( downPower := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_power", Name: "down_power",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downHEC := promauto.NewGaugeVec( downHEC := promauto.NewGaugeVec(
@@ -139,89 +140,90 @@ func newDSLMetricsCollector(client hg612.Client, host string) dslMetricsCollecto
Namespace: "dsl", Namespace: "dsl",
Name: "down_hec", Name: "down_hec",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upHEC := promauto.NewGaugeVec( upHEC := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_hec", Name: "up_hec",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downCRC := promauto.NewGaugeVec( downCRC := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_crc", Name: "down_crc",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upCRC := promauto.NewGaugeVec( upCRC := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_crc", Name: "up_crc",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downFEC := promauto.NewGaugeVec( downFEC := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_fec", Name: "down_fec",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upFEC := promauto.NewGaugeVec( upFEC := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_fec", Name: "up_fec",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downHEC2 := promauto.NewGaugeVec( downHEC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_hec_2", Name: "down_hec_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upHEC2 := promauto.NewGaugeVec( upHEC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_hec_2", Name: "up_hec_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downCRC2 := promauto.NewGaugeVec( downCRC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_crc_2", Name: "down_crc_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upCRC2 := promauto.NewGaugeVec( upCRC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_crc_2", Name: "up_crc_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
downFEC2 := promauto.NewGaugeVec( downFEC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "down_fec_2", Name: "down_fec_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
upFEC2 := promauto.NewGaugeVec( upFEC2 := promauto.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Namespace: "dsl", Namespace: "dsl",
Name: "up_fec_2", Name: "up_fec_2",
}, },
[]string{"host"}, []string{"host", "identifier"},
) )
return dslMetricsCollector{ return dslMetricsCollector{
client: client, client: client,
host: host, host: host,
identifier: identifier,
status: status, status: status,
@@ -259,33 +261,33 @@ func (c dslMetricsCollector) collect() error {
return errors.Wrap(err, "error getting dsl status") return errors.Wrap(err, "error getting dsl status")
} }
c.status.WithLabelValues(c.host, status.DSLCfg.Status, status.DSLCfg.Modulation, status.DSLCfg.DataPath).Set(1) c.status.WithLabelValues(c.host, c.identifier, status.DSLCfg.Status, status.DSLCfg.Modulation, status.DSLCfg.DataPath).Set(1)
c.upCurrRate.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpCurrRate)) c.upCurrRate.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpCurrRate))
c.downCurrRate.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownCurrRate)) c.downCurrRate.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownCurrRate))
c.upCurrRate2.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpCurrRate2)) c.upCurrRate2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpCurrRate2))
c.downCurrRate2.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownCurrRate2)) c.downCurrRate2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownCurrRate2))
c.upMaxRate.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpMaxRate)) c.upMaxRate.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpMaxRate))
c.downMaxRate.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownMaxRate)) c.downMaxRate.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownMaxRate))
c.upSNR.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpSNR)) c.upSNR.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpSNR))
c.downSNR.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownSNR)) c.downSNR.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownSNR))
c.upAttenuation.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpAttenuation)) c.upAttenuation.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpAttenuation))
c.downAttenuation.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownAttenuation)) c.downAttenuation.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownAttenuation))
c.upPower.WithLabelValues(c.host).Set(float64(status.DSLCfg.UpPower)) c.upPower.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.UpPower))
c.downPower.WithLabelValues(c.host).Set(float64(status.DSLCfg.DownPower)) c.downPower.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLCfg.DownPower))
c.downHEC.WithLabelValues(c.host).Set(float64(status.DSLStats.DownHEC)) c.downHEC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownHEC))
c.upHEC.WithLabelValues(c.host).Set(float64(status.DSLStats.UpHEC)) c.upHEC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpHEC))
c.downCRC.WithLabelValues(c.host).Set(float64(status.DSLStats.DownCRC)) c.downCRC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownCRC))
c.upCRC.WithLabelValues(c.host).Set(float64(status.DSLStats.UpCRC)) c.upCRC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpCRC))
c.downFEC.WithLabelValues(c.host).Set(float64(status.DSLStats.DownFEC)) c.downFEC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownFEC))
c.upFEC.WithLabelValues(c.host).Set(float64(status.DSLStats.UpFEC)) c.upFEC.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpFEC))
c.downHEC2.WithLabelValues(c.host).Set(float64(status.DSLStats.DownHEC2)) c.downHEC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownHEC2))
c.upHEC2.WithLabelValues(c.host).Set(float64(status.DSLStats.UpHEC2)) c.upHEC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpHEC2))
c.downCRC2.WithLabelValues(c.host).Set(float64(status.DSLStats.DownCRC2)) c.downCRC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownCRC2))
c.upCRC2.WithLabelValues(c.host).Set(float64(status.DSLStats.UpCRC2)) c.upCRC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpCRC2))
c.downFEC2.WithLabelValues(c.host).Set(float64(status.DSLStats.DownFEC2)) c.downFEC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.DownFEC2))
c.upFEC2.WithLabelValues(c.host).Set(float64(status.DSLStats.UpFEC2)) c.upFEC2.WithLabelValues(c.host, c.identifier).Set(float64(status.DSLStats.UpFEC2))
return nil return nil
} }

View File

@@ -24,6 +24,11 @@ func main() {
Usage: "the fully qualified host for the hg612 modem", Usage: "the fully qualified host for the hg612 modem",
Required: true, Required: true,
}, },
&cli.StringFlag{
Name: "identifier",
Usage: "the identifier for the line and modem",
Required: true,
},
&cli.StringFlag{ &cli.StringFlag{
Name: "bind", Name: "bind",
Usage: "the bind string for the http server ie :8080", Usage: "the bind string for the http server ie :8080",
@@ -38,7 +43,7 @@ func main() {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
client := hg612.New(fmt.Sprintf("http://%s", c.String("host")), http.DefaultClient) client := hg612.New(fmt.Sprintf("http://%s", c.String("host")), http.DefaultClient)
collector := metrics.New(client, c.String("host"), c.Int("interval")) collector := metrics.New(client, c.String("host"), c.String("identifier"), c.Int("interval"))
defer collector.Stop() defer collector.Stop()
collector.Start() collector.Start()