Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .chloggen/sqlserver-ag-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
component: receiver/sqlserver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add Always On Availability Group database replica metrics sourced from sys.dm_hadr_database_replica_states.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [00000]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
Adds 6 new opt-in metrics for monitoring SQL Server Always On Availability Groups:
- sqlserver.availability_group.database_replica.estimated_data_loss (s)
- sqlserver.availability_group.database_replica.estimated_recovery_time (s)
- sqlserver.availability_group.database_replica.hardened_latency (s, SQL Server 2016+)
- sqlserver.availability_group.database_replica.queue.size (By) — log_send and redo queue sizes via sqlserver.availability_group.queue.type attribute
- sqlserver.availability_group.database_replica.log_send.rate (By/s)
- sqlserver.availability_group.database_replica.redo.rate (By/s)
Each metric includes sqlserver.availability_group.name, db.namespace, and sqlserver.replica.name attributes.
Requires direct connection to SQL Server with Always On Availability Groups enabled.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
109 changes: 109 additions & 0 deletions receiver/sqlserverreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,115 @@ Number of SQL attentions (client cancellation interrupts) received per second.
| ---- | ----------- | ---------- | --------- |
| {attentions}/s | Gauge | Double | Development |

### sqlserver.availability_group.database_replica.estimated_data_loss

Estimated potential data loss if a failover occurred now, expressed as the age in seconds of the oldest unsent log record on the primary replica.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| s | Gauge | Double | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |

### sqlserver.availability_group.database_replica.estimated_recovery_time

Estimated time in seconds to bring the secondary database replica up to date if a failover occurred now, based on the current redo queue size.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| s | Gauge | Double | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |

### sqlserver.availability_group.database_replica.hardened_latency

Time in seconds between a log record being generated on the primary replica and hardened to disk on the secondary replica.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| s | Gauge | Double | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |

### sqlserver.availability_group.database_replica.log_send.rate

Rate at which log data is being sent from the primary database replica to the secondary replica.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| By/s | Gauge | Int | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |

### sqlserver.availability_group.database_replica.queue.size

Amount of log data in the availability group queue that has not yet been processed.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| By | Gauge | Int | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |
| sqlserver.availability_group.queue.type | The type of availability group queue. | Str: ``log_send``, ``redo`` | Recommended | - |

### sqlserver.availability_group.database_replica.redo.rate

Rate at which log data is being redone on the secondary database replica.

This metric is only available when the receiver is configured to directly connect to SQL Server and the instance has Always On Availability Groups enabled.

| Unit | Metric Type | Value Type | Stability |
| ---- | ----------- | ---------- | --------- |
| By/s | Gauge | Int | Development |

#### Attributes

| Name | Description | Values | Requirement Level | Semantic Convention |
| ---- | ----------- | ------ | ----------------- | ------------------- |
| sqlserver.availability_group.name | The name of the SQL Server Availability Group. | Any Str | Recommended | - |
| db.namespace | The database name. | Any Str | Recommended | - |
| sqlserver.replica.name | The name of the SQL Server Availability Group replica. | Any Str | Recommended | - |

### sqlserver.computer.uptime

Computer uptime.
Expand Down
17 changes: 17 additions & 0 deletions receiver/sqlserverreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func createDefaultConfig() component.Config {
func setupQueries(cfg *Config) []string {
var queries []string

if isAvailabilityGroupQueryEnabled(&cfg.Metrics) {
queries = append(queries, getSQLServerAvailabilityGroupQuery(cfg.InstanceName))
}

if isDatabaseIOQueryEnabled(&cfg.Metrics) {
queries = append(queries, getSQLServerDatabaseIOQuery(cfg.InstanceName))
}
Expand Down Expand Up @@ -244,6 +248,19 @@ func setupLogsScrapers(params receiver.Settings, cfg *Config) ([]scraperhelper.C
return opts, nil
}

func isAvailabilityGroupQueryEnabled(metrics *metadata.MetricsConfig) bool {
if metrics == nil {
return false
}

return metrics.SqlserverAvailabilityGroupDatabaseReplicaEstimatedDataLoss.Enabled ||
metrics.SqlserverAvailabilityGroupDatabaseReplicaEstimatedRecoveryTime.Enabled ||
metrics.SqlserverAvailabilityGroupDatabaseReplicaHardenedLatency.Enabled ||
metrics.SqlserverAvailabilityGroupDatabaseReplicaQueueSize.Enabled ||
metrics.SqlserverAvailabilityGroupDatabaseReplicaLogSendRate.Enabled ||
metrics.SqlserverAvailabilityGroupDatabaseReplicaRedoRate.Enabled
}

func isDatabaseIOQueryEnabled(metrics *metadata.MetricsConfig) bool {
if metrics == nil {
return false
Expand Down
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func TestSetupQueries(t *testing.T) {

metricsMetadata, ok := metadata["metrics"].(map[string]any)
require.True(t, ok)
require.Len(t, metricsMetadata, 70, "Every time metrics are added or removed, the function `setupQueries` must "+
require.Len(t, metricsMetadata, 76, "Every time metrics are added or removed, the function `setupQueries` must "+
"be modified to properly account for the change. Please update `setupQueries` and then, "+
"and only then, update the expected metric count here.")
}
Loading
Loading