From 27e26037e37eb46f6d9ac24fa2760159c79cfc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=8F=D0=BA=D0=BE=D0=B2=20=D0=98=D0=B3?= =?UTF-8?q?=D0=BE=D1=80=D1=8C?= Date: Thu, 1 Aug 2019 17:55:44 +0300 Subject: [PATCH] Added collector for SQLErrors counter --- collector/mssql.go | 45 ++++++++++++++++++++++++++++++++++++++++- docs/collector.mssql.md | 3 ++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/collector/mssql.go b/collector/mssql.go index 93a55f64..cccbc2b4 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 + SQLErrorsErrors *prometheus.Desc + mssqlInstances mssqlInstancesType mssqlCollectors mssqlCollectorsMap mssqlChildCollectorFailure int @@ -1637,6 +1641,14 @@ func NewMSSQLCollector() (Collector, error) { nil, ), + // Win32_PerfRawData_{instance}_SQLServerSQLErrors + SQLErrorsErrors: prometheus.NewDesc( + prometheus.BuildFQName(Namespace, subsystem, "sqlerrors_errors"), + "(SQLErrors.Errors)", + []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.SQLErrorsErrors, + 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 5812eddf..49781361 100644 --- a/docs/collector.mssql.md +++ b/docs/collector.mssql.md @@ -5,7 +5,7 @@ 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 @@ -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_sqlerror_errors` | _Not yet documented_ | counter | `instance` ### Example metric _This collector does not yet have explained examples, we would appreciate your help adding them!_