mirror of
https://github.com/prometheus/mysqld_exporter.git
synced 2025-04-18 09:24:02 +03:00
chore!: adopt log/slog, drop go-kit/log (#875)
* 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>
This commit is contained in:
parent
abc1816f37
commit
be5dc65671
@ -4,4 +4,5 @@ linters:
|
||||
enable:
|
||||
- misspell
|
||||
- staticcheck
|
||||
- sloglint
|
||||
disable-all: true
|
||||
|
@ -18,10 +18,10 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -71,7 +71,7 @@ func (ScrapeBinlogSize) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeBinlogSize) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeBinlogSize) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var logBin uint8
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, logbinQuery).Scan(&logBin)
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ func TestScrapeBinlogSize(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeBinlogSize{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeBinlogSize{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,11 +17,11 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -51,7 +51,7 @@ func (ScrapeEngineInnodbStatus) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeEngineInnodbStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
rows, err := db.QueryContext(ctx, engineInnodbStatusQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -155,7 +155,7 @@ END OF INNODB MONITOR OUTPUT
|
||||
inst := &instance{db: db}
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeEngineInnodbStatus{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeEngineInnodbStatus{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -18,9 +18,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -50,7 +50,7 @@ func (ScrapeEngineTokudbStatus) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeEngineTokudbStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeEngineTokudbStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
tokudbRows, err := db.QueryContext(ctx, engineTokudbStatusQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -60,7 +60,7 @@ func TestScrapeEngineTokudbStatus(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeEngineTokudbStatus{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeEngineTokudbStatus{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -16,13 +16,12 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -80,14 +79,14 @@ var _ prometheus.Collector = (*Exporter)(nil)
|
||||
// Exporter collects MySQL metrics. It implements prometheus.Collector.
|
||||
type Exporter struct {
|
||||
ctx context.Context
|
||||
logger log.Logger
|
||||
logger *slog.Logger
|
||||
dsn string
|
||||
scrapers []Scraper
|
||||
instance *instance
|
||||
}
|
||||
|
||||
// New returns a new MySQL exporter for the provided DSN.
|
||||
func New(ctx context.Context, dsn string, scrapers []Scraper, logger log.Logger) *Exporter {
|
||||
func New(ctx context.Context, dsn string, scrapers []Scraper, logger *slog.Logger) *Exporter {
|
||||
// Setup extra params for the DSN, default to having a lock timeout.
|
||||
dsnParams := []string{fmt.Sprintf(timeoutParam, *exporterLockTimeout)}
|
||||
|
||||
@ -129,14 +128,14 @@ func (e *Exporter) scrape(ctx context.Context, ch chan<- prometheus.Metric) floa
|
||||
scrapeTime := time.Now()
|
||||
instance, err := newInstance(e.dsn)
|
||||
if err != nil {
|
||||
level.Error(e.logger).Log("msg", "Error opening connection to database", "err", err)
|
||||
e.logger.Error("Error opening connection to database", "err", err)
|
||||
return 0.0
|
||||
}
|
||||
defer instance.Close()
|
||||
e.instance = instance
|
||||
|
||||
if err := instance.Ping(); err != nil {
|
||||
level.Error(e.logger).Log("msg", "Error pinging mysqld", "err", err)
|
||||
e.logger.Error("Error pinging mysqld", "err", err)
|
||||
return 0.0
|
||||
}
|
||||
|
||||
@ -157,8 +156,8 @@ func (e *Exporter) scrape(ctx context.Context, ch chan<- prometheus.Metric) floa
|
||||
label := "collect." + scraper.Name()
|
||||
scrapeTime := time.Now()
|
||||
collectorSuccess := 1.0
|
||||
if err := scraper.Scrape(ctx, instance, ch, log.With(e.logger, "scraper", scraper.Name())); err != nil {
|
||||
level.Error(e.logger).Log("msg", "Error from scraper", "scraper", scraper.Name(), "target", e.getTargetFromDsn(), "err", err)
|
||||
if err := scraper.Scrape(ctx, instance, ch, e.logger.With("scraper", scraper.Name())); err != nil {
|
||||
e.logger.Error("Error from scraper", "scraper", scraper.Name(), "target", e.getTargetFromDsn(), "err", err)
|
||||
collectorSuccess = 0.0
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(mysqlScrapeCollectorSuccess, prometheus.GaugeValue, collectorSuccess, label)
|
||||
@ -172,7 +171,7 @@ func (e *Exporter) getTargetFromDsn() string {
|
||||
// Get target from DSN.
|
||||
dsnConfig, err := mysql.ParseDSN(e.dsn)
|
||||
if err != nil {
|
||||
level.Error(e.logger).Log("msg", "Error parsing DSN", "err", err)
|
||||
e.logger.Error("Error parsing DSN", "err", err)
|
||||
return ""
|
||||
}
|
||||
return dsnConfig.Addr
|
||||
|
@ -17,9 +17,9 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -36,7 +36,7 @@ func TestExporter(t *testing.T) {
|
||||
[]Scraper{
|
||||
ScrapeGlobalStatus{},
|
||||
},
|
||||
log.NewNopLogger(),
|
||||
promslog.NewNopLogger(),
|
||||
)
|
||||
|
||||
convey.Convey("Metrics describing", t, func() {
|
||||
|
@ -18,11 +18,11 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -99,7 +99,7 @@ func (ScrapeGlobalStatus) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeGlobalStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeGlobalStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
globalStatusRows, err := db.QueryContext(ctx, globalStatusQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -64,7 +64,7 @@ func TestScrapeGlobalStatus(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeGlobalStatus{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeGlobalStatus{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -18,11 +18,11 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -138,7 +138,7 @@ func (ScrapeGlobalVariables) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeGlobalVariables) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
globalVariablesRows, err := db.QueryContext(ctx, globalVariablesQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -53,7 +53,7 @@ func TestScrapeGlobalVariables(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeGlobalVariables{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeGlobalVariables{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -19,10 +19,10 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -100,7 +100,7 @@ func nowExpr() string {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeHeartbeat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeHeartbeat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
query := fmt.Sprintf(heartbeatQuery, nowExpr(), *collectHeartbeatDatabase, *collectHeartbeatTable)
|
||||
heartbeatRows, err := db.QueryContext(ctx, query)
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -73,7 +73,7 @@ func TestScrapeHeartbeat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeHeartbeat{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeHeartbeat{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ func (ScrapeAutoIncrementColumns) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeAutoIncrementColumns) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeAutoIncrementColumns) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
autoIncrementRows, err := db.QueryContext(ctx, infoSchemaAutoIncrementQuery)
|
||||
if err != nil {
|
||||
|
@ -18,10 +18,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -160,16 +159,16 @@ func (ScrapeClientStat) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeClientStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeClientStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var varName, varVal string
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, userstatCheckQuery).Scan(&varName, &varVal)
|
||||
if err != nil {
|
||||
level.Debug(logger).Log("msg", "Detailed client stats are not available.")
|
||||
logger.Debug("Detailed client stats are not available.")
|
||||
return nil
|
||||
}
|
||||
if varVal == "OFF" {
|
||||
level.Debug(logger).Log("msg", "MySQL variable is OFF.", "var", varName)
|
||||
logger.Debug("MySQL variable is OFF.", "var", varName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ func TestScrapeClientStat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeClientStat{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeClientStat{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -76,7 +76,7 @@ func (ScrapeInnodbCmp) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeInnodbCmp) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeInnodbCmp) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
informationSchemaInnodbCmpRows, err := db.QueryContext(ctx, innodbCmpQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -39,7 +39,7 @@ func TestScrapeInnodbCmp(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeInnodbCmp{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeInnodbCmp{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -71,7 +71,7 @@ func (ScrapeInnodbCmpMem) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeInnodbCmpMem) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeInnodbCmpMem) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
informationSchemaInnodbCmpMemRows, err := db.QueryContext(ctx, innodbCmpMemQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -39,7 +39,7 @@ func TestScrapeInnodbCmpMem(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeInnodbCmpMem{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeInnodbCmpMem{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -19,10 +19,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -92,7 +91,7 @@ func (ScrapeInnodbMetrics) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeInnodbMetrics) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeInnodbMetrics) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var enabledColumnName string
|
||||
var query string
|
||||
|
||||
@ -132,7 +131,7 @@ func (ScrapeInnodbMetrics) Scrape(ctx context.Context, instance *instance, ch ch
|
||||
if subsystem == "buffer_page_io" {
|
||||
match := bufferPageRE.FindStringSubmatch(name)
|
||||
if len(match) != 3 {
|
||||
level.Warn(logger).Log("msg", "innodb_metrics subsystem buffer_page_io returned an invalid name", "name", name)
|
||||
logger.Warn("innodb_metrics subsystem buffer_page_io returned an invalid name", "name", name)
|
||||
continue
|
||||
}
|
||||
switch match[1] {
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -54,7 +54,7 @@ func TestScrapeInnodbMetrics(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeInnodbMetrics{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeInnodbMetrics{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -101,7 +101,7 @@ func (ScrapeInfoSchemaInnodbTablespaces) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeInfoSchemaInnodbTablespaces) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var tablespacesTablename string
|
||||
var query string
|
||||
db := instance.getDB()
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/blang/semver/v4"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -52,7 +52,7 @@ func TestScrapeInfoSchemaInnodbTablespaces(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeInfoSchemaInnodbTablespaces{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeInfoSchemaInnodbTablespaces{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
@ -101,7 +101,7 @@ func TestScrapeInfoSchemaInnodbTablespacesWithoutSpaceType(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeInfoSchemaInnodbTablespaces{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeInfoSchemaInnodbTablespaces{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -18,12 +18,12 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -96,7 +96,7 @@ func (ScrapeProcesslist) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeProcesslist) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeProcesslist) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
processQuery := fmt.Sprintf(
|
||||
infoSchemaProcesslistQuery,
|
||||
*processlistMinTime,
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -57,7 +57,7 @@ func TestScrapeProcesslist(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeProcesslist{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeProcesslist{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,11 +17,10 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -119,16 +118,16 @@ func (ScrapeQueryResponseTime) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeQueryResponseTime) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeQueryResponseTime) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var queryStats uint8
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, queryResponseCheckQuery).Scan(&queryStats)
|
||||
if err != nil {
|
||||
level.Debug(logger).Log("msg", "Query response time distribution is not available.")
|
||||
logger.Debug("Query response time distribution is not available.")
|
||||
return nil
|
||||
}
|
||||
if queryStats == 0 {
|
||||
level.Debug(logger).Log("msg", "MySQL variable is OFF.", "var", "query_response_time_stats")
|
||||
logger.Debug("MySQL variable is OFF.", "var", "query_response_time_stats")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -53,7 +53,7 @@ func TestScrapeQueryResponseTime(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeQueryResponseTime{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeQueryResponseTime{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,9 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
MySQL "github.com/go-sql-driver/mysql"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -83,14 +82,14 @@ func (ScrapeReplicaHost) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeReplicaHost) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeReplicaHost) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
replicaHostRows, err := db.QueryContext(ctx, replicaHostQuery)
|
||||
if err != nil {
|
||||
if mysqlErr, ok := err.(*MySQL.MySQLError); ok { // Now the error number is accessible directly
|
||||
// Check for error 1109: Unknown table
|
||||
if mysqlErr.Number == 1109 {
|
||||
level.Debug(logger).Log("msg", "information_schema.replica_host_status is not available.")
|
||||
logger.Debug("information_schema.replica_host_status is not available.")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -40,7 +40,7 @@ func TestScrapeReplicaHost(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeReplicaHost{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeReplicaHost{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,9 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -71,17 +70,17 @@ func (ScrapeSchemaStat) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeSchemaStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeSchemaStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var varName, varVal string
|
||||
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, userstatCheckQuery).Scan(&varName, &varVal)
|
||||
if err != nil {
|
||||
level.Debug(logger).Log("msg", "Detailed schema stats are not available.")
|
||||
logger.Debug("Detailed schema stats are not available.")
|
||||
return nil
|
||||
}
|
||||
if varVal == "OFF" {
|
||||
level.Debug(logger).Log("msg", "MySQL variable is OFF.", "var", varName)
|
||||
logger.Debug("MySQL variable is OFF.", "var", varName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ func TestScrapeSchemaStat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeSchemaStat{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSchemaStat{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -18,10 +18,10 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -96,7 +96,7 @@ func (ScrapeTableSchema) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeTableSchema) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeTableSchema) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var dbList []string
|
||||
db := instance.getDB()
|
||||
if *tableSchemaDatabases == "*" {
|
||||
|
@ -17,9 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -71,16 +70,16 @@ func (ScrapeTableStat) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeTableStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeTableStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var varName, varVal string
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, userstatCheckQuery).Scan(&varName, &varVal)
|
||||
if err != nil {
|
||||
level.Debug(logger).Log("msg", "Detailed table stats are not available.")
|
||||
logger.Debug("Detailed table stats are not available.")
|
||||
return nil
|
||||
}
|
||||
if varVal == "OFF" {
|
||||
level.Debug(logger).Log("msg", "MySQL variable is OFF.", "var", varName)
|
||||
logger.Debug("MySQL variable is OFF.", "var", varName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -43,7 +43,7 @@ func TestScrapeTableStat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeTableStat{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeTableStat{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -18,10 +18,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -156,16 +155,16 @@ func (ScrapeUserStat) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeUserStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeUserStat) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var varName, varVal string
|
||||
db := instance.getDB()
|
||||
err := db.QueryRowContext(ctx, userstatCheckQuery).Scan(&varName, &varVal)
|
||||
if err != nil {
|
||||
level.Debug(logger).Log("msg", "Detailed user stats are not available.")
|
||||
logger.Debug("Detailed user stats are not available.")
|
||||
return nil
|
||||
}
|
||||
if varVal == "OFF" {
|
||||
level.Debug(logger).Log("msg", "MySQL variable is OFF.", "var", varName)
|
||||
logger.Debug("MySQL variable is OFF.", "var", varName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -42,7 +42,7 @@ func TestScrapeUserStat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeUserStat{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeUserStat{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -19,10 +19,10 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -120,7 +120,7 @@ func (ScrapeUser) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeUser) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeUser) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
var (
|
||||
userRows *sql.Rows
|
||||
|
@ -18,9 +18,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -181,7 +181,7 @@ func (ScrapePerfEventsStatements) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfEventsStatements) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
perfQuery := fmt.Sprintf(
|
||||
perfEventsStatementsQuery,
|
||||
*perfEventsStatementsDigestTextLimit,
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -176,7 +176,7 @@ func (ScrapePerfEventsStatementsSum) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfEventsStatementsSum) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfEventsStatementsSum) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
// Timers here are returned in picoseconds.
|
||||
perfEventsStatementsSumRows, err := db.QueryContext(ctx, perfEventsStatementsSumQuery)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -60,7 +60,7 @@ func (ScrapePerfEventsWaits) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfEventsWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfEventsWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
// Timers here are returned in picoseconds.
|
||||
perfSchemaEventsWaitsRows, err := db.QueryContext(ctx, perfEventsWaitsQuery)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ func (ScrapePerfFileEvents) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfFileEvents) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfFileEvents) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
// Timers here are returned in picoseconds.
|
||||
perfSchemaFileEventsRows, err := db.QueryContext(ctx, perfFileEventsQuery)
|
||||
|
@ -17,10 +17,10 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -79,7 +79,7 @@ func (ScrapePerfFileInstances) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfFileInstances) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfFileInstances) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
// Timers here are returned in picoseconds.
|
||||
perfSchemaFileInstancesRows, err := db.QueryContext(ctx, perfFileInstancesQuery, *performanceSchemaFileInstancesFilter)
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -49,7 +49,7 @@ func TestScrapePerfFileInstances(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfFileInstances{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfFileInstances{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
panic(fmt.Sprintf("error calling function on test: %s", err))
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -63,7 +63,7 @@ func (ScrapePerfIndexIOWaits) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfIndexIOWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfIndexIOWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
perfSchemaIndexWaitsRows, err := db.QueryContext(ctx, perfIndexIOWaitsQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -41,7 +41,7 @@ func TestScrapePerfIndexIOWaits(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfIndexIOWaits{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfIndexIOWaits{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,10 +17,10 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -78,7 +78,7 @@ func (ScrapePerfMemoryEvents) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfMemoryEvents) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfMemoryEvents) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
perfSchemaMemoryEventsRows, err := db.QueryContext(ctx, perfMemoryEventsQuery)
|
||||
if err != nil {
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -55,7 +55,7 @@ func TestScrapePerfMemoryEvents(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfMemoryEvents{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfMemoryEvents{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
panic(fmt.Sprintf("error calling function on test: %s", err))
|
||||
}
|
||||
close(ch)
|
||||
|
@ -15,9 +15,9 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -100,7 +100,7 @@ func (ScrapePerfReplicationApplierStatsByWorker) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfReplicationApplierStatsByWorker) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfReplicationApplierStatsByWorker) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
perfReplicationApplierStatsByWorkerRows, err := db.QueryContext(ctx, perfReplicationApplierStatsByWorkerQuery)
|
||||
if err != nil {
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -55,7 +55,7 @@ func TestScrapePerfReplicationApplierStatsByWorker(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfReplicationApplierStatsByWorker{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfReplicationApplierStatsByWorker{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -16,9 +16,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -79,7 +79,7 @@ func (ScrapePerfReplicationGroupMemberStats) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfReplicationGroupMemberStats) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfReplicationGroupMemberStats) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
rows, err := db.QueryContext(ctx, perfReplicationGroupMemberStatsQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -67,7 +67,7 @@ func TestScrapePerfReplicationGroupMemberStats(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfReplicationGroupMemberStats{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfReplicationGroupMemberStats{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -16,9 +16,9 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -45,7 +45,7 @@ func (ScrapePerfReplicationGroupMembers) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfReplicationGroupMembers) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfReplicationGroupMembers) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
perfReplicationGroupMembersRows, err := db.QueryContext(ctx, perfReplicationGroupMembersQuery)
|
||||
if err != nil {
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -51,7 +51,7 @@ func TestScrapePerfReplicationGroupMembers(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfReplicationGroupMembers{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfReplicationGroupMembers{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
@ -103,7 +103,7 @@ func TestScrapePerfReplicationGroupMembersMySQL57(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapePerfReplicationGroupMembers{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapePerfReplicationGroupMembers{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -64,7 +64,7 @@ func (ScrapePerfTableIOWaits) Version() float64 {
|
||||
}
|
||||
|
||||
// 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 log.Logger) error {
|
||||
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 {
|
||||
|
@ -17,8 +17,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -93,7 +93,7 @@ func (ScrapePerfTableLockWaits) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapePerfTableLockWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapePerfTableLockWaits) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
db := instance.getDB()
|
||||
perfSchemaTableLockWaitsRows, err := db.QueryContext(ctx, perfTableLockWaitsQuery)
|
||||
if err != nil {
|
||||
|
@ -15,8 +15,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -34,5 +34,5 @@ type Scraper interface {
|
||||
Version() float64
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error
|
||||
Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/google/uuid"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -63,7 +63,7 @@ func (ScrapeSlaveHosts) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeSlaveHosts) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeSlaveHosts) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var (
|
||||
slaveHostsRows *sql.Rows
|
||||
err error
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -40,7 +40,7 @@ func TestScrapeSlaveHostsOldFormat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
@ -79,7 +79,7 @@ func TestScrapeSlaveHostsNewFormat(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
@ -118,7 +118,7 @@ func TestScrapeSlaveHostsWithoutSlaveUuid(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSlaveHosts{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -69,7 +69,7 @@ func (ScrapeSlaveStatus) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape collects data from database connection and sends it over channel as prometheus metric.
|
||||
func (ScrapeSlaveStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeSlaveStatus) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
var (
|
||||
slaveStatusRows *sql.Rows
|
||||
err error
|
||||
|
@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -39,7 +39,7 @@ func TestScrapeSlaveStatus(t *testing.T) {
|
||||
|
||||
ch := make(chan prometheus.Metric)
|
||||
go func() {
|
||||
if err = (ScrapeSlaveStatus{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSlaveStatus{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -15,8 +15,8 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -98,7 +98,7 @@ func (ScrapeSysUserSummary) Version() float64 {
|
||||
}
|
||||
|
||||
// Scrape the information from sys.user_summary, creating a metric for each value of each row, labeled with the user
|
||||
func (ScrapeSysUserSummary) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger log.Logger) error {
|
||||
func (ScrapeSysUserSummary) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error {
|
||||
|
||||
db := instance.getDB()
|
||||
|
||||
|
@ -21,9 +21,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -113,7 +113,7 @@ func TestScrapeSysUserSummary(t *testing.T) {
|
||||
ch := make(chan prometheus.Metric)
|
||||
|
||||
go func() {
|
||||
if err = (ScrapeSysUserSummary{}).Scrape(context.Background(), inst, ch, log.NewNopLogger()); err != nil {
|
||||
if err = (ScrapeSysUserSummary{}).Scrape(context.Background(), inst, ch, promslog.NewNopLogger()); err != nil {
|
||||
t.Errorf("error calling function on test: %s", err)
|
||||
}
|
||||
close(ch)
|
||||
|
@ -17,15 +17,13 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
@ -84,7 +82,7 @@ func (ch *MySqlConfigHandler) GetConfig() *Config {
|
||||
return ch.Config
|
||||
}
|
||||
|
||||
func (ch *MySqlConfigHandler) ReloadConfig(filename string, mysqldAddress string, mysqldUser string, tlsInsecureSkipVerify bool, logger log.Logger) error {
|
||||
func (ch *MySqlConfigHandler) ReloadConfig(filename string, mysqldAddress string, mysqldUser string, tlsInsecureSkipVerify bool, logger *slog.Logger) error {
|
||||
var host, port string
|
||||
defer func() {
|
||||
if err != nil {
|
||||
@ -136,11 +134,11 @@ func (ch *MySqlConfigHandler) ReloadConfig(filename string, mysqldAddress string
|
||||
|
||||
err = sec.StrictMapTo(mysqlcfg)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "failed to parse config", "section", sectionName, "err", err)
|
||||
logger.Error("failed to parse config", "section", sectionName, "err", err)
|
||||
continue
|
||||
}
|
||||
if err := mysqlcfg.validateConfig(); err != nil {
|
||||
level.Error(logger).Log("msg", "failed to validate config", "section", sectionName, "err", err)
|
||||
logger.Error("failed to validate config", "section", sectionName, "err", err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,7 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -28,7 +27,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
c := MySqlConfigHandler{
|
||||
Config: &Config{},
|
||||
}
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -60,7 +59,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
c := MySqlConfigHandler{
|
||||
Config: &Config{},
|
||||
}
|
||||
if err := c.ReloadConfig("testdata/child_client.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/child_client.cnf", "localhost:3306", "", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
cfg := c.GetConfig()
|
||||
@ -73,7 +72,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
Config: &Config{},
|
||||
}
|
||||
os.Setenv("MYSQLD_EXPORTER_PASSWORD", "supersecretpassword")
|
||||
if err := c.ReloadConfig("", "testhost:5000", "testuser", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("", "testhost:5000", "testuser", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
Config: &Config{},
|
||||
}
|
||||
os.Setenv("MYSQLD_EXPORTER_PASSWORD", "supersecretpassword")
|
||||
err := c.ReloadConfig("", "testhost", "testuser", true, log.NewNopLogger())
|
||||
err := c.ReloadConfig("", "testhost", "testuser", true, promslog.NewNopLogger())
|
||||
convey.So(
|
||||
err,
|
||||
convey.ShouldBeError,
|
||||
@ -102,7 +101,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
Config: &Config{},
|
||||
}
|
||||
os.Setenv("MYSQLD_EXPORTER_PASSWORD", "supersecretpassword")
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "fakeuser", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "fakeuser", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -117,7 +116,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
Config: &Config{},
|
||||
}
|
||||
os.Clearenv()
|
||||
err := c.ReloadConfig("testdata/missing_user.cnf", "localhost:3306", "", true, log.NewNopLogger())
|
||||
err := c.ReloadConfig("testdata/missing_user.cnf", "localhost:3306", "", true, promslog.NewNopLogger())
|
||||
convey.So(
|
||||
err,
|
||||
convey.ShouldResemble,
|
||||
@ -130,7 +129,7 @@ func TestValidateConfig(t *testing.T) {
|
||||
Config: &Config{},
|
||||
}
|
||||
os.Clearenv()
|
||||
if err := c.ReloadConfig("testdata/missing_password.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/missing_password.cnf", "localhost:3306", "", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -151,7 +150,7 @@ func TestFormDSN(t *testing.T) {
|
||||
)
|
||||
|
||||
convey.Convey("Host exporter dsn", t, func() {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", false, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", false, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
convey.Convey("Default Client", func() {
|
||||
@ -191,7 +190,7 @@ func TestFormDSNWithSslSkipVerify(t *testing.T) {
|
||||
)
|
||||
|
||||
convey.Convey("Host exporter dsn with tls skip verify", t, func() {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/client.cnf", "localhost:3306", "", true, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
convey.Convey("Default Client", func() {
|
||||
@ -223,7 +222,7 @@ func TestFormDSNWithCustomTls(t *testing.T) {
|
||||
)
|
||||
|
||||
convey.Convey("Host exporter dsn with custom tls", t, func() {
|
||||
if err := c.ReloadConfig("testdata/client_custom_tls.cnf", "localhost:3306", "", false, log.NewNopLogger()); err != nil {
|
||||
if err := c.ReloadConfig("testdata/client_custom_tls.cnf", "localhost:3306", "", false, promslog.NewNopLogger()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
convey.Convey("Target tls enabled", func() {
|
||||
|
18
go.mod
18
go.mod
@ -6,14 +6,13 @@ require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
github.com/alecthomas/kingpin/v2 v2.4.0
|
||||
github.com/blang/semver/v4 v4.0.0
|
||||
github.com/go-kit/log v0.2.1
|
||||
github.com/go-sql-driver/mysql v1.8.1
|
||||
github.com/google/go-cmp v0.6.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/prometheus/client_golang v1.20.2
|
||||
github.com/prometheus/client_golang v1.20.4
|
||||
github.com/prometheus/client_model v0.6.1
|
||||
github.com/prometheus/common v0.59.1
|
||||
github.com/prometheus/exporter-toolkit v0.12.0
|
||||
github.com/prometheus/common v0.60.0
|
||||
github.com/prometheus/exporter-toolkit v0.13.0
|
||||
github.com/smartystreets/goconvey v1.8.1
|
||||
gopkg.in/ini.v1 v1.67.0
|
||||
)
|
||||
@ -24,7 +23,6 @@ require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.5.1 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/jpillora/backoff v1.0.0 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
@ -36,12 +34,12 @@ require (
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/smarty/assertions v1.15.0 // indirect
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/oauth2 v0.22.0 // indirect
|
||||
golang.org/x/crypto v0.27.0 // indirect
|
||||
golang.org/x/net v0.29.0 // indirect
|
||||
golang.org/x/oauth2 v0.23.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.23.0 // indirect
|
||||
golang.org/x/text v0.17.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
36
go.sum
36
go.sum
@ -17,10 +17,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
|
||||
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
|
||||
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
|
||||
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
|
||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
@ -53,14 +49,14 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
|
||||
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||
github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
|
||||
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
|
||||
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
|
||||
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
|
||||
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
|
||||
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
|
||||
github.com/prometheus/exporter-toolkit v0.12.0 h1:DkE5RcEZR3lQA2QD5JLVQIf41dFKNsVMXFhgqcif7fo=
|
||||
github.com/prometheus/exporter-toolkit v0.12.0/go.mod h1:fQH0KtTn0yrrS0S82kqppRjDDiwMfIQUwT+RBRRhwUc=
|
||||
github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA=
|
||||
github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
|
||||
github.com/prometheus/exporter-toolkit v0.13.0 h1:lmA0Q+8IaXgmFRKw09RldZmZdnvu9wwcDLIXGmTPw1c=
|
||||
github.com/prometheus/exporter-toolkit v0.13.0/go.mod h1:2uop99EZl80KdXhv/MxVI2181fMcwlsumFOqBecGkG0=
|
||||
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
|
||||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
@ -75,18 +71,18 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
|
||||
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
|
||||
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
|
||||
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
||||
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
@ -16,19 +16,18 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/promlog"
|
||||
"github.com/prometheus/common/promlog/flag"
|
||||
"github.com/prometheus/common/promslog"
|
||||
"github.com/prometheus/common/promslog/flag"
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/prometheus/exporter-toolkit/web"
|
||||
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
||||
@ -159,7 +158,7 @@ func init() {
|
||||
prometheus.MustRegister(versioncollector.NewCollector("mysqld_exporter"))
|
||||
}
|
||||
|
||||
func newHandler(scrapers []collector.Scraper, logger log.Logger) http.HandlerFunc {
|
||||
func newHandler(scrapers []collector.Scraper, logger *slog.Logger) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var dsn string
|
||||
var err error
|
||||
@ -172,10 +171,10 @@ func newHandler(scrapers []collector.Scraper, logger log.Logger) http.HandlerFun
|
||||
cfg := c.GetConfig()
|
||||
cfgsection, ok := cfg.Sections["client"]
|
||||
if !ok {
|
||||
level.Error(logger).Log("msg", "Failed to parse section [client] from config file", "err", err)
|
||||
logger.Error("Failed to parse section [client] from config file", "err", err)
|
||||
}
|
||||
if dsn, err = cfgsection.FormDSN(target); err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to form dsn from section [client]", "err", err)
|
||||
logger.Error("Failed to form dsn from section [client]", "err", err)
|
||||
}
|
||||
|
||||
collect := q["collect[]"]
|
||||
@ -185,7 +184,7 @@ func newHandler(scrapers []collector.Scraper, logger log.Logger) http.HandlerFun
|
||||
// If a timeout is configured via the Prometheus header, add it to the context.
|
||||
timeoutSeconds, err := getScrapeTimeoutSeconds(r, *timeoutOffset)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error getting timeout from Prometheus header", "err", err)
|
||||
logger.Error("Error getting timeout from Prometheus header", "err", err)
|
||||
}
|
||||
if timeoutSeconds > 0 {
|
||||
// Create new timeout context with request context as parent.
|
||||
@ -230,19 +229,19 @@ func main() {
|
||||
}
|
||||
|
||||
// Parse flags.
|
||||
promlogConfig := &promlog.Config{}
|
||||
flag.AddFlags(kingpin.CommandLine, promlogConfig)
|
||||
promslogConfig := &promslog.Config{}
|
||||
flag.AddFlags(kingpin.CommandLine, promslogConfig)
|
||||
kingpin.Version(version.Print("mysqld_exporter"))
|
||||
kingpin.HelpFlag.Short('h')
|
||||
kingpin.Parse()
|
||||
logger := promlog.New(promlogConfig)
|
||||
logger := promslog.New(promslogConfig)
|
||||
|
||||
level.Info(logger).Log("msg", "Starting mysqld_exporter", "version", version.Info())
|
||||
level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext())
|
||||
logger.Info("Starting mysqld_exporter", "version", version.Info())
|
||||
logger.Info("Build context", "build_context", version.BuildContext())
|
||||
|
||||
var err error
|
||||
if err = c.ReloadConfig(*configMycnf, *mysqldAddress, *mysqldUser, *tlsInsecureSkipVerify, logger); err != nil {
|
||||
level.Info(logger).Log("msg", "Error parsing host config", "file", *configMycnf, "err", err)
|
||||
logger.Info("Error parsing host config", "file", *configMycnf, "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -250,7 +249,7 @@ func main() {
|
||||
enabledScrapers := []collector.Scraper{}
|
||||
for scraper, enabled := range scraperFlags {
|
||||
if *enabled {
|
||||
level.Info(logger).Log("msg", "Scraper enabled", "scraper", scraper.Name())
|
||||
logger.Info("Scraper enabled", "scraper", scraper.Name())
|
||||
enabledScrapers = append(enabledScrapers, scraper)
|
||||
}
|
||||
}
|
||||
@ -270,7 +269,7 @@ func main() {
|
||||
}
|
||||
landingPage, err := web.NewLandingPage(landingConfig)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("err", err)
|
||||
logger.Error("Error creating landing page", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
http.Handle("/", landingPage)
|
||||
@ -278,14 +277,14 @@ func main() {
|
||||
http.HandleFunc("/probe", handleProbe(enabledScrapers, logger))
|
||||
http.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
|
||||
if err = c.ReloadConfig(*configMycnf, *mysqldAddress, *mysqldUser, *tlsInsecureSkipVerify, logger); err != nil {
|
||||
level.Warn(logger).Log("msg", "Error reloading host config", "file", *configMycnf, "error", err)
|
||||
logger.Warn("Error reloading host config", "file", *configMycnf, "error", err)
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`ok`))
|
||||
})
|
||||
srv := &http.Server{}
|
||||
if err := web.ListenAndServe(srv, toolkitFlags, logger); err != nil {
|
||||
level.Error(logger).Log("msg", "Error starting HTTP server", "err", err)
|
||||
logger.Error("Error starting HTTP server", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
11
probe.go
11
probe.go
@ -16,17 +16,16 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/mysqld_exporter/collector"
|
||||
)
|
||||
|
||||
func handleProbe(scrapers []collector.Scraper, logger log.Logger) http.HandlerFunc {
|
||||
func handleProbe(scrapers []collector.Scraper, logger *slog.Logger) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
params := r.URL.Query()
|
||||
@ -45,13 +44,13 @@ func handleProbe(scrapers []collector.Scraper, logger log.Logger) http.HandlerFu
|
||||
cfg := c.GetConfig()
|
||||
cfgsection, ok := cfg.Sections[authModule]
|
||||
if !ok {
|
||||
level.Error(logger).Log("msg", fmt.Sprintf("Could not find section [%s] from config file", authModule))
|
||||
logger.Error(fmt.Sprintf("Could not find section [%s] from config file", authModule))
|
||||
http.Error(w, fmt.Sprintf("Could not find config section [%s]", authModule), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
dsn, err := cfgsection.FormDSN(target)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", fmt.Sprintf("Failed to form dsn from section [%s]", authModule), "err", err)
|
||||
logger.Error(fmt.Sprintf("Failed to form dsn from section [%s]", authModule), "err", err)
|
||||
http.Error(w, fmt.Sprintf("Error forming dsn from config section [%s]", authModule), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -59,7 +58,7 @@ func handleProbe(scrapers []collector.Scraper, logger log.Logger) http.HandlerFu
|
||||
// If a timeout is configured via the Prometheus header, add it to the context.
|
||||
timeoutSeconds, err := getScrapeTimeoutSeconds(r, *timeoutOffset)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error getting timeout from Prometheus header", "err", err)
|
||||
logger.Error("Error getting timeout from Prometheus header", "err", err)
|
||||
}
|
||||
if timeoutSeconds > 0 {
|
||||
// Create new timeout context with request context as parent.
|
||||
|
Loading…
x
Reference in New Issue
Block a user