Skip to content

Commit f876d49

Browse files
authored
[receiver/sqlserver] Add database status metric (#33064)
**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.--> This adds one more metric, `sqlserver.properties.db.status`, which shows the total number of databases in each state. **Link to tracking Issue:** <Issue number if applicable> #29865 **Testing:** <Describe what testing was performed and which tests were added.> Testing added, existing tests are passing.
1 parent 6eaf435 commit f876d49

17 files changed

+575
-10
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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: Add metrics for database status
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: [29865]
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+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/sqlserverreceiver/documentation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ metrics:
226226
enabled: true
227227
```
228228
229+
### sqlserver.database.count
230+
231+
The number of databases
232+
233+
This metric is only available when the receiver is configured to directly connect to SQL Server.
234+
235+
| Unit | Metric Type | Value Type |
236+
| ---- | ----------- | ---------- |
237+
| {databases} | Gauge | Int |
238+
239+
#### Attributes
240+
241+
| Name | Description | Values |
242+
| ---- | ----------- | ------ |
243+
| database.status | The current status of a database | Str: ``online``, ``restoring``, ``recovering``, ``pending_recovery``, ``suspect``, ``offline`` |
244+
229245
### sqlserver.database.io.read_latency
230246
231247
Total time that the users waited for reads issued on this file.

receiver/sqlserverreceiver/factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func setupQueries(cfg *Config) []string {
5151
queries = append(queries, getSQLServerPerformanceCounterQuery(cfg.InstanceName))
5252
}
5353

54+
if cfg.MetricsBuilderConfig.Metrics.SqlserverDatabaseCount.Enabled {
55+
queries = append(queries, getSQLServerPropertiesQuery(cfg.InstanceName))
56+
}
57+
5458
return queries
5559
}
5660

receiver/sqlserverreceiver/internal/metadata/generated_config.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_config_test.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_metrics.go

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/generated_metrics_test.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/sqlserverreceiver/internal/metadata/testdata/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ all_set:
77
enabled: true
88
sqlserver.batch.sql_recompilation.rate:
99
enabled: true
10+
sqlserver.database.count:
11+
enabled: true
1012
sqlserver.database.io.read_latency:
1113
enabled: true
1214
sqlserver.lock.wait.rate:
@@ -64,6 +66,8 @@ none_set:
6466
enabled: false
6567
sqlserver.batch.sql_recompilation.rate:
6668
enabled: false
69+
sqlserver.database.count:
70+
enabled: false
6771
sqlserver.database.io.read_latency:
6872
enabled: false
6973
sqlserver.lock.wait.rate:

receiver/sqlserverreceiver/metadata.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ attributes:
3939
file_type:
4040
description: The type of file being monitored.
4141
type: string
42+
database.status:
43+
description: The current status of a database
44+
type: string
45+
enum: [online, restoring, recovering, pending_recovery, suspect, offline]
4246

4347
metrics:
4448
sqlserver.user.connection.count:
@@ -222,6 +226,15 @@ metrics:
222226
input_type: string
223227
attributes: []
224228
extended_documentation: This metric is only available when the receiver is configured to directly connect to SQL Server.
229+
sqlserver.database.count:
230+
enabled: false
231+
description: The number of databases
232+
unit: "{databases}"
233+
gauge:
234+
value_type: int
235+
input_type: string
236+
attributes: [database.status]
237+
extended_documentation: This metric is only available when the receiver is configured to directly connect to SQL Server.
225238

226239
tests:
227240
config:

0 commit comments

Comments
 (0)