Skip to content

Commit 9bffe94

Browse files
authored
[receiver/sqlserver] Enable more perf counter metrics (#33420)
**Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> These metrics already exist, and are all enabled by default, but were previously not being recorded when directly connecting to the SQL Server instance. This means these metrics will now be enabled by default across all systems and configurations. Metrics: ``` sqlserver.batch.request.rate sqlserver.batch.sql_compilation.rate sqlserver.batch.sql_recompilation.rate sqlserver.page.buffer_cache.hit_ratio sqlserver.user.connection.count ``` **Testing:** <Describe what testing was performed and which tests were added.> Updated tests to account for given metrics **Documentation** Updated documentation to show these metrics are now available on more systems than just Windows.
1 parent d6eaca8 commit 9bffe94

File tree

5 files changed

+118
-15
lines changed

5 files changed

+118
-15
lines changed

.chloggen/sqlserver_pc_metrics.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sqlserverreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Enable more perf counter metrics when directly connecting to SQL Server
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [33420]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This enables the following metrics by default on non Windows-based systems:
20+
`sqlserver.batch.request.rate`
21+
`sqlserver.batch.sql_compilation.rate`
22+
`sqlserver.batch.sql_recompilation.rate`
23+
`sqlserver.page.buffer_cache.hit_ratio`
24+
`sqlserver.user.connection.count`
25+
26+
# If your change doesn't affect end users or the exported elements of any package,
27+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
28+
# Optional: The change log or logs in which this entry should be included.
29+
# e.g. '[user]' or '[user, api]'
30+
# Include 'user' if the change is relevant to end users.
31+
# Include 'api' if there is a change to a library API.
32+
# Default: '[user]'
33+
change_logs: []

receiver/sqlserverreceiver/documentation.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ metrics:
1616
1717
Number of batch requests received by SQL Server.
1818
19-
This metric is only available when running on Windows.
20-
2119
| Unit | Metric Type | Value Type |
2220
| ---- | ----------- | ---------- |
2321
| {requests}/s | Gauge | Double |
@@ -26,8 +24,6 @@ This metric is only available when running on Windows.
2624
2725
Number of SQL compilations needed.
2826
29-
This metric is only available when running on Windows.
30-
3127
| Unit | Metric Type | Value Type |
3228
| ---- | ----------- | ---------- |
3329
| {compilations}/s | Gauge | Double |
@@ -36,8 +32,6 @@ This metric is only available when running on Windows.
3632
3733
Number of SQL recompilations needed.
3834
39-
This metric is only available when running on Windows.
40-
4135
| Unit | Metric Type | Value Type |
4236
| ---- | ----------- | ---------- |
4337
| {compilations}/s | Gauge | Double |
@@ -64,8 +58,6 @@ This metric is only available when running on Windows.
6458
6559
Pages found in the buffer pool without having to read from disk.
6660
67-
This metric is only available when running on Windows.
68-
6961
| Unit | Metric Type | Value Type |
7062
| ---- | ----------- | ---------- |
7163
| % | Gauge | Double |
@@ -210,8 +202,6 @@ This metric is only available when running on Windows.
210202
211203
Number of users connected to the SQL Server.
212204
213-
This metric is only available when running on Windows.
214-
215205
| Unit | Metric Type | Value Type |
216206
| ---- | ----------- | ---------- |
217207
| {connections} | Gauge | Int |

receiver/sqlserverreceiver/metadata.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ metrics:
5555
unit: "{connections}"
5656
gauge:
5757
value_type: int
58-
extended_documentation: This metric is only available when running on Windows.
5958
sqlserver.lock.wait_time.avg:
6059
enabled: true
6160
description: Average wait time for all lock requests that had to wait.
@@ -75,28 +74,24 @@ metrics:
7574
unit: "{requests}/s"
7675
gauge:
7776
value_type: double
78-
extended_documentation: This metric is only available when running on Windows.
7977
sqlserver.batch.sql_compilation.rate:
8078
enabled: true
8179
description: Number of SQL compilations needed.
8280
unit: "{compilations}/s"
8381
gauge:
8482
value_type: double
85-
extended_documentation: This metric is only available when running on Windows.
8683
sqlserver.batch.sql_recompilation.rate:
8784
enabled: true
8885
description: Number of SQL recompilations needed.
8986
unit: "{compilations}/s"
9087
gauge:
9188
value_type: double
92-
extended_documentation: This metric is only available when running on Windows.
9389
sqlserver.page.buffer_cache.hit_ratio:
9490
enabled: true
9591
description: Pages found in the buffer pool without having to read from disk.
9692
unit: "%"
9793
gauge:
9894
value_type: double
99-
extended_documentation: This metric is only available when running on Windows.
10095
sqlserver.page.life_expectancy:
10196
enabled: true
10297
description: Time a page will stay in the buffer pool.

receiver/sqlserverreceiver/scraper.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,15 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
172172
const counterKey = "counter"
173173
const valueKey = "value"
174174
// Constants are the columns for metrics from query
175+
const batchRequestRate = "Batch Requests/sec"
176+
const bufferCacheHitRatio = "Buffer cache hit ratio"
175177
const diskReadIOThrottled = "Disk Read IO Throttled/sec"
176178
const diskWriteIOThrottled = "Disk Write IO Throttled/sec"
177179
const lockWaits = "Lock Waits/sec"
178180
const processesBlocked = "Processes blocked"
181+
const sqlCompilationRate = "SQL Compilations/sec"
182+
const sqlReCompilationsRate = "SQL Re-Compilations/sec"
183+
const userConnCount = "User Connections"
179184

180185
rows, err := s.client.QueryRows(ctx)
181186

@@ -195,6 +200,22 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
195200
}
196201

