Skip to content

Commit

Permalink
Merge pull request prometheus-community#463 from secustor/implement-m…
Browse files Browse the repository at this point in the history
…ssql-base-counters

WIP: Implement mssql base counters
  • Loading branch information
carlpett authored Mar 3, 2020
2 parents 4200b48 + d6ba694 commit cc2c9be
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 18 deletions.
94 changes: 77 additions & 17 deletions collector/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ type MSSQLCollector struct {
AccessMethodsUsedtreepagecookie *prometheus.Desc
AccessMethodsWorkfilesCreated *prometheus.Desc
AccessMethodsWorktablesCreated *prometheus.Desc
AccessMethodsWorktablesFromCacheRatio *prometheus.Desc
AccessMethodsWorktablesFromCacheHits *prometheus.Desc
AccessMethodsWorktablesFromCacheLookups *prometheus.Desc

// Win32_PerfRawData_{instance}_SQLServerAvailabilityReplica
AvailReplicaBytesReceivedfromReplica *prometheus.Desc
Expand All @@ -194,7 +195,8 @@ type MSSQLCollector struct {

// Win32_PerfRawData_{instance}_SQLServerBufferManager
BufManBackgroundwriterpages *prometheus.Desc
BufManBuffercachehitratio *prometheus.Desc
BufManBuffercachehits *prometheus.Desc
BufManBuffercachelookups *prometheus.Desc
BufManCheckpointpages *prometheus.Desc
BufManDatabasepages *prometheus.Desc
BufManExtensionallocatedpages *prometheus.Desc
Expand Down Expand Up @@ -252,7 +254,8 @@ type MSSQLCollector struct {
DatabasesDBCCLogicalScanBytes *prometheus.Desc
DatabasesGroupCommitTime *prometheus.Desc
DatabasesLogBytesFlushed *prometheus.Desc
DatabasesLogCacheHitRatio *prometheus.Desc
DatabasesLogCacheHits *prometheus.Desc
DatabasesLogCacheLookups *prometheus.Desc
DatabasesLogCacheReads *prometheus.Desc
DatabasesLogFilesSizeKB *prometheus.Desc
DatabasesLogFilesUsedSizeKB *prometheus.Desc
Expand Down Expand Up @@ -317,7 +320,8 @@ type MSSQLCollector struct {
GenStatsUserConnections *prometheus.Desc

// Win32_PerfRawData_{instance}_SQLServerLocks
LocksAverageWaitTimems *prometheus.Desc
LocksWaitTime *prometheus.Desc
LocksCount *prometheus.Desc
LocksLockRequests *prometheus.Desc
LocksLockTimeouts *prometheus.Desc
LocksLockTimeoutstimeout0 *prometheus.Desc
Expand Down Expand Up @@ -656,12 +660,18 @@ func NewMSSQLCollector() (Collector, error) {
[]string{"instance"},
nil,
),
AccessMethodsWorktablesFromCacheRatio: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accessmethods_worktables_from_cache_ratio"),
AccessMethodsWorktablesFromCacheHits: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accessmethods_worktables_from_cache_hits"),
"(AccessMethods.WorktablesFromCacheRatio)",
[]string{"instance"},
nil,
),
AccessMethodsWorktablesFromCacheLookups: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "accessmethods_worktables_from_cache_lookups"),
"(AccessMethods.WorktablesFromCacheRatio_Base)",
[]string{"instance"},
nil,
),

// Win32_PerfRawData_{instance}_SQLServerAvailabilityReplica
AvailReplicaBytesReceivedfromReplica: prometheus.NewDesc(
Expand Down Expand Up @@ -726,12 +736,18 @@ func NewMSSQLCollector() (Collector, error) {
[]string{"instance"},
nil,
),
BufManBuffercachehitratio: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "bufman_buffer_cache_hit_ratio"),
BufManBuffercachehits: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "bufman_buffer_cache_hits"),
"(BufferManager.Buffercachehitratio)",
[]string{"instance"},
nil,
),
BufManBuffercachelookups: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "bufman_buffer_cache_lookups"),
"(BufferManager.Buffercachehitratio_Base)",
[]string{"instance"},
nil,
),
BufManCheckpointpages: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "bufman_checkpoint_pages"),
"(BufferManager.Checkpointpages)",
Expand Down Expand Up @@ -1054,12 +1070,18 @@ func NewMSSQLCollector() (Collector, error) {
[]string{"instance", "database"},
nil,
),
DatabasesLogCacheHitRatio: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "databases_log_cache_hit_ratio"),
DatabasesLogCacheHits: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "databases_log_cache_hits"),
"(Databases.LogCacheHitRatio)",
[]string{"instance", "database"},
nil,
),
DatabasesLogCacheLookups: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "databases_log_cache_lookups"),
"(Databases.LogCacheHitRatio_Base)",
[]string{"instance", "database"},
nil,
),
DatabasesLogCacheReads: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "databases_log_cache_reads"),
"(Databases.LogCacheReads)",
Expand Down Expand Up @@ -1424,9 +1446,15 @@ func NewMSSQLCollector() (Collector, error) {
),

