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
}
func New(client hg612.Client, host string, collectIntervalSeconds int) Collector {
func New(client hg612.Client, host string, identifier string, collectIntervalSeconds int) Collector {
return MetricsCollector{
collectIntervalSeconds: collectIntervalSeconds,
ctx: context.Background(),
dslMetricsCollector: newDSLMetricsCollector(client, host),
dslMetricsCollector: newDSLMetricsCollector(client, host, identifier),
}
}

View File

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

View File

@@ -24,6 +24,11 @@ func main() {
Usage: "the fully qualified host for the hg612 modem",
Required: true,
},
&cli.StringFlag{
Name: "identifier",
Usage: "the identifier for the line and modem",
Required: true,
},
&cli.StringFlag{
Name: "bind",
Usage: "the bind string for the http server ie :8080",
@@ -38,7 +43,7 @@ func main() {
Action: func(c *cli.Context) error {
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()
collector.Start()