197202
switch row[counterKey] {
203+
case batchRequestRate:
204+
val, err := strconv.ParseFloat(row[valueKey], 64)
205+
if err != nil {
206+
err = fmt.Errorf("row %d: %w", i, err)
207+
errs = append(errs, err)
208+
} else {
209+
s.mb.RecordSqlserverBatchRequestRateDataPoint(now, val)
210+
}
211+
case bufferCacheHitRatio:
212+
val, err := strconv.ParseFloat(row[valueKey], 64)
213+
if err != nil {
214+
err = fmt.Errorf("row %d: %w", i, err)
215+
errs = append(errs, err)
216+
} else {
217+
s.mb.RecordSqlserverPageBufferCacheHitRatioDataPoint(now, val)
218+
}
198219
case diskReadIOThrottled:
199220
errs = append(errs, s.mb.RecordSqlserverResourcePoolDiskThrottledReadRateDataPoint(now, row[valueKey]))
200221
case diskWriteIOThrottled:
@@ -209,6 +230,30 @@ func (s *sqlServerScraperHelper) recordDatabasePerfCounterMetrics(ctx context.Co
209230
}
210231
case processesBlocked:
211232
errs = append(errs, s.mb.RecordSqlserverProcessesBlockedDataPoint(now, row[valueKey]))
233+
case sqlCompilationRate:
234+
val, err := strconv.ParseFloat(row[valueKey], 64)
235+
if err != nil {
236+
err = fmt.Errorf("row %d: %w", i, err)
237+
errs = append(errs, err)
238+
} else {
239+
s.mb.RecordSqlserverBatchSQLCompilationRateDataPoint(now, val)
240+
}
241+
case sqlReCompilationsRate:
242+
val, err := strconv.ParseFloat(row[valueKey], 64)
243+
if err != nil {
244+
err = fmt.Errorf("row %d: %w", i, err)
245+
errs = append(errs, err)
246+
} else {
247+
s.mb.RecordSqlserverBatchSQLRecompilationRateDataPoint(now, val)
248+
}
249+
case userConnCount:
250+
val, err := strconv.ParseInt(row[valueKey], 10, 64)
251+
if err != nil {
252+
err = fmt.Errorf("row %d: %w", i, err)
253+
errs = append(errs, err)
254+
} else {
255+
s.mb.RecordSqlserverUserConnectionCountDataPoint(now, val)
256+
}
212257
}
213258
}
214259

receiver/sqlserverreceiver/testdata/expectedPerfCounters.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ resourceMetrics:
66
stringValue: 8cac97ac9b8f
77
scopeMetrics:
88
- metrics:
9+
- description: Number of batch requests received by SQL Server.
10+
gauge:
11+
dataPoints:
12+
- asDouble: 3375
13+
startTimeUnixNano: "1000000"
14+
timeUnixNano: "2000000"
15+
name: sqlserver.batch.request.rate
16+
unit: '{requests}/s'
17+
- description: Number of SQL compilations needed.
18+
gauge:
19+
dataPoints:
20+
- asDouble: 413
21+
startTimeUnixNano: "1000000"
22+
timeUnixNano: "2000000"
23+
name: sqlserver.batch.sql_compilation.rate
24+
unit: '{compilations}/s'
25+
- description: Number of SQL recompilations needed.
26+
gauge:
27+
dataPoints:
28+
- asDouble: 63
29+
startTimeUnixNano: "1000000"
30+
timeUnixNano: "2000000"
31+
name: sqlserver.batch.sql_recompilation.rate
32+
unit: '{compilations}/s'
933
- description: Number of lock requests resulting in a wait.
1034
gauge:
1135
dataPoints:
@@ -14,6 +38,14 @@ resourceMetrics:
1438
timeUnixNano: "2000000"
1539
name: sqlserver.lock.wait.rate
1640
unit: '{requests}/s'
41+
- description: Pages found in the buffer pool without having to read from disk.
42+
gauge:
43+
dataPoints:
44+
- asDouble: 100
45+
startTimeUnixNano: "1000000"
46+
timeUnixNano: "2000000"
47+
name: sqlserver.page.buffer_cache.hit_ratio
48+
unit: '%'
1749
- description: The number of processes that are currently blocked
1850
gauge:
1951
dataPoints:
@@ -44,6 +76,14 @@ resourceMetrics:
4476
timeUnixNano: "2000000"
4577
name: sqlserver.resource_pool.disk.throttled.write.rate
4678
unit: '{writes}/s'
79+
- description: Number of users connected to the SQL Server.
80+
gauge:
81+
dataPoints:
82+
- asInt: "3"
83+
startTimeUnixNano: "1000000"
84+
timeUnixNano: "2000000"
85+
name: sqlserver.user.connection.count
86+
unit: '{connections}'
4787
scope:
4888
name: otelcol/sqlserverreceiver
4989
version: latest

0 commit comments

Comments
 (0)