From 7f788dd5f9b8180a79677d44cc719f639648965d Mon Sep 17 00:00:00 2001 From: Felix Yuan Date: Fri, 18 Oct 2024 17:11:41 -0700 Subject: [PATCH] Add auth-type as a metric we collect --- collector.go | 10 ++++++++-- collector_test.go | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/collector.go b/collector.go index fb527dd..229fd2a 100644 --- a/collector.go +++ b/collector.go @@ -110,6 +110,9 @@ var ( } configMap = map[string]*(prometheus.Desc){ + "auth_type": prometheus.NewDesc( + prometheus.BuildFQName(namespace, "config", "authorization_type"), + "Config maximum number of client connections", []string{"method"}, nil), "max_client_conn": prometheus.NewDesc( prometheus.BuildFQName(namespace, "config", "max_client_connections"), "Config maximum number of client connections", nil, nil), @@ -223,11 +226,14 @@ func queryShowConfig(ch chan<- prometheus.Metric, db *sql.DB, logger *slog.Logge } value, err := strconv.ParseFloat(string(values), 64) + labelValues := []string{} if err != nil { - return fmt.Errorf("error parsing SHOW CONFIG column: %v, error: %w ", key, err) + // We couldn't parse the value as a float, so treat it as a string + value = 1.0 + labelValues = append(labelValues, string(values)) } if metric, ok := configMap[key]; ok { - ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value) + ch <- prometheus.MustNewConstMetric(metric, prometheus.GaugeValue, value, labelValues...) } else { logger.Debug("SHOW CONFIG unknown config", "config", key) } diff --git a/collector_test.go b/collector_test.go index 2570b5b..05fb164 100644 --- a/collector_test.go +++ b/collector_test.go @@ -118,6 +118,7 @@ func TestQueryShowConfig(t *testing.T) { expected := []MetricResult{ {labels: labelMap{}, metricType: dto.MetricType_GAUGE, value: 1900}, {labels: labelMap{}, metricType: dto.MetricType_GAUGE, value: 100}, + {labels: labelMap{"method": "md5"}, metricType: dto.MetricType_GAUGE, value: 1}, } convey.Convey("Metrics comparison", t, func() { for _, expect := range expected {