Skip to content

Commit

Permalink
add argument to disable disk-space-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishuraina committed Nov 14, 2024
1 parent 56dedb7 commit e89dd10
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Unreleased section should follow [Release Toolkit](https://github.com/newrelic/release-toolkit#render-markdown-and-update-markdown)

## Unreleased
### Enhancement
- Add `enable_disk_metrics_in_bytes` argument (default true), allows disabling disk-space-metrics

## v2.13.0 - 2024-10-08

Expand Down
1 change: 1 addition & 0 deletions src/args/argument_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ArgumentList struct {
CustomMetricsConfig string `default:"" help:"YAML configuration with one or more SQL queries to collect custom metrics"`
ShowVersion bool `default:"false" help:"Print build information and exit"`
ExtraConnectionURLArgs string `default:"" help:"Appends additional parameters to connection url. Ex. 'applicationintent=readonly&foo=bar'"`
EnableDiskMetricsInBytes bool `default:"true" help:"Enable collection of disk space metrics in bytes."`
}

// Validate validates SQL specific arguments
Expand Down
29 changes: 16 additions & 13 deletions src/metrics/instance_metric_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,6 @@ var instanceDefinitions = []*QueryDefinition{
Sleeping *int64 `db:"sleeping" metric_name:"instance.sleepingProcessesCount" source_type:"gauge"`
}{},
},
{
query: `SELECT Sum(total_bytes) AS total_disk_space FROM (
SELECT DISTINCT
dovs.volume_mount_point,
dovs.available_bytes available_bytes,
dovs.total_bytes total_bytes
FROM sys.master_files mf WITH (nolock)
CROSS apply sys.Dm_os_volume_stats(mf.database_id, mf.file_id) dovs
) drives`,
dataModels: &[]struct {
TotalDiskSpace *int64 `db:"total_disk_space" metric_name:"instance.diskInBytes" source_type:"gauge"`
}{},
},
{
query: `SELECT Sum(runnable_tasks_count) AS runnable_tasks_count
FROM sys.dm_os_schedulers
Expand Down Expand Up @@ -172,3 +159,19 @@ type waitTimeModel struct {
WaitTime *int64 `db:"wait_time"`
WaitCount *int64 `db:"waiting_tasks_count"`
}

var diskMetricInBytesDefination = []*QueryDefinition{
{
query: `SELECT Sum(total_bytes) AS total_disk_space FROM (
SELECT DISTINCT
dovs.volume_mount_point,
dovs.available_bytes available_bytes,
dovs.total_bytes total_bytes
FROM sys.master_files mf WITH (nolock)
CROSS apply sys.Dm_os_volume_stats(mf.database_id, mf.file_id) dovs
) drives`,
dataModels: &[]struct {
TotalDiskSpace *int64 `db:"total_disk_space" metric_name:"instance.diskInBytes" source_type:"gauge"`
}{},
},
}
3 changes: 3 additions & 0 deletions src/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func PopulateInstanceMetrics(instanceEntity *integration.Entity, connection *con
if arguments.EnableBufferMetrics {
collectionList = append(collectionList, instanceBufferDefinitions...)
}
if arguments.EnableDiskMetricsInBytes {
collectionList = append(collectionList, diskMetricInBytesDefination...)
}

for _, queryDef := range collectionList {
models := queryDef.GetDataModels()
Expand Down
3 changes: 2 additions & 1 deletion src/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func Test_populateInstanceMetrics(t *testing.T) {
mock.ExpectClose()

args := args.ArgumentList{
EnableBufferMetrics: true,
EnableBufferMetrics: true,
EnableDiskMetricsInBytes: true,
}
PopulateInstanceMetrics(e, conn, args)

Expand Down

0 comments on commit e89dd10

Please sign in to comment.