influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.63k stars 5.58k forks source link

Input Plugin SQL Server custom query #14264

Closed parvez-cet21 closed 11 months ago

parvez-cet21 commented 11 months ago

Please direct all support questsions to slack or the forums. Thank you.

I already asked over slack didn't get any response yet. I have a configuration like this and I want to run a custom query on SQL Server to fetch data from the test table into Postgresql Database. Expected Behavior I have to execute query SELECT * FROM test

telegraf.conf

# Global tags can be specified here in key="value" format.
[global_tags]
  # dc = "us-east-1" # will tag all metrics with dc=us-east-1
  # rack = "1a"
  ## Environment variables can be used as tags, and throughout the config file
  # user = "$USER"

# Configuration for telegraf agent
[agent]
  ## Default data collection interval for all inputs
  interval = "10s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  round_interval = true

  ## Telegraf will send metrics to outputs in batches of at most
  ## metric_batch_size metrics.
  ## This controls the size of writes that Telegraf sends to output plugins.
  metric_batch_size = 1000

  metric_buffer_limit = 10000

  collection_jitter = "0s"

  flush_interval = "10s"
  flush_jitter = "0s"
  precision = "0s"

  ## Override default hostname, if empty use os.Hostname()
  hostname = "52.146.17.139"
  ## If set to true, do no set the "host" tag in the telegraf agent.
  omit_hostname = false

# Publishes metrics to a postgresql database
[[outputs.postgresql]]
  connection = "postgres://test:XXXX@localhost/telegraf?sslmode=disable"

  ## Postgres schema to use.
  schema = "public"

  ## Templated statements to execute when creating a new table.
  create_templates = [
      '''CREATE TABLE {{ .table }} ({{ .columns }})''',
  ]
  add_column_templates = [
      '''ALTER TABLE {{ .table }} ADD COLUMN IF NOT EXISTS {{ .columns|join ", ADD COLUMN IF NOT EXISTS " }}''',
  ]
  tag_table_add_column_templates = [
      '''ALTER TABLE {{.table}} ADD COLUMN IF NOT EXISTS {{.columns|join ", ADD COLUMN IF NOT EXISTS "}}''',
  ]

###############################################################################
#                            SERVICE INPUT PLUGINS                            #
###############################################################################

# Read metrics from Microsoft SQL Server
[[inputs.sqlserver]]
  ## Specify instances to monitor with a list of connection strings.
  servers = [
     "Server=192.168.1.10;Port=1433;Database=master;User Id=SA;Password=XXXXX;app name=telegraf;log=1;",
  ]

  ## 0 value means no timeout
  # query_timeout = "0s"

  ## valid methods: "connection_string", "AAD"
  # auth_method = "connection_string"

  ## Possible values for database_type are - "SQLServer" or "AzureSQLDB" or "AzureSQLManagedInstance" or "AzureSQLPool"
  database_type = "SQLServer"

  ## A list of queries to include. If not specified, all the below listed queries are used.
  include_query = []

  ## A list of queries to explicitly ignore.
  exclude_query = ["SQLServerAvailabilityReplicaStates", "SQLServerDatabaseReplicaStates","SQLServerSchedulers", "SQLServerRecentBackups", "SQLServerDatabaseIO", "SQLServerMemoryClerks", "SQLServerProperties", "SQLServerRequests", "SQLServerVolumeSpace", "SQLServerCpu", "SQLServerPerformanceCounters", "SQLServerWaitStatsCategorized"]
  ## Version 2 - is compatible from SQL Server 2012 and later versions and also for SQL Azure DB
  # query_version = 2
telegraf-tiger[bot] commented 11 months ago

Hello! I recommend posting this question in our Community Slack or Community Forums, we have a lot of talented community members there who could help answer your question more quickly. You can also learn more about Telegraf by enrolling at InfluxDB University for free!

Heads up, this issue will be automatically closed after 7 days of inactivity. Thank you!

powersj commented 11 months ago

The SQL Server plugin is for collecting metrics about an SQL server instance. Please see the sql plugin instead for running custom queries.

Also please use the above slack and forums for questions. Thanks