Created
November 12, 2019 03:13
-
-
Save ninapavlich/c774d7cbb04cee2b8a0b2aa254d85895 to your computer and use it in GitHub Desktop.
Check if datadog agent is running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetch = require('node-fetch'); | |
const hotShots = require('hot-shots'); | |
const ddAgentHost = process.env.DD_AGENT_HOST || 'localhost'; | |
async function checkAgentStatus() { | |
let metricsUp = 'OK (no error returned)'; | |
let apmUp = ''; | |
const datadog = new hotShots.StatsD({ | |
protocol: undefined, | |
host: ddAgentHost, | |
port: 8125, | |
errorHandler(error) { | |
metricsUp += `errorHandler: ${error}`; | |
}, | |
}); | |
await datadog.close(async (error) => { | |
metricsUp = await `Close error: ${error}`; | |
console.log(metricsUp); | |
}); | |
await fetch(`http://${ddAgentHost}:8126/services`) | |
.then(async (response) => { | |
console.log(await response.text()); | |
apmUp = response.statusText; | |
}) | |
.catch((error) => { | |
apmUp = error; | |
}); | |
return { | |
metricsUp, | |
apmUp, | |
}; | |
} | |
module.exports = { | |
checkAgentStatus, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment