You've already forked mysqld_exporter
mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-07-09 18:21:43 +03:00
* chore!: adopt log/slog, drop go-kit/log Requires: prometheus/common#697 This PR includes: - linter updates to enable `sloglint` linter - Go dep updates for prometheus/{client_golang,common,exporter-toolkit} libs - refactorings to adopt log/slog in favor of go-kit/log The bulk of this PR was automated by the following script which is being used to aid in converting the various exporters/projects to use slog: https://gist.github.com/tjhop/49f96fb7ebbe55b12deee0b0312d8434 Builds and passes tests locally with go workspaces and up-to-date main branch of prometheus/common. Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> * build(deps): bump prometheus/common to v0.60.0 Signed-off-by: TJ Hoplock <t.hoplock@gmail.com> --------- Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
126 lines
4.4 KiB
Go
126 lines
4.4 KiB
Go
// Copyright 2018 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.table_io_waits_summary_by_table`.
|
|
|
|
package collector
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
const perfTableIOWaitsQuery = `
|
|
SELECT
|
|
OBJECT_SCHEMA, OBJECT_NAME,
|
|
COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE,
|
|
SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE, SUM_TIMER_DELETE
|
|
FROM performance_schema.table_io_waits_summary_by_table
|
|
WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema')
|
|
`
|
|
|
|
// Metric descriptors.
|
|
var (
|
|
performanceSchemaTableWaitsDesc = prometheus.NewDesc(
|
|
prometheus.BuildFQName(namespace, performanceSchema, "table_io_waits_total"),
|
|
"The total number of table I/O wait events for each table and operation.",
|
|
[]string{"schema", "name", "operation"}, nil,
|
|
)
|
|
performanceSchemaTableWaitsTimeDesc = prometheus.NewDesc(
|
|
prometheus.BuildFQName(namespace, performanceSchema, "table_io_waits_seconds_total"),
|
|
"The total time of table I/O wait events for each table and operation.",
|
|
[]string{"schema", "name", "operation"}, nil,
|
|
)
|
|
)
|
|
|
|
// ScrapePerfTableIOWaits collects from `performance_schema.table_io_waits_summary_by_table`.
|
|
type ScrapePerfTableIOWaits struct{}
|
|
|
|
// Name of the Scraper. Should be unique.
|
|
func (ScrapePerfTableIOWaits) Name() string {
|
|
return "perf_schema.tableiowaits"
|
|
}
|
|
|
|
// Help describes the role of the Scraper.
|
|
func (ScrapePerfTableIOWaits) Help() string {
|
|
return "Collect metrics from performance_schema.table_io_waits_summary_by_table"
|
|
}
|
|
|
|
// Version of MySQL from which scraper is available.
|
|
func (ScrapePerfTableIOWaits) Version() float64 {
|
|
return 5.6
|
|
}
|
|
|
|
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
|
func (ScrapePerfTableIOWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
|
db := instance.getDB()
|
|
perfSchemaTableWaitsRows, err := db.QueryContext(ctx, perfTableIOWaitsQuery)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer perfSchemaTableWaitsRows.Close()
|
|
|
|
var (
|
|
objectSchema, objectName string
|
|
countFetch, countInsert, countUpdate, countDelete uint64
|
|
timeFetch, timeInsert, timeUpdate, timeDelete uint64
|
|
)
|
|
|
|
for perfSchemaTableWaitsRows.Next() {
|
|
if err := perfSchemaTableWaitsRows.Scan(
|
|
&objectSchema, &objectName, &countFetch, &countInsert, &countUpdate, &countDelete,
|
|
&timeFetch, &timeInsert, &timeUpdate, &timeDelete,
|
|
); err != nil {
|
|
return err
|
|
}
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countFetch),
|
|
objectSchema, objectName, "fetch",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countInsert),
|
|
objectSchema, objectName, "insert",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countUpdate),
|
|
objectSchema, objectName, "update",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsDesc, prometheus.CounterValue, float64(countDelete),
|
|
objectSchema, objectName, "delete",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsTimeDesc, prometheus.CounterValue, float64(timeFetch)/picoSeconds,
|
|
objectSchema, objectName, "fetch",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsTimeDesc, prometheus.CounterValue, float64(timeInsert)/picoSeconds,
|
|
objectSchema, objectName, "insert",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsTimeDesc, prometheus.CounterValue, float64(timeUpdate)/picoSeconds,
|
|
objectSchema, objectName, "update",
|
|
)
|
|
ch <- prometheus.MustNewConstMetric(
|
|
performanceSchemaTableWaitsTimeDesc, prometheus.CounterValue, float64(timeDelete)/picoSeconds,
|
|
objectSchema, objectName, "delete",
|
|
)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// check interface
|
|
var _ Scraper = ScrapePerfTableIOWaits{}
|