Skip to content

Commit

Permalink
Add auth-type as a metric we collect
Browse files Browse the repository at this point in the history
  • Loading branch information
Sticksman committed Oct 19, 2024
1 parent 6ecb3e5 commit 7f788dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7f788dd

Please sign in to comment.