Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth-type v2 #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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