From 65b05f6527da95f294c2571276891a71c657d3aa Mon Sep 17 00:00:00 2001 From: Michael Montgomery Date: Thu, 10 Dec 2020 15:14:05 -0600 Subject: [PATCH] Add database state metric Optimize dockerfile Add .dockerignore to speed up builds, ignoring .git, and node_modules --- .dockerignore | 2 ++ Dockerfile | 5 ++++- metrics.js | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .dockerignore 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 9ba929c..3b2bb0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,11 +8,14 @@ RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Copy dependency definitions -COPY package.json *.js /usr/src/app/ +COPY package.json /usr/src/app/ # Install dependecies RUN npm install --production +# Copy application files +COPY *.js /usr/src/app/ + # Expose the port the app runs in EXPOSE 4000 diff --git a/metrics.js b/metrics.js index 3801372..af08d11 100644 --- a/metrics.js +++ b/metrics.js @@ -203,6 +203,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, @@ -214,7 +229,8 @@ const metrics = [ mssql_io_stall, mssql_batch_requests, mssql_os_process_memory, - mssql_os_sys_memory + mssql_os_sys_memory, + mssql_database_state, ]; module.exports = {