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

MSSQL enhancements: support user databases #4108

Closed
lalit-satapathy opened this issue Sep 1, 2022 · 26 comments · Fixed by #7500
Closed

MSSQL enhancements: support user databases #4108

lalit-satapathy opened this issue Sep 1, 2022 · 26 comments · Fixed by #7500
Assignees
Labels
Team:Service-Integrations Label for the Service Integrations team

Comments

@lalit-satapathy
Copy link
Collaborator

lalit-satapathy commented Sep 1, 2022

The MSSQL Integration currently loads "transaction_log metrics" from following dbs:

  • tempdb
  • msdb
  • model
  • master

The integration code should be updated to load from all the dbs.

@lalit-satapathy lalit-satapathy added the Team:Service-Integrations Label for the Service Integrations team label Sep 1, 2022
@lalit-satapathy
Copy link
Collaborator Author

lalit-satapathy commented Sep 7, 2022

The short-term solution to this would be to add an optional input in transaction_log for users to enter a customer DB name. The metrics can be extracted for this customer DB along with all system DBs. CC @ManojS-shetty

@VF-JustinMolnar
Copy link

Hi @lalit-satapathy ,
I am interested in the short term solution you describe. Do you have any details on how we can add an optional input to the transaction_log so we can capture our custom databases?
Thanks.

@ManojS-shetty
Copy link
Contributor

Hi @lalit-satapathy , I am interested in the short term solution you describe. Do you have any details on how we can add an optional input to the transaction_log so we can capture our custom databases? Thanks.

HI @VF-JustinMolnar We would like to inform you that as Lalit suggested we will be providing this optional input in transaction_log as a part of package release.

We will be updating the progress of the development and testing on this issue thread.

Thank you

@lalit-satapathy lalit-satapathy changed the title MSSQL Integration: transaction_log metrics should load from all tables MSSQL enhancements: transaction_log metrics should load from all tables Oct 10, 2022
@lalit-satapathy lalit-satapathy changed the title MSSQL enhancements: transaction_log metrics should load from all tables MSSQL enhancements: support user databased Oct 10, 2022
@lalit-satapathy lalit-satapathy changed the title MSSQL enhancements: support user databased MSSQL enhancements: support user databases Oct 10, 2022
@Danouchka
Copy link

Danouchka commented Nov 23, 2022

Hi @lalit-satapathy for me it's a bug compared to Metricbeat capabilities , user called it a regression. Why on that point, Metricbeat retrieves metrics for all DBs and Elastic-Agent only system DBs ?
Additional input , even on short term, does not make sense because it supposes to enter manually each DB name.
But the idea is also to monitor Customer DBs for which the DBA or infra team would not be aware of.

@lalit-satapathy
Copy link
Collaborator Author

Hi @Danouchka,

This is only a "short term solution" as mentioned in here. The long-term solution is TBD.

@ritalwar
Copy link
Contributor

Hi, similar to metricbeat, I am working on retrieving metrics for all the DBs using agent as well.
Will be updating the progress here.

@ritalwar
Copy link
Contributor

Short-term solution where user database can be manually provided is done. #4869.

@rameshelastic
Copy link

@ritalwar , lets update the latest on this issue.

@ritalwar
Copy link
Contributor

Working on long term solution approach where we can get all user DBs metrics for transaction log.
Able to resolve it for sys.dm_db_log_stats table data and able to get data for all the DBs.
Trying to find a way to get all Dbs data from sys.dm_db_log_space_usage table.

@ritalwar
Copy link
Contributor

ritalwar commented Feb 8, 2023

Considering a strategy where a first integration can be added to obtain a list of all databases. The user can then edit the integration to add database names from that list and obtain the corresponding metrics.

@Danouchka
Copy link

Danouchka commented Feb 8, 2023 via email

@Danouchka
Copy link

Hi

Your strategy may be good but please

1/ explain why it's different from GCP compute metrics
2/ do you agree then that we have to implement #4260 before

Thank you

@ritalwar
Copy link
Contributor

Hi,

I'm not certain about the comparison, so currently looking into the other possibilities as well.

Additionally, as mentioned earlier, trying to find a means to collect data for all Dbs from the sys.dm_db_log_space_usage table, making some headway with the use of the "DBCC SQLPERF (LOGSPACE)" query, which is giving Log Size (MB) and Log Space Used (%) data for all the dbs.

Trying to further get  total_log_size_in_bytes and log_space_in_bytes_since_last_backup data for all databases.

@Danouchka
Copy link

Hi @ritalwar

Please combine your query with the latest one mentionned in #4260
As we need those information (path to filename, online status) as well. Thank you

For reminder, The query mentionned in #4260. (just one issue with this one below, SpaceUsed is null for user DBs)
SELECT DB_NAME() AS DbName, name AS FileName, type_desc, size/128.0 AS CurrentSizeMB, size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0 AS FreeSpaceMB, State_desc as State_desc, physical_name as physical_name, (size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0)*100./(size/128.0 ) as percentfree FROM sys.master_files WHERE type IN (0,1);

@Danouchka
Copy link

Danouchka commented Feb 27, 2023

Hello

Regarding latest elastic-agent integration "Microsoft SQL Server" , version 1.13.0, we have still issues.
Although we can add user databases, some metrics are not retrieved well regarding the transaction log
Elastic agent is 8.6.1

In elastic-integration, I added the 2 following user DBs

  • Microsoft.eShopOnWeb.Identity
  • Microsoft.eShopOnWeb.CatalogDb

I have 2 issues regarding transaction log metrics
a) I have part of the metrics for Microsoft.eShopOnWeb.Identity. You can compare with metricbeat.
Elastic agent integration
Capture d’écran 2023-02-27 à 12 46 56
Metricbeat mssql module
Capture d’écran 2023-02-27 à 12 47 04

b) I have data only for Microsoft.eShopOnWeb.Identity and not Microsoft.eShopOnWeb.CatalogDb
Elastic agent integration
Capture d’écran 2023-02-27 à 12 49 06
Metricbeat mssql module
Capture d’écran 2023-02-27 à 12 49 13

c) In Elastic Agent integration, I have the following error

[elastic_agent.metricbeat][error] Error fetching data for metricset sql.query: fetch table mode failed: mssql: Database ‘Microsoft’ does not exist. Make sure that the name is entered correctly.

Does elastic agent have issues with User DB dotted names ?

Elastic Agent diagnostics available in MP

@Danouchka
Copy link

My integration settings
cc @lalit-satapathy
Capture d’écran 2023-02-27 à 14 20 09

@ritalwar
Copy link
Contributor

Separate issue filed to support user dbs with special characters.
Please track here: #5528

@rameshelastic
Copy link

@ritalwar , can we close this too?

@ritalwar
Copy link
Contributor

ritalwar commented May 5, 2023

We currently support user databases in such a way that customers can add a list of user databases to observe performance and transaction-log metrics.
However, it would take some time to support all user databases by default; @lalit-satapathy can we create a separate issue to provide that support, or should we keep this issue open and decide priority for this in 8.9?

@shmsr
Copy link
Member

shmsr commented May 24, 2023

Hi @ritalwar

Please combine your query with the latest one mentionned in #4260 As we need those information (path to filename, online status) as well. Thank you

For reminder, The query mentionned in #4260. (just one issue with this one below, SpaceUsed is null for user DBs) SELECT DB_NAME() AS DbName, name AS FileName, type_desc, size/128.0 AS CurrentSizeMB, size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0 AS FreeSpaceMB, State_desc as State_desc, physical_name as physical_name, (size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0)*100./(size/128.0 ) as percentfree FROM sys.master_files WHERE type IN (0,1);

For user database(s), querying from sys.master_files and getting NULL for the concerned filled seems expected. From the documentation of sys.master_files:

Contains a row per file of a database as stored in the master database.

So it does not say user databases and that's why I think you are getting NULL. To get the relevant info I think you have to use sys.database_files instead.

Example:

cc: @Danouchka

@Danouchka
Copy link

Hi @shmsr I will give a try thank you ! and let you know

@Danouchka
Copy link

I get this below.
Strange, I get some NULL regardless using sys.database_files or sys.master_files.

sqlcmd -S localhost -U SA -P sqlMS200675# -Q "SELECT DB_NAME() AS DbName, name AS FileName, type_desc, size/128.0 AS CurrentSizeMB, size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)/128.0 AS FreeSpaceMB, State_desc as State_desc, physical_name as physical_name, CAST(max_size AS bigint)/128.0 AS max_file_size_mb, (size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)/128.0)*100./(size/128.0 ) as percentfree FROM sys.master_files  WHERE type_desc IN ('ROWS','LOG') ;"
DbName                                                                                                                           FileName                                                                                                                         type_desc                                                    CurrentSizeMB       FreeSpaceMB                   State_desc                                                   physical_name                                                                                                                                                                                                                                                        max_file_size_mb             percentfree
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------ ------------------- ----------------------------- ------------------------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- ----------------------------------------
master                                                                                                                           master                                                                                                                           ROWS                                                                    4.437500                       .812500 ONLINE                                                       /var/opt/mssql/data/master.mdf                                                                                                                                                                                                                                                           -.007812                               18.3098591
master                                                                                                                           mastlog                                                                                                                          LOG                                                                     2.000000                      1.351563 ONLINE                                                       /var/opt/mssql/data/mastlog.ldf                                                                                                                                                                                                                                                          -.007812                               67.5781500
master                                                                                                                           tempdev                                                                                                                          ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/tempdb.mdf                                                                                                                                                                                                                                                           -.007812                                     NULL
master                                                                                                                           templog                                                                                                                          LOG                                                                     8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/templog.ldf                                                                                                                                                                                                                                                          -.007812                                     NULL
master                                                                                                                           tempdev2                                                                                                                         ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/tempdb2.ndf                                                                                                                                                                                                                                                          -.007812                                     NULL
master                                                                                                                           tempdev3                                                                                                                         ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/tempdb3.ndf                                                                                                                                                                                                                                                          -.007812                                     NULL
master                                                                                                                           tempdev4                                                                                                                         ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/tempdb4.ndf                                                                                                                                                                                                                                                          -.007812                                     NULL
master                                                                                                                           modeldev                                                                                                                         ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/model.mdf                                                                                                                                                                                                                                                            -.007812                                     NULL
master                                                                                                                           modellog                                                                                                                         LOG                                                                     8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/modellog.ldf                                                                                                                                                                                                                                                         -.007812                                     NULL
master                                                                                                                           MSDBData                                                                                                                         ROWS                                                                   13.437500                          NULL ONLINE                                                       /var/opt/mssql/data/MSDBData.mdf                                                                                                                                                                                                                                                         -.007812                                     NULL
master                                                                                                                           MSDBLog                                                                                                                          LOG                                                                      .500000                          NULL ONLINE                                                       /var/opt/mssql/data/MSDBLog.ldf                                                                                                                                                                                                                                                    2097152.000000                                     NULL
master                                                                                                                           Microsoft.eShopOnWeb.CatalogDb                                                                                                   ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/Microsoft.eShopOnWeb.CatalogDb.mdf                                                                                                                                                                                                                                   -.007812                                     NULL
master                                                                                                                           Microsoft.eShopOnWeb.CatalogDb_log                                                                                               LOG                                                                     8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/Microsoft.eShopOnWeb.CatalogDb_log.ldf                                                                                                                                                                                                                         2097152.000000                                     NULL
master                                                                                                                           Microsoft.eShopOnWeb.Identity                                                                                                    ROWS                                                                    8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/Microsoft.eShopOnWeb.Identity.mdf                                                                                                                                                                                                                                    -.007812                                     NULL
master                                                                                                                           Microsoft.eShopOnWeb.Identity_log                                                                                                LOG                                                                     8.000000                          NULL ONLINE                                                       /var/opt/mssql/data/Microsoft.eShopOnWeb.Identity_log.ldf                                                                                                                                                                                                                          2097152.000000                                     NULL

(15 rows affected)
[root@sa-da-webserver ~]# sqlcmd -S localhost -U SA -P sqlMS200675# -Q "SELECT DB_NAME() AS DbName, name AS FileName, type_desc, size/128.0 AS CurrentSizeMB, size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)/128.0 AS FreeSpaceMB, State_desc as State_desc, physical_name as physical_name, CAST(max_size AS bigint)/128.0 AS max_file_size_mb, (size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)/128.0)*100./(size/128.0 ) as percentfree FROM sys.database_files  WHERE type_desc IN ('ROWS','LOG') ;"
DbName                                                                                                                           FileName                                                                                                                         type_desc                                                    CurrentSizeMB       FreeSpaceMB                   State_desc                                                   physical_name                                                                                                                                                                                                                                                        max_file_size_mb             percentfree
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------ ------------------- ----------------------------- ------------------------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- ----------------------------------------
master                                                                                                                           master                                                                                                                           ROWS                                                                    4.437500                       .812500 ONLINE                                                       /var/opt/mssql/data/master.mdf                                                                                                                                                                                                                                                           -.007812                               18.3098591
master                                                                                                                           mastlog                                                                                                                          LOG                                                                     2.000000                      1.351563 ONLINE                                                       /var/opt/mssql/data/mastlog.ldf                                                                                                                                                                                                                                                          -.007812                               67.5781500

(2 rows affected)
[root@sa-da-webserver ~]#

@shmsr
Copy link
Member

shmsr commented May 25, 2023

@Danouchka Do you have any user-defined DB? I just see master. Also, with the second command, there are just 2 rows and that too of master and I do not any NULL there. Do you mean something else?

@Danouchka
Copy link

Good Point !
Microsoft.eShopOnWeb.CatalogDb was supposed to be a user DB ...let me check how it was created !

@shmsr shmsr self-assigned this May 30, 2023
@shmsr
Copy link
Member

shmsr commented Jun 1, 2023

To summarize, we already have a solution in place which enables users to manually feed the user databases along with the already set system databases (as default). But to close this issue we’d ideally want to have a solution that gets all accessible databases on a server.

I have a proposal that suggests a simple approach to how we can achieve the same instead of introducing SQL chaining similar to that of HTTP JSON chaining in beats. Implementation is quite simple and it'd help us close this issue with a solid and simple solution without affecting older functionality.

Even if we introduce SQL chaining which will introduce some kind of chaining where we use the response of one query into another, I hardly have any use case that cannot be achieved with a simpler alternative. Considering, integrations only fetch metrics, logs, etc. (for instrumentation/ observability needs) from the databases; the requirement of some kind of chaining seems unnecessary. If someone has a solid use case, I am all ears. In case, we have solid use cases then we'll definitely explore adding some kind of chaining.

Proposal: Recommended approach

  • Add a new field in integrations for mssql module to enter database agnostic queries. Add queries as well.
  • Add a new field in beats in the SQL module to respect the field and accordingly do the next few steps. Name of all databases are fetched on every call to Fetch and names of the databases are collected and then given queries are executed for each and every database.

Please see elastic/beats#35688 for more details.

@shmsr
Copy link
Member

shmsr commented Sep 22, 2023

The feature requested is released in the 2.2.0 version of Microsoft SQL Server. For more info see: #7500

Please ensure to use the 8.10 stack or above in order to use the fetch_from_all_databases feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Service-Integrations Label for the Service Integrations team
Projects
None yet
7 participants