SQLServer
SQL Server Collector collects SQL Server waitstats
, database_io
and other related metrics.
Configuration¶
SQL Server version >= 2008, tested version:
- 2017
- 2019
- 2022
Prerequisites¶
-
SQL Server version >= 2019
-
Create a user:
Linux、Windows:
USE master;
GO
CREATE LOGIN [datakit] WITH PASSWORD = N'yourpassword';
GO
GRANT VIEW SERVER STATE TO [datakit];
GO
GRANT VIEW ANY DEFINITION TO [datakit];
GO
Aliyun RDS SQL Server:
Collector Configuration¶
Go to the conf.d/db
directory under the DataKit installation directory, copy sqlserver.conf.sample
and name it sqlserver.conf
. Examples are as follows:
[[inputs.sqlserver]]
## your sqlserver host ,example ip:port
host = ""
## your sqlserver user,password
user = ""
password = ""
## Instance name. If not specified, a connection to the default instance is made.
instance_name = ""
## Database name to query. Default is master.
database = "master"
## by default, support TLS 1.2 and above.
## set to true if server side uses TLS 1.0 or TLS 1.1
allow_tls10 = false
## connection timeout default: 30s
connect_timeout = "30s"
## Metric name in metric_exclude_list will not be collected.
metric_exclude_list = [""]
## parameters to be added to the connection string
## Examples:
## "encrypt=disable"
## "certificate=/path/to/cert.pem"
## reference: https://github.com/microsoft/go-mssqldb?tab=readme-ov-file#connection-parameters-and-dsn
#
# connection_parameters = "encrypt=disable"
## (optional) collection interval, default is 10s
interval = "10s"
## Set true to enable election
election = true
## configure db_filter to filter out metrics from certain databases according to their database_name tag.
## If leave blank, no metric from any database is filtered out.
# db_filter = ["some_db_instance_name", "other_db_instance_name"]
## collect object
[inputs.sqlserver.object]
# Set true to enable collecting objects
enabled = true
# interval to collect sqlserver object which will be greater than collection interval
interval = "600s"
## Run a custom SQL query and collect corresponding metrics.
#
# [[inputs.sqlserver.custom_queries]]
# sql = '''
# select counter_name,cntr_type,cntr_value
# from sys.dm_os_performance_counters
# '''
# metric = "sqlserver_custom_stat"
# tags = ["counter_name","cntr_type"]
# interval = "10s"
# fields = ["cntr_value"]
# [inputs.sqlserver.log]
# files = []
# #grok pipeline script path
# pipeline = "sqlserver.p"
[inputs.sqlserver.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
After configuration, restart DataKit.
The collector can now be turned on by ConfigMap Injection Collector Configuration.
Log Collector Configuration¶
Note
DataKit must be installed on the host where SQLServer is running.
To collect SQL Server logs, enable files
in sqlserver.conf and write to the absolute path of the SQL Server log file. For example:
When log collection is turned on, a log with a log (aka source) ofsqlserver
is collected.
Metrics¶
For all of the following data collections, the global election tags will be added automatically, we can add extra tags in [inputs.sqlserver.tags]
if needed:
sqlserver
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
committed_memory | The amount of memory committed to the memory manager. Version > 2008 Type: int Unit: digital,B |
cpu_count | Specifies the number of logical CPUs on the system. Not nullable Type: int Unit: count |
db_offline | Num of database state in offline Type: int Unit: count |
db_online | Num of database state in online Type: int Unit: count |
db_recovering | Num of database state in recovering Type: int Unit: count |
db_recovery_pending | Num of database state in recovery_pending Type: int Unit: count |
db_restoring | Num of database state in restoring Type: int Unit: count |
db_suspect | Num of database state in suspect Type: int Unit: count |
physical_memory | Total physical memory on the machine. Version > 2008 Type: int Unit: digital,B |
server_memory | Memory used Type: int Unit: digital,B |
target_memory | Amount of memory that can be consumed by the memory manager. When this value is larger than the committed memory, then the memory manager will try to obtain more memory. When it is smaller, the memory manager will try to shrink the amount of memory committed. Version > 2008 Type: int Unit: digital,B |
uptime | Total time elapsed since the last computer restart Type: int Unit: time,ms |
virtual_memory | Amount of virtual memory available to the process in user mode. Version > 2008 Type: int Unit: digital,B |
sqlserver_performance
¶
Tags & Fields | Description |
---|---|
counter_name ( tag ) |
Name of the counter. To get more information about a counter, this is the name of the topic to select from the list of counters in Use SQL Server Objects. |
counter_type ( tag ) |
Type of the counter |
instance ( tag ) |
Name of the specific instance of the counter |
object_name ( tag ) |
Category to which this counter belongs. |
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
active_transactions | Number of active transactions across all databases on the SQL Server instance. Type: int Unit: count |
auto_param_attempts | Number of auto-parameterization attempts per second. Type: int Unit: count |
backup_restore_throughput | Read/write throughput for backup and restore operations of a database per second. Type: int Unit: count |
batch_requests | The number of batch requests per second. Type: int Unit: count |
buffer_cache_hit_ratio | The ratio of data pages found and read from the buffer cache over all data page requests. Type: float Unit: percent,percent |
cache_object_counts | Number of cache objects in the cache. Type: int Unit: count |
cache_pages | Number of 8-kilobyte (KB) pages used by cache objects. Type: int Unit: count |
checkpoint_pages | The number of pages flushed to disk per second by a checkpoint or other operation that require all dirty pages to be flushed. Type: int Unit: count |
cntr_value | Current value of the counter Type: int Unit: count |
connection_memory | Specifies the total amount of dynamic memory the server is using for maintaining connections. Type: int Unit: digital,KB |
database_cache_memory | Specifies the amount of memory the server is currently using for the database pages cache. Type: int Unit: digital,KB |
deadlocks | Number of lock requests per second that resulted in a deadlock. Type: int Unit: count |
failed_auto_params | Number of failed auto-parameterization attempts per second. Type: int Unit: count |
flow_control | Number of times flow-control initiated in the last second. Flow Control Time (ms/sec) divided by Flow Control/sec is the average time per wait. Type: int Unit: count |
full_scans | Number of unrestricted full scans per second. These can be either base-table or full-index scans. Type: int Unit: count |
granted_workspace_memory | Specifies the total amount of memory currently granted to executing processes, such as hash, sort, bulk copy, and index creation operations. Type: int Unit: digital,KB |
latch_waits | Number of latch requests that could not be granted immediately. Type: int Unit: count |
lock_memory | Specifies the total amount of dynamic memory the server is using for locks. Type: int Unit: digital,KB |
lock_waits | The number of times per second that SQL Server is unable to retain a lock right away for a resource. Type: int Unit: count |
log_bytes_flushed | Total number of log bytes flushed. Type: int Unit: digital,B |
log_flush_wait_time | Total wait time (in milliseconds) to flush the log. On an Always On secondary database, this value indicates the wait time for log records to be hardened to disk. Type: int Unit: time,ms |
log_flushes | Number of log flushes per second. Type: int Unit: count |
log_pool_memory | Total amount of dynamic memory the server is using for Log Pool. Type: int Unit: digital,KB |
longest_transaction_running_time | The time (in seconds) that the oldest active transaction has been running. Only works if database is under read committed snapshot isolation level. Type: int Unit: time,ms |
memory_grants_outstanding | Specifies the total number of processes that have successfully acquired a workspace memory grant. Type: int Unit: count |
memory_grants_pending | Specifies the total number of processes waiting for a workspace memory grant. Type: int Unit: count |
optimizer_memory | Specifies the total amount of dynamic memory the server is using for query optimization. Type: int Unit: digital,KB |
page_life_expectancy | Duration that a page resides in the buffer pool. Type: int Unit: time,ms |
page_reads | Indicates the number of physical database page reads that are issued per second. This statistic displays the total number of physical page reads across all databases. Type: int Unit: count |
page_splits | The number of page splits per second. Type: int Unit: count |
page_writes | Indicates the number of physical database page writes that are issued per second. Type: int Unit: count |
processes_blocked | The number of processes blocked. Type: int Unit: count |
safe_auto_params | Number of safe auto-parameterization attempts per second. Type: int Unit: count |
sql_cache_memory | Specifies the amount of memory the server is using for the dynamic SQL cache. Type: int Unit: digital,KB |
sql_compilations | The number of SQL compilations per second. Type: int Unit: count |
sql_re_compilations | The number of SQL re-compilations per second. Type: int Unit: count |
stolen_server_memory | Specifies the amount of memory the server is using for purposes other than database pages. Type: int Unit: digital,KB |
total_server_memory | Specifies the amount of memory the server has committed using the memory manager. Type: int Unit: digital,KB |
transaction_delay | Total delay in waiting for unterminated commit acknowledgment for all the current transactions, in milliseconds. Type: int Unit: count |
transactions | Number of transactions started for the SQL Server instance per second. Type: int Unit: count |
user_connections | Number of user connections. Type: int Unit: count |
version_cleanup_rate | The cleanup rate of the version store in tempdb. Type: int Unit: digital,KB |
version_generation_rate | The generation rate of the version store in tempdb. Type: int Unit: digital,KB |
version_store_size | The size of the version store in tempdb. Type: int Unit: digital,KB |
write_transactions | Number of transactions that wrote to all databases on the SQL Server instance and committed, in the last second. Type: int Unit: count |
sqlserver_waitstats
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
wait_category ( tag ) |
Wait category info |
wait_type ( tag ) |
Name of the wait type. For more information, see Types of Waits, later in this topic |
max_wait_time_ms | Maximum wait time on this wait type. Type: int Unit: time,ms |
resource_wait_ms | wait_time_ms-signal_wait_time_ms Type: int Unit: time,ms |
signal_wait_time_ms | Difference between the time that the waiting thread was signaled and when it started running Type: int Unit: time,ms |
wait_time_ms | Total wait time for this wait type in milliseconds. This time is inclusive of signal_wait_time_ms Type: int Unit: time,ms |
waiting_tasks_count | Number of waits on this wait type. This counter is incremented at the start of each wait. Type: int Unit: count |
sqlserver_database_io
¶
Tags & Fields | Description |
---|---|
database_name ( tag ) |
Database name |
file_type ( tag ) |
Description of the file type, ROWS/LOG/FILESTREAM/FULLTEXT (Full-text catalogs earlier than SQL Server 2008.) |
logical_filename ( tag ) |
Logical name of the file in the database |
physical_filename ( tag ) |
Operating-system file name. |
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
read_bytes | Total number of bytes read on this file Type: int Unit: digital,B |
read_latency_ms | Total time, in milliseconds, that the users waited for reads issued on the file. Type: int Unit: time,ms |
reads | Number of reads issued on the file. Type: int Unit: count |
rg_read_stall_ms | Does not apply to:: SQL Server 2008 through SQL Server 2012 (11.x).Total IO latency introduced by IO resource governance for reads Type: int Unit: time,ms |
rg_write_stall_ms | Does not apply to:: SQL Server 2008 through SQL Server 2012 (11.x).Total IO latency introduced by IO resource governance for writes. Is not nullable. Type: int Unit: time,ms |
write_bytes | Total number of bytes written to the file Type: int Unit: digital,B |
write_latency_ms | Total time, in milliseconds, that users waited for writes to be completed on the file Type: int Unit: time,ms |
writes | Number of writes issued on the file. Type: int Unit: count |
sqlserver_schedulers
¶
Tags & Fields | Description |
---|---|
cpu_id ( tag ) |
CPU ID assigned to the scheduler. |
scheduler_id ( tag ) |
ID of the scheduler. All schedulers that are used to run regular queries have ID numbers less than 1048576. Those schedulers that have IDs greater than or equal to 1048576 are used internally by SQL Server, such as the dedicated administrator connection scheduler. Is not nullable. |
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
active_workers_count | Number of workers that are active. An active worker is never preemptive, must have an associated task, and is either running, runnable, or suspended. Is not nullable. Type: int Unit: count |
context_switches_count | Number of context switches that have occurred on this scheduler Type: int Unit: count |
current_tasks_count | Number of current tasks that are associated with this scheduler. Type: int Unit: count |
current_workers_count | Number of workers that are associated with this scheduler. This count includes workers that are not assigned any task. Is not nullable. Type: int Unit: count |
is_idle | Scheduler is idle. No workers are currently running Type: bool Unit: N/A |
is_online | If SQL Server is configured to use only some of the available processors on the server, this configuration can mean that some schedulers are mapped to processors that are not in the affinity mask. If that is the case, this column returns 0. This value means that the scheduler is not being used to process queries or batches. Type: bool Unit: N/A |
load_factor | Internal value that indicates the perceived load on this scheduler Type: int Unit: count |
pending_disk_io_count | Number of pending I/Os that are waiting to be completed. Type: int Unit: count |
preemptive_switches_count | Number of times that workers on this scheduler have switched to the preemptive mode Type: int Unit: count |
runnable_tasks_count | Number of workers, with tasks assigned to them, that are waiting to be scheduled on the runnable queue. Type: int Unit: count |
total_cpu_usage_ms | Applies to: SQL Server 2016 (13.x) and laterTotal CPU consumed by this scheduler as reported by non-preemptive workers. Type: int Unit: time,ms |
total_scheduler_delay_ms | Applies to: SQL Server 2016 (13.x) and laterThe time between one worker switching out and another one switching in Type: int Unit: time,ms |
work_queue_count | Number of tasks in the pending queue. These tasks are waiting for a worker to pick them up Type: int Unit: count |
yield_count | Internal value that is used to indicate progress on this scheduler. This value is used by the Scheduler Monitor to determine whether a worker on the scheduler is not yielding to other workers on time. Type: int Unit: count |
sqlserver_volumespace
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
sqlserver_host ( tag ) |
Host name which installed SQLServer |
volume_mount_point ( tag ) |
Mount point at which the volume is rooted. Can return an empty string. Returns null on Linux operating system. |
volume_available_space_bytes | Available free space on the volume Type: int Unit: digital,B |
volume_total_space_bytes | Total size in bytes of the volume Type: int Unit: digital,B |
volume_used_space_bytes | Used size in bytes of the volume Type: int Unit: digital,B |
sqlserver_database_size
¶
Tags & Fields | Description |
---|---|
database_name ( tag ) |
Name of the database |
server ( tag ) |
The address of the server. The value is host:port |
data_size | The size of file of Rows Type: float Unit: digital,KB |
log_size | The size of file of Log Type: float Unit: digital,KB |
sqlserver_database_backup
¶
Tags & Fields | Description |
---|---|
database ( tag ) |
Database name |
server ( tag ) |
The address of the server. The value is host:port |
backup_count | The total count of successful backups made for a database Type: int Unit: count |
sqlserver_database_files
¶
Tags & Fields | Description |
---|---|
database ( tag ) |
Database name |
file_id ( tag ) |
ID of the file within database |
file_type ( tag ) |
File type: 0 = Rows, 1 = Log, 2 = File-Stream, 3 = Identified for informational purposes only, 4 = Full-text |
physical_name ( tag ) |
Operating-system file name |
server ( tag ) |
The address of the server. The value is host:port |
state ( tag ) |
Database file state: 0 = Online, 1 = Restoring, 2 = Recovering, 3 = Recovery_Pending, 4 = Suspect, 5 = Unknown, 6 = Offline, 7 = Defunct |
state_desc ( tag ) |
Description of the file state |
size | Current size of the database file Type: int Unit: digital,KB |
collector
¶
Tags & Fields | Description |
---|---|
instance ( tag ) |
Server addr of the instance |
job ( tag ) |
Server name of the instance |
up | Type: int Unit: - |
Object¶
database
¶
SQLServer object metrics( Version-1.78.0)
Tags & Fields | Description |
---|---|
database_type ( tag ) |
The type of the database. The value is SQLServer |
host ( tag ) |
The hostname of the SQLServer server |
name ( tag ) |
The name of the database. The value is host:port in default |
port ( tag ) |
The port of the SQLServer server |
server ( tag ) |
The server address of the SQLServer server |
version ( tag ) |
The version of the SQLServer server |
avg_query_time | The average time taken by a query to execute Type: float Unit: timeStamp,usec |
message | Summary of database information Type: string Unit: - |
qps | The number of queries executed by the database per second Type: float Unit: gauge |
tps | The number of transactions executed by the database per second Type: float Unit: gauge |
uptime | The number of seconds that the server has been up Type: int Unit: time,s |
message
Metric Field Structure¶
The basic structure of the message
field is as follows:
{
"setting": [ # settings information
{
"name": "recovery interval (min)",
"value": "123",
"value_in_use": "0",
"maximum": "10",
"minimum": "0",
"is_dynamic": true,
"is_advanced": true
}
...
],
"databases": [ # databases information
{
"name": "db1",
"owner_name": "dbo",
"collation": "SQL_Latin1_General_CP1_CI_AS",
"schemas": [
{
"name": "schema1",
"owner_name": "dbo",
"tables": [
{
"name": "table1",
"columns": [], # columns information
"indexes": [], # indexes information
"foreign_keys": [], # foreign keys information
"partitions": { # partitions information
"partition_count": 1
}
}
...
]
}
]
}
...
]
}
setting
¶
The data in the setting
field is derived from the sys.configurations
system view, which contains information about the global variables of the SQL Server instance. For detailed fields, you can refer to the SQL Server documentation.
databases
¶
The databases
field stores information about all databases on the SQL Server instance. The information for each database is as follows:
Field Name | Description | Type |
---|---|---|
name |
The name of the database | string |
owner_name |
The name of the database owner (e.g., dbo) | string |
collation |
The default collation of the database (e.g., SQL_Latin1_General_CP1_CI_AS) | string |
schemas |
A list containing table information | list |
schemas
¶
The schemas
field stores information about all schemas in the database. The information for each schema is as follows:
Field Name | Description | Type |
---|---|---|
name |
The name of the schema | string |
owner_name |
The name of the schema owner (e.g., dbo) | string |
tables |
A list containing table information | list |
The tables
field stores information about all tables included in the schema. The information for each table is as follows:
Field Name | Description | Type |
---|---|---|
name |
The name of the table | string |
columns |
A list containing column information | list |
indexes |
A list containing index information | list |
foreign_keys |
A list containing foreign key information | list |
partitions |
A dictionary containing partition information | dict |
The tables.columns
field stores information about all columns included in the table. The information for each column is as follows:
Field Name | Description | Type |
---|---|---|
name |
The name of the column | string |
data_type |
The data type of the column | string |
nullable |
Whether the column allows null values | string |
default |
The default value of the column | string |
The tables.indexes
field stores information about all indexes included in the table. The information for each index is as follows:
Field Name | Description | Type |
---|---|---|
name |
The name of the index | string |
type |
The type of the index | string |
is_unique |
Whether the index is unique | string |
is_primary_key |
Whether the index is a primary key | string |
column_names |
The names of the columns included in the index | string |
is_disabled |
Whether the index is disabled | string |
is_unique_constraint |
Whether the index is a unique constraint | string |
The tables.foreign_keys
field stores information about all foreign keys included in the table. The information for each foreign key is as follows:
Field Name | Description | Type |
---|---|---|
foreign_key_name |
The name of the foreign key | string |
referencing_table |
The name of the referencing table | string |
referenced_table |
The name of the referenced table | string |
referencing_columns |
The names of the referencing columns | string |
referenced_columns |
The names of the referenced columns | string |
update_action |
The cascading action for updates | string |
delete_action |
The cascading action for deletions | string |
The tables.partitions
field stores the number of all partitions included in the table. The specific field description is as follows:
Field Name | Description | Type |
---|---|---|
partition_count |
The number of partitions | number |
Logging¶
Following measurements are collected as logs with the level of info
.
sqlserver_lock_row
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
blocking_session_id | ID of the session that is blocking the request Type: int Unit: count |
cpu_time | CPU time in milliseconds that is used by the request Type: int Unit: time,ms |
host_name | Name of the client workstation that is specific to a session Type: string Unit: TODO |
last_request_end_time | Time of the last completion of a request on the session, in second Type: int Unit: time,ms |
last_request_start_time | Time at which the last request on the session began, in second Type: int Unit: time,ms |
logical_reads | Number of logical reads that have been performed by the request Type: int Unit: count |
login_name | SQL Server login name under which the session is currently executing Type: string Unit: TODO |
memory_usage | Number of 8-KB pages of memory used by this session Type: int Unit: count |
message | Text of the SQL query Type: string Unit: TODO |
row_count | Number of rows returned on the session up to this point Type: int Unit: count |
session_id | ID of the session to which this request is related Type: int Unit: count |
session_status | Status of the session Type: string Unit: TODO |
sqlserver_lock_table
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
db_name | Name of the database under which this resource is scoped Type: string Unit: TODO |
object_name | Name of the entity in a database with which a resource is associated Type: string Unit: TODO |
request_mode | Mode of the request Type: string Unit: TODO |
request_session_id | Session ID that currently owns this request Type: int Unit: count |
request_status | Current status of this request Type: string Unit: TODO |
resource_type | Represents the resource type Type: string Unit: TODO |
sqlserver_lock_dead
¶
Tags & Fields | Description |
---|---|
server ( tag ) |
The address of the server. The value is host:port |
blocking_object_name | Indicates the name of the object to which this partition belongs Type: string Unit: TODO |
blocking_session_id | ID of the session that is blocking the request Type: int Unit: count |
blocking_text | Text of the SQL query which is blocking Type: string Unit: TODO |
db_name | Name of the database under which this resource is scoped Type: string Unit: TODO |
message | Text of the SQL query which is blocking Type: string Unit: TODO |
request_mode | Mode of the request Type: string Unit: TODO |
request_session_id | Session ID that currently owns this request Type: int Unit: count |
requesting_text | Text of the SQL query which is requesting Type: string Unit: TODO |
resource_type | Represents the resource type Type: string Unit: TODO |
sqlserver_logical_io
¶
Tags & Fields | Description |
---|---|
message ( tag ) |
Text of the SQL query |
server ( tag ) |
The address of the server. The value is host:port |
avg_logical_io | Average number of logical writes and logical reads Type: int Unit: count |
creation_time | The Unix time at which the plan was compiled, in millisecond Type: int Unit: count |
execution_count | Number of times that the plan has been executed since it was last compiled Type: int Unit: count |
last_execution_time | Last time at which the plan started executing, unix time in millisecond Type: int Unit: count |
total_logical_io | Total number of logical writes and logical reads Type: int Unit: count |
total_logical_reads | Total amount of logical reads Type: int Unit: count |
total_logical_writes | Total amount of logical writes Type: int Unit: count |
sqlserver_worker_time
¶
Tags & Fields | Description |
---|---|
message ( tag ) |
Text of the SQL query |
server ( tag ) |
The address of the server. The value is host:port |
avg_worker_time | Average amount of CPU time, reported in milliseconds Type: int Unit: count |
creation_time | The Unix time at which the plan was compiled, in millisecond Type: int Unit: count |
execution_count | Number of times that the plan has been executed since it was last compiled Type: int Unit: count |
last_execution_time | Last time at which the plan started executing, unix time in millisecond Type: int Unit: count |
total_worker_time | Total amount of CPU time, reported in milliseconds Type: int Unit: count |
Pipeline for SQLServer logging¶
- SQL Server Common Log Pipeline
Example of common log text:
2021-05-28 10:46:07.78 spid10s 0 transactions rolled back in database 'msdb' (4:0). This is an informational message only. No user action is required
The list of extracted fields are as follows:
Field Name | Field Value | Description |
---|---|---|
msg |
spid... | log content |
time |
1622169967780000000 | nanosecond timestamp (as row protocol time) |
origin |
spid10s | source |
status |
info | As the log does not have an explicit field to describe the log level, the default is info. |