2019-08-09 23:50:05 +00:00
|
|
|
import * as appInsights from "applicationinsights";
|
2019-04-17 22:18:35 +00:00
|
|
|
import * as https from "https";
|
|
|
|
import * as os from "os";
|
|
|
|
|
2019-07-16 19:57:02 +00:00
|
|
|
export class TelemetryClient implements appInsights.TelemetryClient {
|
|
|
|
public config: any = {};
|
2019-04-17 22:18:35 +00:00
|
|
|
|
|
|
|
public channel = {
|
|
|
|
setUseDiskRetryCaching: (): void => undefined,
|
|
|
|
};
|
|
|
|
|
2019-07-16 19:57:02 +00:00
|
|
|
public trackEvent(options: appInsights.EventTelemetry): void {
|
2019-04-17 22:18:35 +00:00
|
|
|
if (!options.properties) {
|
|
|
|
options.properties = {};
|
|
|
|
}
|
|
|
|
if (!options.measurements) {
|
|
|
|
options.measurements = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const cpus = os.cpus();
|
2019-07-16 19:57:02 +00:00
|
|
|
options.measurements.cores = cpus.length;
|
|
|
|
options.properties["common.cpuModel"] = cpus[0].model;
|
|
|
|
} catch (error) {}
|
2019-04-17 22:18:35 +00:00
|
|
|
|
|
|
|
try {
|
2019-07-16 19:57:02 +00:00
|
|
|
options.measurements.memoryFree = os.freemem();
|
|
|
|
options.measurements.memoryTotal = os.totalmem();
|
|
|
|
} catch (error) {}
|
2019-04-17 22:18:35 +00:00
|
|
|
|
|
|
|
try {
|
2019-07-16 19:57:02 +00:00
|
|
|
options.properties["common.shell"] = os.userInfo().shell;
|
|
|
|
options.properties["common.release"] = os.release();
|
|
|
|
options.properties["common.arch"] = os.arch();
|
|
|
|
} catch (error) {}
|
2019-04-17 22:18:35 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const request = https.request({
|
|
|
|
host: "v1.telemetry.coder.com",
|
|
|
|
port: 443,
|
|
|
|
path: "/track",
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
});
|
2019-07-16 19:57:02 +00:00
|
|
|
request.on("error", () => { /* We don't care. */ });
|
2019-04-17 22:18:35 +00:00
|
|
|
request.write(JSON.stringify(options));
|
|
|
|
request.end();
|
2019-07-16 19:57:02 +00:00
|
|
|
} catch (error) {}
|
2019-04-17 22:18:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 19:57:02 +00:00
|
|
|
public flush(options: appInsights.FlushOptions): void {
|
|
|
|
if (options.callback) {
|
|
|
|
options.callback("");
|
|
|
|
}
|
2019-04-17 22:18:35 +00:00
|
|
|
}
|
|
|
|
}
|