Skip to content

Commit

Permalink
Enhance the buffer cache hit ratio calculations for performance metri…
Browse files Browse the repository at this point in the history
…cs (#40022)

* changes to enhance the buffer cache hit ratio calculations for performance metrics

* Update CHANGELOG.next.asciidoc

updated with PR number

* Update performance.go

indentation fixed.

* check for 0 value add

* Update x-pack/metricbeat/module/mssql/performance/performance.go

Co-authored-by: Gabriel Pop <94497545+gpop63@users.noreply.github.com>

* Update CHANGELOG.next.asciidoc

Co-authored-by: subham sarkar <sarkar.subhams2@gmail.com>

* review comment added

* review comment added

---------

Co-authored-by: Gabriel Pop <94497545+gpop63@users.noreply.github.com>
Co-authored-by: subham sarkar <sarkar.subhams2@gmail.com>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 5225e0d commit b872d5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
17 changes: 14 additions & 3 deletions x-pack/metricbeat/module/mssql/performance/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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%' )
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b872d5e

Please sign in to comment.