// Win32_PerfRawData_{instance}_SQLServerLocks
LocksAverageWaitTimems: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "locks_average_wait_seconds"),
"(Locks.AverageWaitTimems)",
LocksWaitTime: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "locks_wait_time_seconds"),
"(Locks.AverageWaitTimems Total time in seconds which locks have been holding resources)",
[]string{"instance", "resource"},
nil,
),
LocksCount: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "locks_count"),
"(Locks.AverageWaitTimems_Base count of how often requests have run into locks)",
[]string{"instance", "resource"},
nil,
),
Expand Down Expand Up @@ -1863,6 +1891,7 @@ type win32PerfRawDataSQLServerAccessMethods struct {
WorkfilesCreatedPersec uint64
WorktablesCreatedPersec uint64
WorktablesFromCacheRatio uint64
WorktablesFromCacheRatio_Base uint64
}

func (c *MSSQLCollector) collectAccessMethods(ch chan<- prometheus.Metric, sqlInstance string) (*prometheus.Desc, error) {
Expand Down Expand Up @@ -2175,11 +2204,18 @@ func (c *MSSQLCollector) collectAccessMethods(ch chan<- prometheus.Metric, sqlIn
)

ch <- prometheus.MustNewConstMetric(
c.AccessMethodsWorktablesFromCacheRatio,
c.AccessMethodsWorktablesFromCacheHits,
prometheus.CounterValue,
float64(v.WorktablesFromCacheRatio),
sqlInstance,
)

ch <- prometheus.MustNewConstMetric(
c.AccessMethodsWorktablesFromCacheLookups,
prometheus.CounterValue,
float64(v.WorktablesFromCacheRatio_Base),
sqlInstance,
)
return nil, nil
}

