diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index fd7f83bcd9b9..bcfdbd52694a 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -327,6 +327,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Add SSL support for aerospike module {pull}38126[38126] - Add last_terminated_timestamp metric in kubernetes module {pull}39200[39200] {issue}3802[3802] - Add pod.status.ready_time and pod.status.reason metrics in kubernetes module {pull}39316[39316] +- Add "Buffer cache hit ratio base" to calculate "Buffer cache hit ratio" for performance metrics {pull}40022[40022] *Metricbeat* diff --git a/x-pack/metricbeat/module/mssql/performance/performance.go b/x-pack/metricbeat/module/mssql/performance/performance.go index 7cc6848829f5..746b24f9029d 100644 --- a/x-pack/metricbeat/module/mssql/performance/performance.go +++ b/x-pack/metricbeat/module/mssql/performance/performance.go @@ -65,6 +65,9 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { func (m *MetricSet) Fetch(reporter mb.ReporterV2) { var err error var rows *sql.Rows + var bufferCacheHitRatioValue, bufferCacheHitRatioBaseValue int64 + bufferCacheHitRatio := "Buffer cache hit ratio" + bufferCacheHitRatioBase := "Buffer cache hit ratio base" rows, err = m.db.Query(`SELECT object_name, counter_name, instance_name, @@ -80,6 +83,7 @@ WHERE counter_name = 'SQL Compilations/sec' AND instance_name = '_Total' ) OR ( counter_name IN ( 'Page life expectancy', 'Buffer cache hit ratio', + 'Buffer cache hit ratio base', 'Target pages', 'Database pages', 'Checkpoint pages/sec' ) AND object_name LIKE '%:Buffer Manager%' ) @@ -112,13 +116,20 @@ WHERE counter_name = 'SQL Compilations/sec' row.instanceName = strings.TrimSpace(row.instanceName) row.objectName = strings.TrimSpace(row.objectName) - if row.counterName == "Buffer cache hit ratio" { - mapStr[row.counterName] = fmt.Sprintf("%v", float64(*row.counterValue)/100) - } else { + switch row.counterName { + case bufferCacheHitRatio: + bufferCacheHitRatioValue = *row.counterValue + case bufferCacheHitRatioBase: + bufferCacheHitRatioBaseValue = *row.counterValue + default: mapStr[row.counterName] = fmt.Sprintf("%v", *row.counterValue) } } + if bufferCacheHitRatioBaseValue != 0 { + mapStr[bufferCacheHitRatio] = fmt.Sprintf("%f", float64(bufferCacheHitRatioValue)/float64(bufferCacheHitRatioBaseValue)) + } + res, err := schema.Apply(mapStr) if err != nil { m.log.Error(fmt.Errorf("error applying schema %w", err))