Skip to content

Commit

Permalink
SQL Server Receiver added (#9252)
Browse files Browse the repository at this point in the history
This makes use of the  windowsperfcounter watchers, using them to collect SQL Server metrics.
  • Loading branch information
StefanKurek authored Apr 15, 2022
1 parent 6417070 commit c7fe9fd
Show file tree
Hide file tree
Showing 31 changed files with 4,756 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
uses: actions/checkout@v3
- name: install iis
run: Install-WindowsFeature -name Web-Server -IncludeManagementTools
- name: Install SQL Server 2019 Dev
run: ./.github/workflows/scripts/sqlserver_install.ps1
- name: Setup Go
uses: actions/setup-go@v3
with:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/scripts/sqlserver_install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Install-SQLServer2019 {
Write-Host "Downloading SQL Server 2019..."
$Path = $env:TEMP
$Installer = "SQL2019-SSEI-Dev.exe"
$URL = "https://go.microsoft.com/fwlink/?linkid=866662"
Invoke-WebRequest $URL -OutFile $Path\$Installer

Write-Host "Installing SQL Server..."
Start-Process -FilePath $Path\$Installer -Args "/ACTION=INSTALL /IACCEPTSQLSERVERLICENSETERMS /QUIET" -Verb RunAs -Wait
Remove-Item $Path\$Installer
}

Install-SQLServer2019
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
### 🚩 Deprecations 🚩

### 🚀 New components 🚀

- `iisreceiver`: Add implementation of IIS Metric Receiver (#8832)
- `sqlserverreceiver`: Add implementation of SQL Server Metric Receiver (#8398)

### 💡 Enhancements 💡

### 🧰 Bug fixes 🧰
Expand Down
3 changes: 3 additions & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver v0.49.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver v0.49.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver v0.49.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver v0.0.0-00010101000000-000000000000 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.49.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver v0.49.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver v0.49.0 // indirect
Expand Down Expand Up @@ -775,6 +776,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywa

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver => ../../receiver/splunkhecreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver => ../../receiver/sqlserverreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver => ../../receiver/statsdreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver => ../../receiver/syslogreceiver
Expand Down
288 changes: 288 additions & 0 deletions cmd/configschema/go.sum

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver v0.0.0-00010101000000-000000000000
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver v0.49.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver v0.49.0
Expand Down Expand Up @@ -779,6 +780,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywa

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver => ./receiver/splunkhecreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver => ./receiver/sqlserverreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver => ./receiver/statsdreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver => ./receiver/syslogreceiver
Expand Down
377 changes: 377 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/skywalkingreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkhecreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/syslogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver"
Expand Down Expand Up @@ -215,6 +216,7 @@ func Components() (component.Factories, error) {
simpleprometheusreceiver.NewFactory(),
skywalkingreceiver.NewFactory(),
splunkhecreceiver.NewFactory(),
sqlserverreceiver.NewFactory(),
statsdreceiver.NewFactory(),
wavefrontreceiver.NewFactory(),
windowsperfcountersreceiver.NewFactory(),
Expand Down
4 changes: 4 additions & 0 deletions internal/components/receivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func TestDefaultReceivers(t *testing.T) {
{
receiver: "splunk_hec",
},
{
receiver: "sqlserver",
skipLifecyle: true, // Requires a running windows process
},
{
receiver: "statsd",
},
Expand Down
1 change: 1 addition & 0 deletions receiver/sqlserverreceiver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
26 changes: 26 additions & 0 deletions receiver/sqlserverreceiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Microsoft SQL Server Receiver

The `sqlserver` receiver grabs metrics about a Microsoft SQL Server instance using the Windows Performance Counters.
Because of this, it is a Windows only receiver.

Supported pipeline types: `metrics`

## Configuration

The following settings are optional:

- `collection_interval` (default = `10s`): The internal at which metrics should be emitted by this receiver.

Example:

```yaml
receivers:
sqlserver:
collection_interval: 10s
```
The full list of settings exposed for this receiver are documented [here](./config.go) with detailed sample configurations [here](./testdata/config.yaml).
## Metrics
Details about the metrics produced by this receiver can be found in [documentation.md](./documentation.md)
27 changes: 27 additions & 0 deletions receiver/sqlserverreceiver/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"

import (
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

// Config defines configuration for a sqlserver receiver.
type Config struct {
scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
Metrics metadata.MetricsSettings `mapstructure:"metrics"`
}
51 changes: 51 additions & 0 deletions receiver/sqlserverreceiver/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sqlserverreceiver

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

func TestValidate(t *testing.T) {
testCases := []struct {
desc string
cfg *Config
}{
{
desc: "valid config",
cfg: &Config{
Metrics: metadata.DefaultMetricsSettings(),
},
}, {
desc: "valid config with no metric settings",
cfg: &Config{},
},
{
desc: "default config is valid",
cfg: createDefaultConfig().(*Config),
},
}

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
actualErr := tc.cfg.Validate()
require.NoError(t, actualErr)
})
}
}
17 changes: 17 additions & 0 deletions receiver/sqlserverreceiver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate mdatagen --experimental-gen metadata.yaml

package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"
51 changes: 51 additions & 0 deletions receiver/sqlserverreceiver/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.)

# sqlserverreceiver

## Metrics

These are the metrics available for this scraper.

| Name | Description | Unit | Type | Attributes |
| ---- | ----------- | ---- | ---- | ---------- |
| **sqlserver.batch.request.rate** | Number of batch requests received by SQL Server. | {requests}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.batch.sql_compilation.rate** | Number of SQL compilations needed. | {compilations}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.batch.sql_recompilation.rate** | Number of SQL recompilations needed. | {compilations}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.lock.wait.rate** | Number of lock requests resulting in a wait. | {requests}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.lock.wait_time.avg** | Average wait time for all lock requests that had to wait. | ms | Gauge(Double) | <ul> </ul> |
| **sqlserver.page.buffer_cache.hit_ratio** | Pages found in the buffer pool without having to read from disk. | % | Gauge(Double) | <ul> </ul> |
| **sqlserver.page.checkpoint.flush.rate** | Number of pages flushed by operations requiring dirty pages to be flushed. | {pages}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.page.lazy_write.rate** | Number of lazy writes moving dirty pages to disk. | {writes}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.page.life_expectancy** | Time a page will stay in the buffer pool. | s | Gauge(Double) | <ul> </ul> |
| **sqlserver.page.operation.rate** | Number of physical database page operations issued. | {operations}/s | Gauge(Double) | <ul> <li>page.operations</li> </ul> |
| **sqlserver.page.split.rate** | Number of pages split as a result of overflowing index pages. | {pages}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction.rate** | Number of transactions started for the database (not including XTP-only transactions). | {transactions}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction.write.rate** | Number of transactions that wrote to the database and committed. | {transactions}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.flush.data.rate** | Total number of log bytes flushed. | By/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.flush.rate** | Number of log flushes. | {flushes}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.flush.wait.rate** | Number of commits waiting for a transaction log flush. | {commits}/s | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.growth.count** | Total number of transaction log expansions for a database. | {growths} | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.shrink.count** | Total number of transaction log shrinks for a database. | {shrinks} | Gauge(Double) | <ul> </ul> |
| **sqlserver.transaction_log.usage** | Percent of transaction log space used. | % | Gauge(Double) | <ul> </ul> |
| **sqlserver.user.connection.count** | Number of users connected to the SQL Server. | {connections} | Gauge(Double) | <ul> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Any metric can be enabled or disabled with the following scraper configuration:

```yaml
metrics:
<metric_name>:
enabled: <true|false>
```
## Resource attributes
| Name | Description | Type |
| ---- | ----------- | ---- |
| sqlserver.database.name | The name of the SQL Server database. | String |
## Metric attributes
| Name | Description | Values |
| ---- | ----------- | ------ |
| page.operations (type) | The page operation types. | read, write |
45 changes: 45 additions & 0 deletions receiver/sqlserverreceiver/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2020, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"

import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

const typeStr = "sqlserver"

// NewFactory creates a factory for SQL Server receiver.
func NewFactory() component.ReceiverFactory {
return component.NewReceiverFactory(
typeStr,
createDefaultConfig,
component.WithMetricsReceiver(createMetricsReceiver))
}

func createDefaultConfig() config.Receiver {
return &Config{
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
ReceiverSettings: config.NewReceiverSettings(config.NewComponentID(typeStr)),
CollectionInterval: 10 * time.Second,
},
Metrics: metadata.DefaultMetricsSettings(),
}
}
37 changes: 37 additions & 0 deletions receiver/sqlserverreceiver/factory_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows
// +build !windows

package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"

import (
"context"
"errors"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/consumer"
)

// createMetricsReceiver creates a metrics receiver based on provided config.
func createMetricsReceiver(
ctx context.Context,
params component.ReceiverCreateSettings,
cfg config.Receiver,
consumer consumer.Metrics,
) (component.MetricsReceiver, error) {
return nil, errors.New("the sqlserver receiver is only supported on Windows")
}
36 changes: 36 additions & 0 deletions receiver/sqlserverreceiver/factory_others_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows
// +build !windows

package sqlserverreceiver

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
)

func TestCreateMetricsReceiver(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
mReceiver, err := factory.CreateMetricsReceiver(context.Background(), componenttest.NewNopReceiverCreateSettings(), cfg, consumertest.NewNop())

assert.EqualError(t, err, "the sqlserver receiver is only supported on Windows")
assert.Nil(t, mReceiver)
}
Loading

0 comments on commit c7fe9fd

Please sign in to comment.