Expand Down Expand Up @@ -2282,6 +2318,7 @@ func (c *MSSQLCollector) collectAvailabilityReplica(ch chan<- prometheus.Metric,
type win32PerfRawDataSQLServerBufferManager struct {
BackgroundwriterpagesPersec uint64
Buffercachehitratio uint64
Buffercachehitratio_Base uint64
CheckpointpagesPersec uint64
Databasepages uint64
Extensionallocatedpages uint64
Expand Down Expand Up @@ -2327,12 +2364,19 @@ func (c *MSSQLCollector) collectBufferManager(ch chan<- prometheus.Metric, sqlIn
)

ch <- prometheus.MustNewConstMetric(
c.BufManBuffercachehitratio,
c.BufManBuffercachehits,
prometheus.GaugeValue,
float64(v.Buffercachehitratio),
sqlInstance,
)

ch <- prometheus.MustNewConstMetric(
c.BufManBuffercachelookups,
prometheus.GaugeValue,
float64(v.Buffercachehitratio_Base),
sqlInstance,
)

ch <- prometheus.MustNewConstMetric(
c.BufManCheckpointpages,
prometheus.CounterValue,
Expand Down Expand Up @@ -2704,6 +2748,7 @@ type win32PerfRawDataSQLServerDatabases struct {
GroupCommitTimePersec uint64
LogBytesFlushedPersec uint64
LogCacheHitRatio uint64
LogCacheHitRatio_Base uint64
LogCacheReadsPersec uint64
LogFilesSizeKB uint64
LogFilesUsedSizeKB uint64
Expand Down Expand Up @@ -2819,12 +2864,19 @@ func (c *MSSQLCollector) collectDatabases(ch chan<- prometheus.Metric, sqlInstan
)

ch <- prometheus.MustNewConstMetric(
c.DatabasesLogCacheHitRatio,
c.DatabasesLogCacheHits,
prometheus.GaugeValue,
float64(v.LogCacheHitRatio),
sqlInstance, dbName,
)

ch <- prometheus.MustNewConstMetric(
c.DatabasesLogCacheLookups,
prometheus.GaugeValue,
float64(v.LogCacheHitRatio_Base),
sqlInstance, dbName,
)

ch <- prometheus.MustNewConstMetric(
c.DatabasesLogCacheReads,
prometheus.CounterValue,
Expand Down Expand Up @@ -3299,6 +3351,7 @@ func (c *MSSQLCollector) collectGeneralStatistics(ch chan<- prometheus.Metric, s
type win32PerfRawDataSQLServerLocks struct {
Name string
AverageWaitTimems uint64
AverageWaitTimems_Base uint64
LockRequestsPersec uint64
LockTimeoutsPersec uint64
LockTimeoutstimeout0Persec uint64
Expand All @@ -3321,12 +3374,19 @@ func (c *MSSQLCollector) collectLocks(ch chan<- prometheus.Metric, sqlInstance s
lockResourceName := v.Name

ch <- prometheus.MustNewConstMetric(
c.LocksAverageWaitTimems,
c.LocksWaitTime,
prometheus.GaugeValue,
float64(v.AverageWaitTimems)/1000.0,
sqlInstance, lockResourceName,
)

ch <- prometheus.MustNewConstMetric(
c.LocksCount,
prometheus.GaugeValue,
float64(v.AverageWaitTimems_Base)/1000.0,
sqlInstance, lockResourceName,
)

ch <- prometheus.MustNewConstMetric(
c.LocksLockRequests,
prometheus.CounterValue,
Expand Down
22 changes: 21 additions & 1 deletion docs/collector.mssql.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,27 @@ Name | Description | Type | Labels
_This collector does not yet have explained examples, we would appreciate your help adding them!_

## Useful queries
_This collector does not yet have any useful queries added, we would appreciate your help adding them!_

### Buffer Cache Hit Ratio

When you read the counter in perfmon you will get the the percentage pages found in the buffer cache. This percentage is calculated internally based on the total number of cache hits divided by the total number of cache lookups over the last few thousand page accesses.
This collector retrieves the two internal values separately. In order to calculate the Buffer Cache Hit Ratio in PromQL.

```
wmi_mssql_bufman_buffer_cache_hits{instance="host:9182", exported_instance="MSSQLSERVER"} /
wmi_mssql_bufman_buffer_cache_lookups{instance="host:9182", exported_instance="MSSQLSERVER"}
```

This principal can be used for following metrics too:
- AccessMethodsWorktablesFromCacheHitRatio
- accessmethods_worktables_from_cache_hits
- accessmethods_worktables_from_cache_lookups
- LogCacheHitRatio
- databases_log_cache_hits
- databases_log_cache_lookups
- AverageLockWaitTime
- locks_wait_time_seconds
- locks_count

## Alerting examples
_This collector does not yet have alerting examples, we would appreciate your help adding them!_

0 comments on commit cc2c9be

Please sign in to comment.