diff --git a/collector/mssql.go b/collector/mssql.go index 93a55f643..b54670292 100644 --- a/collector/mssql.go +++ b/collector/mssql.go @@ -91,7 +91,7 @@ func mssqlBuildWMIInstanceClass(suffix string, instance string) string { type mssqlCollectorsMap map[string]mssqlCollectorFunc func mssqlAvailableClassCollectors() string { - return "accessmethods,availreplica,bufman,databases,dbreplica,genstats,locks,memmgr,sqlstats" + return "accessmethods,availreplica,bufman,databases,dbreplica,genstats,locks,memmgr,sqlstats,sqlerrors" } func (c *MSSQLCollector) getMSSQLCollectors() mssqlCollectorsMap { @@ -105,6 +105,7 @@ func (c *MSSQLCollector) getMSSQLCollectors() mssqlCollectorsMap { mssqlCollectors["locks"] = c.collectLocks mssqlCollectors["memmgr"] = c.collectMemoryManager mssqlCollectors["sqlstats"] = c.collectSQLStats + mssqlCollectors["sqlerrors"] = c.collectSQLErrors return mssqlCollectors } @@ -358,6 +359,9 @@ type MSSQLCollector struct { SQLStatsSQLReCompilations *prometheus.Desc SQLStatsUnsafeAutoParams *prometheus.Desc + // Win32_PerfRawData_{instance}_SQLServerSQLErrors + SQLErrorsTotal *prometheus.Desc + mssqlInstances mssqlInstancesType mssqlCollectors mssqlCollectorsMap mssqlChildCollectorFailure int @@ -1637,6 +1641,14 @@ func NewMSSQLCollector() (Collector, error) { nil, ), + // Win32_PerfRawData_{instance}_SQLServerSQLErrors + SQLErrorsTotal: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "sql_errors_total"), + "(SQLErrors.Total)", + []string{"instance", "resource"}, + nil, + ), + mssqlInstances: getMSSQLInstances(), } @@ -3558,3 +3570,34 @@ func (c *MSSQLCollector) collectSQLStats(ch chan<- prometheus.Metric, sqlInstanc return nil, nil } + +type win32PerfRawDataSQLServerSQLErrors struct { + Name string + Errorssec uint64 +} + +// Win32_PerfRawData_MSSQLSERVER_SQLServerErrors docs: +// - https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-errors-object +func (c *MSSQLCollector) collectSQLErrors(ch chan<- prometheus.Metric, sqlInstance string) (*prometheus.Desc, error) { + var dst []win32PerfRawDataSQLServerSQLErrors + log.Debugf("mssql_sqlerrors collector iterating sql instance %s.", sqlInstance) + + class := mssqlBuildWMIInstanceClass("SQLErrors", sqlInstance) + q := queryAllForClassWhere(&dst, class, `Name <> '_Total'`) + if err := wmi.Query(q, &dst); err != nil { + return nil, err + } + + for _, v := range dst { + resource := v.Name + + ch <- prometheus.MustNewConstMetric( + c.SQLErrorsTotal, + prometheus.CounterValue, + float64(v.Errorssec), + sqlInstance, resource, + ) + } + + return nil, nil +} \ No newline at end of file diff --git a/docs/collector.mssql.md b/docs/collector.mssql.md index 5812eddf4..76c7c1a1c 100644 --- a/docs/collector.mssql.md +++ b/docs/collector.mssql.md @@ -5,14 +5,14 @@ The mssql collector exposes metrics about the MSSQL server ||| -|- Metric name prefix | `mssql` -Classes | [`Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-access-methods-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerAvailabilityReplica`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-availability-replica)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerDatabaseReplica`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-replica)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-databases-object?view=sql-server-2017)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-general-statistics-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerLocks`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-locks-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-memory-manager-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-statistics-object) +Classes | [`Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-access-methods-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerAvailabilityReplica`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-availability-replica)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-buffer-manager-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerDatabaseReplica`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-database-replica)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-databases-object?view=sql-server-2017)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-general-statistics-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerLocks`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-locks-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-memory-manager-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-statistics-object)
[`Win32_PerfRawData_MSSQLSERVER_SQLServerSQLErrors`](https://docs.microsoft.com/en-us/sql/relational-databases/performance-monitor/sql-server-sql-errors-object) Enabled by default? | No ## Flags ### `--collectors.mssql.classes-enabled` -Comma-separated list of MSSQL WMI classes to use. Supported values are `accessmethods`, `availreplica`, `bufman`, `databases`, `dbreplica`, `genstats`, `locks`, `memmgr` and `sqlstats`. +Comma-separated list of MSSQL WMI classes to use. Supported values are `accessmethods`, `availreplica`, `bufman`, `databases`, `dbreplica`, `genstats`, `locks`, `memmgr`, `sqlstats` and `sqlerrors`. ### `--collectors.mssql.class-print` @@ -230,6 +230,7 @@ Name | Description | Type | Labels `wmi_mssql_sqlstats_sql_compilations` | _Not yet documented_ | counter | `instance` `wmi_mssql_sqlstats_sql_recompilations` | _Not yet documented_ | counter | `instance` `wmi_mssql_sqlstats_unsafe_auto_parameterization_attempts` | _Not yet documented_ | counter | `instance` +`wmi_mssql_sql_errors_total` | _Not yet documented_ | counter | `instance`, `resource` ### Example metric _This collector does not yet have explained examples, we would appreciate your help adding them!_ diff --git a/tools/collector-generator/New-Collector.ps1 b/tools/collector-generator/New-Collector.ps1 index 9cf01978f..687b852d0 100644 --- a/tools/collector-generator/New-Collector.ps1 +++ b/tools/collector-generator/New-Collector.ps1 @@ -17,7 +17,7 @@ else { $wmiObject = Get-WMIObject -ComputerName $ComputerName -Class $Class } -$members = @($wmiObject ` +$members = $wmiObject ` | Get-Member -MemberType Properties ` | Where-Object { $_.Definition -Match '^u?int' -and $_.Name -NotMatch '_' } ` | Select-Object Name, @{Name="Type";Expression={$_.Definition.Split(" ")[0]}})