prometheus.exporter.mssql
prometheus.exporter.mssql
组件整合了sql_exporter
,用于收集Microsoft SQL Server的统计数据并作为Prometheus指标公开。
用法
prometheus.exporter.mssql "LABEL" {
connection_string = CONNECTION_STRING
}
参数
以下参数可用于配置导出器的行为。省略的字段将使用默认值。
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
connection_string | secret | 用于连接Microsoft SQL Server的连接字符串。 | 是 | |
max_idle_connections | int | 针对任何一个目标的最大空闲连接数。 | 3 | 否 |
max_open_connections | int | Maximum number of open connections to any one target. | 3 | 否 |
timeout | duration | 查询超时时间(秒)。 | "10s" | 否 |
query_config | string | MSSQL查询到Prometheus指标配置的行内字符串。 | 否 |
在sql_exporter
示例中展示了connection_string
参数的格式。
sqlserver://USERNAME_HERE:PASSWORD_HERE@SQLMI_HERE_ENDPOINT.database.windows.net:1433?encrypt=true&hostNameInCertificate=%2A.SQL_MI_DOMAIN_HERE.database.windows.net&trustservercertificate=true
如果指定,则query_config
参数必须是一个定义哪些MSSQL查询映射到自定义Prometheus指标的字面量字符串的YAML文档。通常使用另一个组件的导出加载query_config
。例如,
local.file.LABEL.content
remote.http.LABEL.content
remote.s3.LABEL.content
有关创建配置的详细信息,请参阅sql_exporter。
身份验证
默认情况下,在connection_string
参数内部使用的USERNAME
和PASSWORD
对应于SQL Server的用户名和密码。
如果Alloy和SQL Server运行在相同的Windows域中,那么你可以在connection_string
中使用参数authenticator=winsspi
进行身份验证,而不需要额外的凭证。
sqlserver://@<HOST>:<PORT>?authenticator=winsspi
如果您想使用Windows凭证进行身份验证,而不是SQL Server凭证,可以在connection_string
中使用参数authenticator=ntlm
。此时,USERNAME
和PASSWORD
对应于Windows用户名和密码。Windows域可能需要以反斜杠\
为后缀添加到用户名之前。
sqlserver://<DOMAIN\USERNAME>:<PASSWORD>@<HOST>:<PORT>?authenticator=ntlm
块
prometheus.exporter.mssql
组件不支持任何块,并且完全通过参数进行配置。
导出的字段
以下字段被导出,并且可以被其他组件引用。
名称 | 类型 | 描述 |
---|---|---|
目标 | list(map(string)) | 可以用来收集导出器的度量指标的目标。 |
例如,可以将targets
传递给一个discovery.relabel
组件来重写目标的标签集,或传递给一个收集公开指标的prometheus.scrape
组件。
导出的目标使用配置的由run
命令指定的内存中流量地址。
组件健康状态
prometheus.exporter.mssql
仅在提供无效配置时报告为不健康。在这些情况下,导出字段保留其最后的健康值。
调试信息
prometheus.exporter.mssql
没有暴露任何特定组件的调试信息。
调试度量指标
prometheus.exporter.mssql
没有暴露任何特定组件的调试度量指标。
示例
此示例使用一个prometheus.scrape
组件来收集来自prometheus.exporter.mssql
的指标。
prometheus.exporter.mssql "example" {
connection_string = "sqlserver://user:pass@localhost:1433"
}
// Configure a prometheus.scrape component to collect mssql metrics.
prometheus.scrape "demo" {
targets = prometheus.exporter.mssql.example.targets
forward_to = [prometheus.remote_write.demo.receiver]
}
prometheus.remote_write "demo" {
endpoint {
url = PROMETHEUS_REMOTE_WRITE_URL
basic_auth {
username = USERNAME
password = PASSWORD
}
}
}
替换以下
PROMETHEUS_REMOTE_WRITE_URL
:要将指标发送到的Prometheus远程写入兼容服务器的URL。USERNAME
:用于对远程写入API进行身份验证的用户名。PASSWORD
:用于对远程写入API进行身份验证的密码。
自定义度量指标
您可以使用可选的query_config
参数来检索MSSQL实例的自定义Prometheus度量指标。
如果这样定义,新配置将用于查询您的MSSQL实例并创建任何定义的Prometheus度量指标。如果您想在默认度量指标之上实施额外的度量指标,则必须使用默认配置作为基础。
此集成使用的默认配置如下
collector_name: mssql_standard
metrics:
- metric_name: mssql_local_time_seconds
type: gauge
help: 'Local time in seconds since epoch (Unix time).'
values: [unix_time]
query: |
SELECT DATEDIFF(second, '19700101', GETUTCDATE()) AS unix_time
- metric_name: mssql_connections
type: gauge
help: 'Number of active connections.'
key_labels:
- db
values: [count]
query: |
SELECT DB_NAME(sp.dbid) AS db, COUNT(sp.spid) AS count
FROM sys.sysprocesses sp
GROUP BY DB_NAME(sp.dbid)
#
# Collected from sys.dm_os_performance_counters
#
- metric_name: mssql_deadlocks_total
type: counter
help: 'Number of lock requests that resulted in a deadlock.'
values: [cntr_value]
query: |
SELECT cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Number of Deadlocks/sec' AND instance_name = '_Total'
- metric_name: mssql_user_errors_total
type: counter
help: 'Number of user errors.'
values: [cntr_value]
query: |
SELECT cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Errors/sec' AND instance_name = 'User Errors'
- metric_name: mssql_kill_connection_errors_total
type: counter
help: 'Number of severe errors that caused SQL Server to kill the connection.'
values: [cntr_value]
query: |
SELECT cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Errors/sec' AND instance_name = 'Kill Connection Errors'
- metric_name: mssql_page_life_expectancy_seconds
type: gauge
help: 'The minimum number of seconds a page will stay in the buffer pool on this node without references.'
values: [cntr_value]
query: |
SELECT top(1) cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Page life expectancy'
- metric_name: mssql_batch_requests_total
type: counter
help: 'Number of command batches received.'
values: [cntr_value]
query: |
SELECT cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Batch Requests/sec'
- metric_name: mssql_log_growths_total
type: counter
help: 'Number of times the transaction log has been expanded, per database.'
key_labels:
- db
values: [cntr_value]
query: |
SELECT rtrim(instance_name) AS db, cntr_value
FROM sys.dm_os_performance_counters WITH (NOLOCK)
WHERE counter_name = 'Log Growths' AND instance_name <> '_Total'
- metric_name: mssql_buffer_cache_hit_ratio
type: gauge
help: 'Ratio of requests that hit the buffer cache'
values: [BufferCacheHitRatio]
query: |
SELECT (a.cntr_value * 1.0 / b.cntr_value) * 100.0 as BufferCacheHitRatio
FROM sys.dm_os_performance_counters a
JOIN (SELECT cntr_value, OBJECT_NAME
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Buffer cache hit ratio base'
AND OBJECT_NAME = 'SQLServer:Buffer Manager') b ON a.OBJECT_NAME = b.OBJECT_NAME
WHERE a.counter_name = 'Buffer cache hit ratio'
AND a.OBJECT_NAME = 'SQLServer:Buffer Manager'
- metric_name: mssql_checkpoint_pages_sec
type: gauge
help: 'Checkpoint Pages Per Second'
values: [cntr_value]
query: |
SELECT cntr_value
FROM sys.dm_os_performance_counters
WHERE [counter_name] = 'Checkpoint pages/sec'
#
# Collected from sys.dm_io_virtual_file_stats
#
- metric_name: mssql_io_stall_seconds_total
type: counter
help: 'Stall time in seconds per database and I/O operation.'
key_labels:
- db
value_label: operation
values:
- read
- write
query_ref: mssql_io_stall
#
# Collected from sys.dm_os_process_memory
#
- metric_name: mssql_resident_memory_bytes
type: gauge
help: 'SQL Server resident memory size (AKA working set).'
values: [resident_memory_bytes]
query_ref: mssql_process_memory
- metric_name: mssql_virtual_memory_bytes
type: gauge
help: 'SQL Server committed virtual memory size.'
values: [virtual_memory_bytes]
query_ref: mssql_process_memory
- metric_name: mssql_available_commit_memory_bytes
type: gauge
help: 'SQL Server available to be committed memory size.'
values: [available_commit_limit_bytes]
query_ref: mssql_process_memory
- metric_name: mssql_memory_utilization_percentage
type: gauge
help: 'The percentage of committed memory that is in the working set.'
values: [memory_utilization_percentage]
query_ref: mssql_process_memory
- metric_name: mssql_page_fault_count_total
type: counter
help: 'The number of page faults that were incurred by the SQL Server process.'
values: [page_fault_count]
query_ref: mssql_process_memory
#
# Collected from sys.dm_os_sys_info
#
- metric_name: mssql_server_total_memory_bytes
type: gauge
help: 'SQL Server committed memory in the memory manager.'
values: [committed_memory_bytes]
query_ref: mssql_os_sys_info
- metric_name: mssql_server_target_memory_bytes
type: gauge
help: 'SQL Server target committed memory set for the memory manager.'
values: [committed_memory_target_bytes]
query_ref: mssql_os_sys_info
#
# Collected from sys.dm_os_sys_memory
#
- metric_name: mssql_os_memory
type: gauge
help: 'OS physical memory, used and available.'
value_label: 'state'
values: [used, available]
query: |
SELECT
(total_physical_memory_kb - available_physical_memory_kb) * 1024 AS used,
available_physical_memory_kb * 1024 AS available
FROM sys.dm_os_sys_memory
- metric_name: mssql_os_page_file
type: gauge
help: 'OS page file, used and available.'
value_label: 'state'
values: [used, available]
query: |
SELECT
(total_page_file_kb - available_page_file_kb) * 1024 AS used,
available_page_file_kb * 1024 AS available
FROM sys.dm_os_sys_memory
queries:
# Populates `mssql_io_stall` and `mssql_io_stall_total`
- query_name: mssql_io_stall
query: |
SELECT
cast(DB_Name(a.database_id) as varchar) AS [db],
sum(io_stall_read_ms) / 1000.0 AS [read],
sum(io_stall_write_ms) / 1000.0 AS [write]
FROM
sys.dm_io_virtual_file_stats(null, null) a
INNER JOIN sys.master_files b ON a.database_id = b.database_id AND a.file_id = b.file_id
GROUP BY a.database_id
# Populates `mssql_resident_memory_bytes`, `mssql_virtual_memory_bytes`, mssql_available_commit_memory_bytes,
# and `mssql_memory_utilization_percentage`, and `mssql_page_fault_count_total`
- query_name: mssql_process_memory
query: |
SELECT
physical_memory_in_use_kb * 1024 AS resident_memory_bytes,
virtual_address_space_committed_kb * 1024 AS virtual_memory_bytes,
available_commit_limit_kb * 1024 AS available_commit_limit_bytes,
memory_utilization_percentage,
page_fault_count
FROM sys.dm_os_process_memory
# Populates `mssql_server_total_memory_bytes` and `mssql_server_target_memory_bytes`.
- query_name: mssql_os_sys_info
query: |
SELECT
committed_kb * 1024 AS committed_memory_bytes,
committed_target_kb * 1024 AS committed_memory_target_bytes
FROM sys.dm_os_sys_info
兼容组件
prometheus.exporter.mssql
具有以下可以由以下组件消费的导出
- 消费目标的组件
注意
连接某些组件可能不合理,或者组件可能需要进一步配置才能正确连接。有关更多详细信息,请参阅链接的文档。