Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/prometheus/exporter/mysql/mysql.go
4095 views
1
package mysql
2
3
import (
4
"github.com/grafana/agent/component"
5
"github.com/grafana/agent/component/prometheus/exporter"
6
"github.com/grafana/agent/pkg/integrations"
7
"github.com/grafana/agent/pkg/integrations/mysqld_exporter"
8
"github.com/grafana/agent/pkg/river/rivertypes"
9
config_util "github.com/prometheus/common/config"
10
)
11
12
func init() {
13
component.Register(component.Registration{
14
Name: "prometheus.exporter.mysql",
15
Args: Arguments{},
16
Exports: exporter.Exports{},
17
Build: exporter.New(createExporter, "mysql"),
18
})
19
}
20
21
func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {
22
a := args.(Arguments)
23
return a.Convert().NewIntegration(opts.Logger)
24
}
25
26
// DefaultArguments holds the default settings for the mysqld_exporter integration.
27
var DefaultArguments = Arguments{
28
LockWaitTimeout: 2,
29
InfoSchemaProcessList: InfoSchemaProcessList{
30
ProcessesByUser: true,
31
ProcessesByHost: true,
32
},
33
InfoSchemaTables: InfoSchemaTables{
34
Databases: "*",
35
},
36
PerfSchemaEventsStatements: PerfSchemaEventsStatements{
37
Limit: 250,
38
TimeLimit: 86400,
39
TextLimit: 120,
40
},
41
PerfSchemaFileInstances: PerfSchemaFileInstances{
42
Filter: ".*",
43
RemovePrefix: "/var/lib/mysql",
44
},
45
Heartbeat: Heartbeat{
46
Database: "heartbeat",
47
Table: "heartbeat",
48
},
49
}
50
51
// Arguments controls the mysql component.
52
type Arguments struct {
53
// DataSourceName to use to connect to MySQL.
54
DataSourceName rivertypes.Secret `river:"data_source_name,attr,optional"`
55
56
// Collectors to mark as enabled in addition to the default.
57
EnableCollectors []string `river:"enable_collectors,attr,optional"`
58
// Collectors to explicitly mark as disabled.
59
DisableCollectors []string `river:"disable_collectors,attr,optional"`
60
61
// Overrides the default set of enabled collectors with the given list.
62
SetCollectors []string `river:"set_collectors,attr,optional"`
63
64
// Collector-wide options
65
LockWaitTimeout int `river:"lock_wait_timeout,attr,optional"`
66
LogSlowFilter bool `river:"log_slow_filter,attr,optional"`
67
68
// Collector-specific config options
69
InfoSchemaProcessList InfoSchemaProcessList `river:"info_schema.processlist,block,optional"`
70
InfoSchemaTables InfoSchemaTables `river:"info_schema.tables,block,optional"`
71
PerfSchemaEventsStatements PerfSchemaEventsStatements `river:"perf_schema.eventsstatements,block,optional"`
72
PerfSchemaFileInstances PerfSchemaFileInstances `river:"perf_schema.file_instances,block,optional"`
73
Heartbeat Heartbeat `river:"heartbeat,block,optional"`
74
MySQLUser MySQLUser `river:"mysql.user,block,optional"`
75
}
76
77
// InfoSchemaProcessList configures the info_schema.processlist collector
78
type InfoSchemaProcessList struct {
79
MinTime int `river:"min_time,attr,optional"`
80
ProcessesByUser bool `river:"processes_by_user,attr,optional"`
81
ProcessesByHost bool `river:"processes_by_host,attr,optional"`
82
}
83
84
// InfoSchemaTables configures the info_schema.tables collector
85
type InfoSchemaTables struct {
86
Databases string `river:"databases,attr,optional"`
87
}
88
89
// PerfSchemaEventsStatements configures the perf_schema.eventsstatements collector
90
type PerfSchemaEventsStatements struct {
91
Limit int `river:"limit,attr,optional"`
92
TimeLimit int `river:"time_limit,attr,optional"`
93
TextLimit int `river:"text_limit,attr,optional"`
94
}
95
96
// PerfSchemaFileInstances configures the perf_schema.file_instances collector
97
type PerfSchemaFileInstances struct {
98
Filter string `river:"filter,attr,optional"`
99
RemovePrefix string `river:"remove_prefix,attr,optional"`
100
}
101
102
// Heartbeat controls the heartbeat collector
103
type Heartbeat struct {
104
Database string `river:"database,attr,optional"`
105
Table string `river:"table,attr,optional"`
106
UTC bool `river:"utc,attr,optional"`
107
}
108
109
// MySQLUser controls the mysql.user collector
110
type MySQLUser struct {
111
Privileges bool `river:"privileges,attr,optional"`
112
}
113
114
// UnmarshalRiver implements River unmarshalling for Config.
115
func (c *Arguments) UnmarshalRiver(f func(interface{}) error) error {
116
*c = DefaultArguments
117
118
type args Arguments
119
return f((*args)(c))
120
}
121
122
func (a *Arguments) Convert() *mysqld_exporter.Config {
123
return &mysqld_exporter.Config{
124
DataSourceName: config_util.Secret(a.DataSourceName),
125
EnableCollectors: a.EnableCollectors,
126
DisableCollectors: a.DisableCollectors,
127
SetCollectors: a.SetCollectors,
128
LockWaitTimeout: a.LockWaitTimeout,
129
LogSlowFilter: a.LogSlowFilter,
130
InfoSchemaProcessListMinTime: a.InfoSchemaProcessList.MinTime,
131
InfoSchemaProcessListProcessesByUser: a.InfoSchemaProcessList.ProcessesByUser,
132
InfoSchemaProcessListProcessesByHost: a.InfoSchemaProcessList.ProcessesByHost,
133
InfoSchemaTablesDatabases: a.InfoSchemaTables.Databases,
134
PerfSchemaEventsStatementsLimit: a.PerfSchemaEventsStatements.Limit,
135
PerfSchemaEventsStatementsTimeLimit: a.PerfSchemaEventsStatements.TimeLimit,
136
PerfSchemaEventsStatementsTextLimit: a.PerfSchemaEventsStatements.TextLimit,
137
PerfSchemaFileInstancesFilter: a.PerfSchemaFileInstances.Filter,
138
PerfSchemaFileInstancesRemovePrefix: a.PerfSchemaFileInstances.RemovePrefix,
139
HeartbeatDatabase: a.Heartbeat.Database,
140
HeartbeatTable: a.Heartbeat.Table,
141
HeartbeatUTC: a.Heartbeat.UTC,
142
MySQLUserPrivileges: a.MySQLUser.Privileges,
143
}
144
}
145
146