Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/sql_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (

func init() {
prometheus.MustRegister(version.NewCollector("sql_exporter"))
flag.StringVar(&cfg.TargetLabel, "config.target-label", "target", "Target label name")
}

func main() {
Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
// and serves to help us avoid overflow/wraparound issues.
const MaxInt32 int = 1<<31 - 1

var TargetLabel string

// Load attempts to parse the given config file and return a Config object.
func Load(configFile string) (*Config, error) {
klog.Infof("Loading configuration from %s", configFile)
Expand Down Expand Up @@ -630,7 +632,7 @@ func checkLabel(label string, ctx ...string) error {
if label == "" {
return fmt.Errorf("empty label defined in %s", strings.Join(ctx, " "))
}
if label == "job" || label == "instance" {
if label == "job" || label == TargetLabel {
return fmt.Errorf("reserved label %q redefined in %s", label, strings.Join(ctx, " "))
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func NewJob(jc *config.JobConfig, gc *config.GlobalConfig) (Job, errors.WithCont
for _, sc := range jc.StaticConfigs {
for tname, dsn := range sc.Targets {
constLabels := prometheus.Labels{
"job": jc.Name,
"instance": tname,
"job": jc.Name,
config.TargetLabel: tname,
}
for name, value := range sc.Labels {
// Shouldn't happen as there are sanity checks in config, but check nonetheless.
Expand Down
12 changes: 6 additions & 6 deletions target.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ type target struct {
conn *sql.DB
}

// NewTarget returns a new Target with the given instance name, data source name, collectors and constant labels.
// NewTarget returns a new Target with the given target name, data source name, collectors and constant labels.
// An empty target name means the exporter is running in single target mode: no synthetic metrics will be exported.
func NewTarget(
logContext, name, dsn string, ccs []*config.CollectorConfig, constLabels prometheus.Labels, gc *config.GlobalConfig) (
logContext, tname, dsn string, ccs []*config.CollectorConfig, constLabels prometheus.Labels, gc *config.GlobalConfig) (
Target, errors.WithContext,
) {
if name != "" {
logContext = fmt.Sprintf("%s, target=%q", logContext, name)
constLabels = prometheus.Labels{"instance": name}
if tname != "" {
logContext = fmt.Sprintf("%s, target=%q", logContext, tname)
constLabels = prometheus.Labels{config.TargetLabel: tname}
}

constLabelPairs := make([]*dto.LabelPair, 0, len(constLabels))
Expand All @@ -82,7 +82,7 @@ func NewTarget(
upDesc := NewAutomaticMetricDesc(logContext, upMetricName, upMetricHelp, prometheus.GaugeValue, constLabelPairs)
scrapeDurationDesc := NewAutomaticMetricDesc(logContext, scrapeDurationName, scrapeDurationHelp, prometheus.GaugeValue, constLabelPairs)
t := target{
name: name,
name: tname,
dsn: dsn,
collectors: collectors,
constLabels: constLabels,
Expand Down