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

Add database state metric #15

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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