Skip to content

Instantly share code, notes, and snippets.

@ranfysvalle02
Last active February 21, 2023 14:34
Show Gist options
  • Save ranfysvalle02/70b0fc39ab8693c19197e8fe74449a42 to your computer and use it in GitHub Desktop.
Save ranfysvalle02/70b0fc39ab8693c19197e8fe74449a42 to your computer and use it in GitHub Desktop.
ATLAS API -> DYNATRACE (OR ANY OTHER API)
exports = async function(arg){
const AxiosDigestAuth = require('@mhoc/axios-digest-auth').default;
const axios = require('axios').default;
const digestAuth = new AxiosDigestAuth({
axios:axios,
username: "__USERNAME_GOES_HERE__",
password: "__PASSWORD_GOES_HERE__",
});
const response = await digestAuth.request({
headers: { Accept: "application/json" },
method: "GET",
url: 'https://cloud.mongodb.com/api/atlas/v1.0/groups/__GROUP_ID__/processes/__process__.mongodb.net:27017/measurements?granularity=PT1M&period=PT1M&pretty=true&m=MEMORY_VIRTUAL&m=OPLOG_RATE_GB_PER_HOUR&m=CACHE_DIRTY_BYTES',
});
let resJSON = {};
resJSON = Object.values(response.data.measurements[1]['dataPoints']);
resJSON = resJSON[0];
resJSON = Object.values(resJSON);
if(resJSON[1]){resJSON[1]=JSON.stringify(resJSON[1]);}
if(resJSON[1]){
let resJSON2 = await axios.post(
'https://bnt27255.live.dynatrace.com/api/v2/metrics/ingest',
"DEMODEMO,client=CLIENTNAMEGOESHERE,environment=PROD "+String(resJSON[1]),
{
headers: {
"Content-Type": "text/plain",
"Accept": "*/*",
"Authorization": "Api-Token dt0c01.W7OKYYCTAXAZC7SA4VZGOTDZ.364W2BWCPC5BORAXV3HVNLABRTPO622FUE7MML2ERI4A3AWGPVMELJM7YSCDRUCQ"
}
}
);
}
return {debug:resJSON[1],x:"MDB_UPS.server0,VIRTUAL_MEMORY=0 "+String(resJSON[1]),OK: true};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment