Path: blob/main/component/prometheus/exporter/mysql/mysql.go
4095 views
package mysql12import (3"github.com/grafana/agent/component"4"github.com/grafana/agent/component/prometheus/exporter"5"github.com/grafana/agent/pkg/integrations"6"github.com/grafana/agent/pkg/integrations/mysqld_exporter"7"github.com/grafana/agent/pkg/river/rivertypes"8config_util "github.com/prometheus/common/config"9)1011func init() {12component.Register(component.Registration{13Name: "prometheus.exporter.mysql",14Args: Arguments{},15Exports: exporter.Exports{},16Build: exporter.New(createExporter, "mysql"),17})18}1920func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {21a := args.(Arguments)22return a.Convert().NewIntegration(opts.Logger)23}2425// DefaultArguments holds the default settings for the mysqld_exporter integration.26var DefaultArguments = Arguments{27LockWaitTimeout: 2,28InfoSchemaProcessList: InfoSchemaProcessList{29ProcessesByUser: true,30ProcessesByHost: true,31},32InfoSchemaTables: InfoSchemaTables{33Databases: "*",34},35PerfSchemaEventsStatements: PerfSchemaEventsStatements{36Limit: 250,37TimeLimit: 86400,38TextLimit: 120,39},40PerfSchemaFileInstances: PerfSchemaFileInstances{41Filter: ".*",42RemovePrefix: "/var/lib/mysql",43},44Heartbeat: Heartbeat{45Database: "heartbeat",46Table: "heartbeat",47},48}4950// Arguments controls the mysql component.51type Arguments struct {52// DataSourceName to use to connect to MySQL.53DataSourceName rivertypes.Secret `river:"data_source_name,attr,optional"`5455// Collectors to mark as enabled in addition to the default.56EnableCollectors []string `river:"enable_collectors,attr,optional"`57// Collectors to explicitly mark as disabled.58DisableCollectors []string `river:"disable_collectors,attr,optional"`5960// Overrides the default set of enabled collectors with the given list.61SetCollectors []string `river:"set_collectors,attr,optional"`6263// Collector-wide options64LockWaitTimeout int `river:"lock_wait_timeout,attr,optional"`65LogSlowFilter bool `river:"log_slow_filter,attr,optional"`6667// Collector-specific config options68InfoSchemaProcessList InfoSchemaProcessList `river:"info_schema.processlist,block,optional"`69InfoSchemaTables InfoSchemaTables `river:"info_schema.tables,block,optional"`70PerfSchemaEventsStatements PerfSchemaEventsStatements `river:"perf_schema.eventsstatements,block,optional"`71PerfSchemaFileInstances PerfSchemaFileInstances `river:"perf_schema.file_instances,block,optional"`72Heartbeat Heartbeat `river:"heartbeat,block,optional"`73MySQLUser MySQLUser `river:"mysql.user,block,optional"`74}7576// InfoSchemaProcessList configures the info_schema.processlist collector77type InfoSchemaProcessList struct {78MinTime int `river:"min_time,attr,optional"`79ProcessesByUser bool `river:"processes_by_user,attr,optional"`80ProcessesByHost bool `river:"processes_by_host,attr,optional"`81}8283// InfoSchemaTables configures the info_schema.tables collector84type InfoSchemaTables struct {85Databases string `river:"databases,attr,optional"`86}8788// PerfSchemaEventsStatements configures the perf_schema.eventsstatements collector89type PerfSchemaEventsStatements struct {90Limit int `river:"limit,attr,optional"`91TimeLimit int `river:"time_limit,attr,optional"`92TextLimit int `river:"text_limit,attr,optional"`93}9495// PerfSchemaFileInstances configures the perf_schema.file_instances collector96type PerfSchemaFileInstances struct {97Filter string `river:"filter,attr,optional"`98RemovePrefix string `river:"remove_prefix,attr,optional"`99}100101// Heartbeat controls the heartbeat collector102type Heartbeat struct {103Database string `river:"database,attr,optional"`104Table string `river:"table,attr,optional"`105UTC bool `river:"utc,attr,optional"`106}107108// MySQLUser controls the mysql.user collector109type MySQLUser struct {110Privileges bool `river:"privileges,attr,optional"`111}112113// UnmarshalRiver implements River unmarshalling for Config.114func (c *Arguments) UnmarshalRiver(f func(interface{}) error) error {115*c = DefaultArguments116117type args Arguments118return f((*args)(c))119}120121func (a *Arguments) Convert() *mysqld_exporter.Config {122return &mysqld_exporter.Config{123DataSourceName: config_util.Secret(a.DataSourceName),124EnableCollectors: a.EnableCollectors,125DisableCollectors: a.DisableCollectors,126SetCollectors: a.SetCollectors,127LockWaitTimeout: a.LockWaitTimeout,128LogSlowFilter: a.LogSlowFilter,129InfoSchemaProcessListMinTime: a.InfoSchemaProcessList.MinTime,130InfoSchemaProcessListProcessesByUser: a.InfoSchemaProcessList.ProcessesByUser,131InfoSchemaProcessListProcessesByHost: a.InfoSchemaProcessList.ProcessesByHost,132InfoSchemaTablesDatabases: a.InfoSchemaTables.Databases,133PerfSchemaEventsStatementsLimit: a.PerfSchemaEventsStatements.Limit,134PerfSchemaEventsStatementsTimeLimit: a.PerfSchemaEventsStatements.TimeLimit,135PerfSchemaEventsStatementsTextLimit: a.PerfSchemaEventsStatements.TextLimit,136PerfSchemaFileInstancesFilter: a.PerfSchemaFileInstances.Filter,137PerfSchemaFileInstancesRemovePrefix: a.PerfSchemaFileInstances.RemovePrefix,138HeartbeatDatabase: a.Heartbeat.Database,139HeartbeatTable: a.Heartbeat.Table,140HeartbeatUTC: a.Heartbeat.UTC,141MySQLUserPrivileges: a.MySQLUser.Privileges,142}143}144145146