123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package mysqlreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver"
- import (
- "context"
- "time"
- "go.opentelemetry.io/collector/component"
- "go.opentelemetry.io/collector/config/confignet"
- "go.opentelemetry.io/collector/consumer"
- "go.opentelemetry.io/collector/receiver"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata"
- )
- func NewFactory() receiver.Factory {
- return receiver.NewFactory(
- metadata.Type,
- createDefaultConfig,
- receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
- }
- func createDefaultConfig() component.Config {
- cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
- cfg.CollectionInterval = 10 * time.Second
- return &Config{
- ScraperControllerSettings: cfg,
- AllowNativePasswords: true,
- Username: "root",
- NetAddr: confignet.NetAddr{
- Endpoint: "localhost:3306",
- Transport: "tcp",
- },
- MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
- StatementEvents: StatementEventsConfig{
- DigestTextLimit: defaultStatementEventsDigestTextLimit,
- Limit: defaultStatementEventsLimit,
- TimeLimit: defaultStatementEventsTimeLimit,
- },
- }
- }
- func createMetricsReceiver(
- _ context.Context,
- params receiver.CreateSettings,
- rConf component.Config,
- consumer consumer.Metrics,
- ) (receiver.Metrics, error) {
- cfg := rConf.(*Config)
- ns := newMySQLScraper(params, cfg)
- scraper, err := scraperhelper.NewScraper(metadata.Type, ns.scrape, scraperhelper.WithStart(ns.start),
- scraperhelper.WithShutdown(ns.shutdown))
- if err != nil {
- return nil, err
- }
- return scraperhelper.NewScraperControllerReceiver(
- &cfg.ScraperControllerSettings, params, consumer,
- scraperhelper.AddScraper(scraper),
- )
- }
|