Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Metricset on X-Pack MSSQL Metricbeat module #9826

Merged

Conversation

sayden
Copy link
Contributor

@sayden sayden commented Dec 28, 2018

performance metricset is a series of customized queries to extract very relevant information using the sys.dm_os_performance_counters database (more information here).

This concurrent structure was based on the fact that each fetch operation needs to establish a new connection to the database. Now that the connection is maintained active, a transport channel could be used to report events and maybe the code would be a bit simpler (but I need to be sure about a couple of things of how the framework works before doing it to not leave dangling channels by accident)

GA

  • Supported versions are documented
  • Supported operating systems are documented (if applicable)
  • Integration tests
  • System tests
  • Automated checks that all fields are documented
  • Documentation
  • Example data.json exists and an automated way to generate it exists (go test -data)
  • Fields follow naming conventions: https://www.elastic.co/guide/en/beats/devguide/master/event-conventions.html
  • Dashboards exists (if applicable)
  • Kibana Home Tutorial (if applicable)

@sayden sayden self-assigned this Dec 28, 2018
@sayden sayden requested a review from ruflin December 28, 2018 14:15
@sayden sayden requested a review from a team as a code owner December 28, 2018 14:15
@sayden sayden changed the title Metricbeat Performance MSSQL metricset Metricbeat Performance Metricset on X-Pack MSSQL module Dec 28, 2018
@sayden sayden changed the title Metricbeat Performance Metricset on X-Pack MSSQL module Performance Metricset on X-Pack MSSQL Metricbeat module Dec 28, 2018
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already looking good. Left some minor comments. Can you add a changelog entry? It can be combined with the entry for mssql.

x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/performance/_meta/data.json Outdated Show resolved Hide resolved
x-pack/metricbeat/module/mssql/performance/performance.go Outdated Show resolved Hide resolved
@sayden sayden force-pushed the feature/xp/mb/mssql-performance-metricset branch from f9b23ec to 6c5a634 Compare January 9, 2019 17:44
@sayden sayden requested a review from a team as a code owner January 9, 2019 17:44
@sayden
Copy link
Contributor Author

sayden commented Jan 9, 2019

After a short chat with @ruflin we have decide to split this metricset in two. The reason was that the current metrics being fetch have mixed data from instances and databases. In short, we are going to leave all instance based performance metrics in this metricset and create a new metricset to retrieve database specific performance counters.

At the same time, instead of doing a query to retrieve each performance value, we are using a WHERE clause as a filter to retrieve all metrics we want and then do any manipulation inside the code, taking out some load from the database by removing a UNION and a JOIN.

Finally, the code will be more self contained and less abstracted so each metricset will have full independency of manipulation instead of being under the hood of the SQL framework that is built within fetcher.go that, all in all, has its limitations.

err = errors.Wrap(err, "error doing ping to db")
}

return db, err
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This db instance is closed at the Metricset, I'm not fully sure if this is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the connection per metricset? If yes, then this sounds correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it is per Metricset yes. I wasn't sure if that was correct either 😅 but it looked like the best way to isolate errors between metricset (that each has it's own connection).

objectName string
instanceName string
counterName string
counterValue *int64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All values returned by Performance Counters table are BIGINT

@sayden sayden mentioned this pull request Jan 10, 2019
12 tasks
Copy link
Member

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor comments.

Could you make Hound happy?

x-pack/metricbeat/module/mssql/connection.go Show resolved Hide resolved
x-pack/metricbeat/module/mssql/fetcher.go Outdated Show resolved Hide resolved
func (m *MetricSet) Fetch(reporter mb.ReporterV2) {
var err error
var rows *sql.Rows
rows, err = m.db.Query("SELECT object_name, counter_name, instance_name, cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'SQL Compilations/sec' OR counter_name = 'SQL Re-Compilations/sec' OR counter_name = 'User Connections' OR counter_name = 'Page splits/sec' OR (counter_name = 'Lock Waits/sec' AND instance_name = '_Total') OR counter_name = 'Page splits/sec' OR (object_name = 'SQLServer:Buffer Manager' AND counter_name = 'Page life expectancy') OR counter_name = 'Batch Requests/sec' OR (counter_name = 'Buffer cache hit ratio' AND object_name = 'SQLServer:Buffer Manager') OR (counter_name = 'Lock Waits/sec' and instance_name = '_Total')")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for now. I remember for all these fields 1 column was empty (don't remember which one). Perhaps to simplify the query we could just check if this column is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the query without WHERE returns 2000 rows, 1000 are with the empty column. I guess that what you want is to simplify (automatize) the process of adding more fields. What we could do is to ask for everything (those 1000 rows), and take only the values we want from an array but we will still have to download 1000 rows from the db

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I would probably download the 1000 rows but I don't know the size of it. Curious what would be less load on the DB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have just checked and they are 273 rows and doing some ugly maths by checking the size of each cell, it will be a total of 109200 bytes to download.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100KB sounds doable but let's keep it as is for now and "improve" it in case it ever becomes an issue.

x-pack/metricbeat/module/mssql/performance/performance.go Outdated Show resolved Hide resolved
func (m *MetricSet) Fetch(reporter mb.ReporterV2) {
var err error
var rows *sql.Rows
rows, err = m.db.Query("SELECT object_name, counter_name, instance_name, cntr_value FROM sys.dm_os_performance_counters WHERE counter_name = 'SQL Compilations/sec' OR counter_name = 'SQL Re-Compilations/sec' OR counter_name = 'User Connections' OR counter_name = 'Page splits/sec' OR (counter_name = 'Lock Waits/sec' AND instance_name = '_Total') OR counter_name = 'Page splits/sec' OR (object_name = 'SQLServer:Buffer Manager' AND counter_name = 'Page life expectancy') OR counter_name = 'Batch Requests/sec' OR (counter_name = 'Buffer cache hit ratio' AND object_name = 'SQLServer:Buffer Manager') OR (counter_name = 'Lock Waits/sec' and instance_name = '_Total')")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I would probably download the 1000 rows but I don't know the size of it. Curious what would be less load on the DB.

@sayden sayden merged commit 1007aef into elastic:master Jan 10, 2019
@ruflin ruflin deleted the feature/xp/mb/mssql-performance-metricset branch January 10, 2019 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants