Telegraf默认的Plugin中包括了对SQL Server的实现, 这个Plugin还包括了对Azure SQL PaaS的实现
# # Read metrics from Microsoft SQL Server [[inputs.sqlserver]] # ## Specify instances to monitor with a list of connection strings. # ## All connection parameters are optional. # ## By default, the host is localhost, listening on default port, TCP 1433. # ## for Windows, the user is the currently running AD user (SSO). # ## See https://github.com/denisenkom/go-mssqldb for detailed connection # ## parameters, in particular, tls connections can be created like so: # ## "encrypt=true;certificate=<cert>;hostNameInCertificate=<SqlServer host fqdn>" servers = [ "Server=localhost;Port=1433;User Id=telegraf;Password=<yourPassword>;app name=telegraf;log=1;" ] # # ## Optional parameter, setting this to 2 will use a new version # ## of the collection queries that break compatibility with the original # ## dashboards. query_version = 2 # # ## If you are using AzureDB, setting this to true will gather resource utilization metrics # # azuredb = false # # ## Possible queries: # ## - PerformanceCounters # ## - WaitStatsCategorized # ## - DatabaseIO # ## - DatabaseProperties # ## - CPUHistory # ## - DatabaseSize # ## - DatabaseStats # ## - MemoryClerk # ## - VolumeSpace # ## - PerformanceMetrics # ## - Schedulers # ## - AzureDBResourceStats # ## - AzureDBResourceGovernance # ## - SqlRequests # ## - ServerProperties # ## A list of queries to include. If not specified, all the above listed queries are used. # # include_query = [] # # ## A list of queries to explicitly ignore. # exclude_query = [ 'Schedulers' , 'SqlRequests']启动Telegraf之后,可以看到时已经加载的inputs和收集间隔
[root@SQL19N1 log]# systemctl status telegraf ● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB Loaded: loaded (/usr/lib/systemd/system/telegraf.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-05-26 14:19:07 UTC; 19min ago Docs: https://github.com/influxdata/telegraf Main PID: 12359 (telegraf) CGroup: /system.slice/telegraf.service └─12359 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d May 26 14:19:07 SQL19N1 systemd[1]: Started The plugin-driven server agent for reporting metrics into InfluxDB. May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Starting Telegraf 1.14.3 May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Loaded inputs: system cpu disk diskio kernel mem processes swap sqlserver May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Loaded aggregators: May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Loaded processors: May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Loaded outputs: influxdb May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! Tags enabled: host=SQL19N1 May 26 14:19:07 SQL19N1 telegraf[12359]: 2020-05-26T14:19:07Z I! [agent] Config: Interval:20s, Quiet:false, Hostname:"SQL19N1", Flush Interval:10sTelegraf on Windows
以管理员身份执行如下PowerShell命令
# 下载软件 wget https://dl.influxdata.com/telegraf/releases/telegraf-1.14.3_windows_amd64.zip · -OutFile "c:\temp\telegraf-1.14.3_windows_amd64.zip" # 解压缩到C:\Program Files\Telegraf Expand-Archive "c:\temp\telegraf-1.14.3_windows_amd64.zip", "C:\Program Files" # 将telegraf安装为windows服务 C:\"Program Files"\Telegraf\telegraf.exe --service install修改telegraf.conf中outputs.influxdb和添加inputs.sqlserver部分,这些内容和在Linux上的配置一样,就不赘述了。
conf修改完成后,可以先测试一下telegraf是否能正常启动,没问题的话就启动telegraf服务。
# 测试 C:\"Program Files"\Telegraf\telegraf.exe --config C:\"Program Files"\Telegraf\telegraf.conf --test # 启动服务 C:\"Program Files"\Telegraf\telegraf.exe --service start配置Grafana的数据源和Dashboard
登录Grafana后,在左侧的Configuration->Data Source中配置InfluxDB数据源,填写地址、账号、密码并设置为默认数据源,如下图
Dashboard,可以自己创建,也可以在采用公开社区的(感谢热心无私的大佬们)。这里,我采用SQL Servers by Jonathan Rioux。这个Dashboard中使用的Piechart不是Grafana预置的,所以还需要安装:
# Grafana所在Host安装,重启服务生效 grafana-cli plugins install grafana-piechart-panel systemctl restart grafana-server.service然后在Grafana界面,选择左侧的Dashboard->Import->填入Dashboard ID->Import,如下图: