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

Not able to get databases metrics using resource_groups #40

Open
hristodragolovbede opened this issue Jan 8, 2019 · 12 comments
Open

Not able to get databases metrics using resource_groups #40

hristodragolovbede opened this issue Jan 8, 2019 · 12 comments

Comments

@hristodragolovbede
Copy link

I'm trying to get database metrics using resource group filtering which was added recently.
Targeting the database directly using the following resource:

/resourceGroups/SOMERG/providers/Microsoft.Sql/servers/SERVER/databases/DATABASE

works fine but when I try retrieving the metrics with resource group filtering it fails with:
collected metric storage_percent_percent_total label: label: gauge: was collected before with the same name and label values

I'm using the following configuration:

resource_groups:

  • resource_group: "SOMERG"
    resource_types:
    • "Microsoft.Sql/servers/databases"
      metrics:
    • name: "storage_percent"

I wasn't sure what the resource_types should be and tried specifying different combinations but none was displaying anything except this one.

@brian-brazil
Copy link
Member

@debfx Are we missing some distinguishing labels?

@debfx
Copy link
Contributor

debfx commented Jan 9, 2019

@hristodragolovbede Do you also have a targets section in your config?
At least that's the error you would get when you try to gather metrics for the same resource through targets and resource_groups.

@hristodragolovbede
Copy link
Author

No, there is nothing in the targets section. Config file is populated only with the config described above (including authentication stuff)

@hristodragolovbede
Copy link
Author

I added a regex to include specific databases by using resource_name_include_re:
It worked. But if you specify a regex matching everything it fails again with the same error.

@hristodragolovbede
Copy link
Author

I tried few more things:

  • I specified an include statement that matches more than one database - it fails.
  • Another interesting thing is that for resource_name I get the name of the SQL server. I expect to see the name of the database instead?

@chaconcin
Copy link

Hi hristodragolovbede:
Did you resolve the issue? Were you able to monitor more than one SQL Server as PaaS in the same Resource Group? If so, how did you solve it? I have the same issue, 3 SQL Servers in the same RG but only one can be monitored.
The same issue for App Services

@hristodragolovbede
Copy link
Author

Hi hristodragolovbede:
Did you resolve the issue? Were you able to monitor more than one SQL Server as PaaS in the same Resource Group? If so, how did you solve it? I have the same issue, 3 SQL Servers in the same RG but only one can be monitored.
The same issue for App Services

No, I didn't find a solution unfortunately.

@chaconcin
Copy link

Were you able to monitor more than one SQL Database with targets instead of Resource Groups? If so, could you paste the code?
I´ve tried both but no luck

@chaconcin
Copy link

I´ve configured the monitor of three instances with Azure Grafana plugin and it works, so I suppose that is exporter issue. Someone could help me with this? I´ve not able to do it neither resource_group nor target.

@mboret
Copy link
Contributor

mboret commented Mar 11, 2019

Same issue here. I can confirm, it works if I add "resource_name_include_re" with my databases name as value. But doesn't work with a regex value which match everything. Does the problem could not be related to the metric label "resource_name" with the value of the SQL Server and not the SQL server database? As one SQL Server can have one or more SQL databases. Don't really know...

@chaconcin
Copy link

Hi mboret:
Can you monitor all the SQL Databases using resource_name_include_re one by one? Not server but SQL Database name? I will try it but I think that I tried it but no luck

@mboret
Copy link
Contributor

mboret commented Mar 12, 2019

@chaconcin No it doesn't work. When I've only one database it works , but adding another one generates exporter errors. I think this confirms what I've supposed, database metrics are stored with the sql server name as resource_name label. So with one database it works but with more than one it fails as the metric already exist.
@debfx
The problem seems in the utils.go:


    func CreateResourceLabels(resourceID string) map[string]string {
	labels := make(map[string]string)
	labels["resource_group"] = strings.Split(resourceID, "/")[4]
	labels["resource_name"] = strings.Split(resourceID, "/")[8]
	return labels
}

For a DB SQL database the resourceID is:

/subscriptions/XXXX-XXXXX-XXXXX-XXXXX-XXXXX/resourceGroups/rg-test/providers/Microsoft.Sql/servers/test-sql-server/databases/test-database-a/providers/microsoft.Insights

And for a app service site the resourceID is:

/subscriptions/XXXX-XXXXX-XXXXX-XXXXX-XXXXX/resourceGroups/rg-test/providers/Microsoft.Web/sites/test-backend/providers/microsoft.Insights

For the SQL DB, the "resource_name" is always the SQL server name and not the database name.
Maybe we can solve the issue by adding another label:


    func CreateResourceLabels(resourceID string) map[string]string {
	labels := make(map[string]string)
	labels["resource_group"] = strings.Split(resourceID, "/")[4]
	labels["resource_name"] = strings.Split(resourceID, "/")[8]
        if len(strings.Split(resourceID, "/")) > 13 {
	    labels["sub_resource_name"] = strings.Split(resourceID, "/")[10]
        }
	return labels
}

mboret added a commit to mboret/azure_metrics_exporter that referenced this issue Mar 13, 2019
Hi,

This is related to issue RobustPerception#40 
The exporter works only if the DB SQL server has one database with more than one this create a conflict has the exporter reports that the metric already exists. 
In fact, it's related to the label "resource_name", which takes the name of the SQL Server and not of the database. 

The resourceID for a DB:

> /subscriptions/XXXX-XXXXX-XXXXX-XXXXX-XXXXX/resourceGroups/rg-test/providers/Microsoft.Sql/servers/test-sql-server/databases/test-database-a/providers/microsoft.Insights

The solution could be to add another label to identify the database name("sub_resource_name"). 
Maybe there is the same issue with other Azure services which have long resourceID and so this change can fix it.
brian-brazil pushed a commit that referenced this issue Apr 3, 2019
* Add additional label to fix SQL database scrap issue

Hi,

This is related to issue #40 
The exporter works only if the DB SQL server has one database with more than one this create a conflict has the exporter reports that the metric already exists. 
In fact, it's related to the label "resource_name", which takes the name of the SQL Server and not of the database. 

The resourceID for a DB:

> /subscriptions/XXXX-XXXXX-XXXXX-XXXXX-XXXXX/resourceGroups/rg-test/providers/Microsoft.Sql/servers/test-sql-server/databases/test-database-a/providers/microsoft.Insights

The solution could be to add another label to identify the database name("sub_resource_name"). 
Maybe there is the same issue with other Azure services which have long resourceID and so this change can fix it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants