From 154dbfa37acf13ceab48150da340913bf5e7c572 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilyev Date: Mon, 25 Jan 2021 19:34:19 +0400 Subject: [PATCH] Added the sample of DB size sensor for MS SQL. (#15529) Co-authored-by: Franck Nijhof --- source/_integrations/sql.markdown | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/_integrations/sql.markdown b/source/_integrations/sql.markdown index 59681e16faf..4055ca93bf9 100644 --- a/source/_integrations/sql.markdown +++ b/source/_integrations/sql.markdown @@ -161,3 +161,20 @@ sensor: ``` {% endraw %} + +#### MS SQL + +Use the same `db_url` as for the `recorder` integration. Change `DB_NAME` to the name that you use as the database name, to ensure that your sensor will work properly. Be sure `username` has enough rights to access the sys tables. + +{% raw %} +```yaml +sensor: + - platform: sql + db_url: "mssql+pyodbc://username:password@SERVER_IP/DB_NAME?charset=utf8;DRIVER={FreeTDS};Port=1433;" + queries: + - name: DB size + query: "SELECT TOP 1 SUM(m.size) * 8 / 1024 as size FROM sys.master_files m INNER JOIN sys.databases d ON d.database_id=m.database_id WHERE d.name='DB_NAME';" + column: 'size' + unit_of_measurement: MiB +``` +{% endraw %}