Dynatrace API Module
Welcome to the Dynatrace Api node module. This is a simple helper module
for interacting with the Dynatrace API including caching support.
Requirements
- Dynatrace SaaS or Managed environment
- API key from Dynatrace environment
- Minimum node version 6.10
Basic Usage
Problem Feed and Details
const { Dynatrace } = require("@davis/dynatrace");
const redis = require("redis").createClient();
const dynatrace = new Dynatrace({
baseUrl: "https://base-url-of-dynatrace-server",
apiToken: "api-token-of-dynatrace-server",
redis: redis,
cacheTTL: 600,
cachePrefix: "davis-redis-cache"
});
dynatrace
.problemFeed({
relativeTime: "day"
})
.then(problems => {
console.log(`There were ${problems.length} problems in the last day.`);
return problems[0];
})
.then(problem => {
console.log(
`The first problem is a ${problem.status} ${problem.impactLevel} problem`
);
return problem.getDetails();
})
.then(details => {
console.log(`with ${details.commentCount} comments.`);
return details.addComment({
content: "Checked using the dynatrace nodejs client",
username: "@cto",
context: "nodejs client"
});
});
Timeseries
dynatrace
.applications({ tag: "davis" })
.then(apps => _.find(apps, a => a.displayName === "Davis"))
.then(davis => {
return davis.userActionDurationXHR({
queryMode: "total",
relativeTime: "day"
});
})
.then(data => {
console.log(util.inspect(data, null, null));
});
Deployments
Deploy An Application
async function deploy(entityId) {
const deployment = dynatrace.startDeployment({
deploymentName: "Test deployment",
deploymentProject: "dynatrace node module",
deploymentVersion: "0.0.1-7",
source: "dynatrace node module"
});
deployment.attachRules({ entityIds: [entityId] });
deployment.ciBackLink("https://link-to-ci");
return deployment.send();
}
Get Deployments
async function deployments(entityId) {
dynatrace
.applications()
.then(apps => apps[0])
.then(app => app.deployments())
.then(console.log);
}
Timeseries
dynatrace
.applications()
.then(apps => apps[0])
.then(app =>
app.userActionsPerMinute({
relativeTime: "2hours",
queryMode: "total",
aggregationType: "avg"
})
);