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 performance_schema.status_by_host gauge #465

Open
wants to merge 1 commit into
base: main
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
87 changes: 87 additions & 0 deletions collector/perf_schema_status_by_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2020 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Scrape `performance_schema.status_by_host` column information.

package collector

import (
"context"
"database/sql"

"github.com/go-kit/kit/log"
"github.com/prometheus/client_golang/prometheus"
)

const perfStatusByHostQuery = `
SELECT HOST, VARIABLE_NAME, VARIABLE_VALUE
FROM performance_schema.status_by_host
WHERE HOST IS NOT NULL;
`

// Metric descriptors.
var (
performanceSchemaStatusByHostDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, performanceSchema, "status_by_host"),
"The status variable value for a given host.",
[]string{"host", "variable_name"}, nil,
)
)

// ScrapePerfStatusByHost collects status_by_host table information.
type ScrapePerfStatusByHost struct{}

// Name of the Scraper. Should be unique.
func (ScrapePerfStatusByHost) Name() string {
return "perf_schema.status_by_host"
}

// Help describes the role of the Scraper.
func (ScrapePerfStatusByHost) Help() string {
return "Collect status_by_host gauges in performance_schema"
}

// Version of MySQL from which scraper is available.
func (ScrapePerfStatusByHost) Version() float64 {
return 5.7
}

// Scrape collects data from database connection and sends it over channel as prometheus metric.
func (ScrapePerfStatusByHost) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
statusByHostRows, err := db.QueryContext(ctx, perfStatusByHostQuery)
if err != nil {
return err
}
defer statusByHostRows.Close()

var (
host, variable_name string
value float64
)

for statusByHostRows.Next() {
if err := statusByHostRows.Scan(
&host, &variable_name, &value,
); err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
performanceSchemaStatusByHostDesc, prometheus.GaugeValue, value,
host, variable_name,
)
}
return nil
}

// check interface
var _ Scraper = ScrapePerfStatusByHost{}
1 change: 1 addition & 0 deletions mysqld_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var scrapers = map[collector.Scraper]bool{
collector.ScrapePerfReplicationGroupMembers{}: false,
collector.ScrapePerfReplicationGroupMemberStats{}: false,
collector.ScrapePerfReplicationApplierStatsByWorker{}: false,
collector.ScrapePerfStatusByHost{}: false,
collector.ScrapeUserStat{}: false,
collector.ScrapeClientStat{}: false,
collector.ScrapeTableStat{}: false,
Expand Down