Skip to content

Commit

Permalink
renamed up metric to mssql_up based on #27
Browse files Browse the repository at this point in the history
updated docker run command to be more self contained and cleans up after itself
rename test server to start
  • Loading branch information
Pierre Awaragi committed Mar 20, 2022
1 parent 562b406 commit 4a2069f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ To execute and the application using locally running mssql (see above for how to
use the following command which will generate all a detailed logs

```shell
npm run test:serve
npm start
```

A more verbose execution with all queries and their results printed out

```shell
npm run test:serve:verbose
npm run start:verbose
```

### Using Docker
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Request = require('tedious').Request;
const app = require('express')();

const client = require('./metrics').client;
const up = require('./metrics').up;
const mssql_up = require('./metrics').mssql_up;
const metrics = require('./metrics').metrics;

let config = {
Expand Down Expand Up @@ -92,7 +92,7 @@ async function measure(connection, collector) {
* @returns Promise of execution (no value returned)
*/
async function collect(connection) {
up.set(1);
mssql_up.set(1);
for (let i = 0; i < metrics.length; i++) {
await measure(connection, metrics[i]);
}
Expand All @@ -111,9 +111,9 @@ app.get('/metrics', async (req, res) => {
} catch (error) {
// error connecting
appLog("Error handling metrics request");
up.set(0);
mssql_up.set(0);
res.header("X-Error", error.message || error);
res.send(client.register.getSingleMetricAsString(up.name));
res.send(client.register.getSingleMetricAsString(mssql_up.name));
}
});

Expand Down
4 changes: 2 additions & 2 deletions metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const metricsLog = require("debug")("metrics");
const client = require('prom-client');

// UP metric
const up = new client.Gauge({name: 'up', help: "UP Status"});
const mssql_up = new client.Gauge({name: 'mssql_up', help: "UP Status"});

// Query based metrics
// -------------------
Expand Down Expand Up @@ -260,7 +260,7 @@ const metrics = [

module.exports = {
client: client,
up: up,
mssql_up,
metrics: metrics,
};

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
},
"scripts": {
"docker:build": "docker build . -t awaragi/prometheus-mssql-exporter",
"docker:run": "docker run --name prometheus-mssql-exporter --rm -it -p 4000:4000 -e SERVER=$(docker inspect mssql | jq -r '.[].NetworkSettings.Networks.bridge.IPAddress') -e USERNAME=SA -e PASSWORD=qkD4x3yy -e DEBUG=app,db,metrics $(docker build -q .)",
"docker:run": "export DOCKERID=$(docker build -q .) && docker run --name prometheus-mssql-exporter --rm -it -p 4000:4000 -e SERVER=$(docker inspect mssql | jq -r '.[].NetworkSettings.Networks.bridge.IPAddress') -e USERNAME=SA -e PASSWORD=qkD4x3yy -e DEBUG=app,db,metrics $DOCKERID && docker image rm $DOCKERID",

"test:serve": "DEBUG=app,db,metrics SERVER=localhost USERNAME=SA PASSWORD=qkD4x3yy node ./index.js",
"test:serve:verbose": "DEBUG=app,db,metrics,metrics SERVER=localhost USERNAME=SA PASSWORD=qkD4x3yy node ./index.js",
"start": "DEBUG=app,db,metrics SERVER=localhost USERNAME=SA PASSWORD=qkD4x3yy node ./index.js",
"start:verbose": "DEBUG=app,db,metrics,metrics SERVER=localhost USERNAME=SA PASSWORD=qkD4x3yy node ./index.js",

"test:mssql:2019": "docker run --name mssql --rm -e ACCEPT_EULA=Y -e SA_PASSWORD=qkD4x3yy -p 1433:1433 --name mssql mcr.microsoft.com/mssql/server:2019-latest",
"test:mssql:2017": "docker run --name mssql --rm -e ACCEPT_EULA=Y -e SA_PASSWORD=qkD4x3yy -p 1433:1433 --name mssql mcr.microsoft.com/mssql/server:2017-latest",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('E2E Test', function () {
const lines = parse(text);

// some specific tests
expect(lines.up).toBe(1);
expect(lines.mssql_up).toBe(1);
expect(lines.mssql_instance_local_time).toBeGreaterThan(0);
expect(lines.mssql_total_physical_memory_kb).toBeGreaterThan(0);

Expand All @@ -33,7 +33,7 @@ describe('E2E Test', function () {

// bulk ensure that all expected results of a vanilla mssql server instance are here
expect(Object.keys(lines)).toEqual([
"up",
"mssql_up",
"mssql_instance_local_time",
"mssql_connections{database=\"master\",state=\"current\"}",
"mssql_deadlocks",
Expand Down

0 comments on commit 4a2069f

Please sign in to comment.