Skip to content

Commit

Permalink
Add database state metric (#15)
Browse files Browse the repository at this point in the history
Optimize dockerfile
Add .dockerignore to speed up builds, ignoring .git, and node_modules
Add database state metric

Co-authored-by: Pierre Awaragi <pierre@awaragi.com>
  • Loading branch information
naemono and awaragi authored Mar 21, 2022
1 parent b125581 commit 225088f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
node_modules
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -283,6 +298,7 @@ const metrics = [
mssql_batch_requests,
mssql_os_process_memory,
mssql_os_sys_memory,
mssql_database_state,
];

module.exports = {
Expand Down

0 comments on commit 225088f

Please sign in to comment.