diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..85dcc16 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +node_modules diff --git a/Dockerfile b/Dockerfile index 9857549..9e51f37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN mkdir -p /usr/src/app # Change directory so that our commands run inside this new directory WORKDIR /usr/src/app -# Copy dependency definitions +# Copy application COPY package.json *.js ./ # Install dependecies diff --git a/metrics.js b/metrics.js index b1041e5..08e78b9 100644 --- a/metrics.js +++ b/metrics.js @@ -269,6 +269,21 @@ from sys.dm_os_sys_memory`, }, }; +const mssql_database_state = { + metrics: { + mssql_database_state: new client.Gauge({name: 'mssql_database_state', help: 'State of databases: 0 = ONLINE, 1 = RESTORING, 2 = RECOVERING 3 = RECOVERY_PENDING 4 = SUSPECT 5 = EMERGENCY 6 = OFFLINE 7 = COPYING 10 = OFFLINE_SECONDARY', labelNames: ['database']}) + }, + query: `select name, state from sys.databases;`, + collect: function (rows, metrics) { + for (let i = 0; i < rows.length; i++) { + const row = rows[i]; + const database = row[0].value; + const state = row[1].value; + metrics.mssql_database_state.set({database: database}, state); + } + } +}; + const metrics = [ mssql_instance_local_time, mssql_connections, @@ -283,6 +298,7 @@ const metrics = [ mssql_batch_requests, mssql_os_process_memory, mssql_os_sys_memory, + mssql_database_state, ]; module.exports = {