This repository has been archived by the owner on Oct 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrop-series.ts
59 lines (49 loc) · 1.61 KB
/
drop-series.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import {
InfluxDB,
FieldType as InfluxFieldType,
IPoint,
ISchemaOptions,
ISingleHostConfig,
IExpressionHead
} from 'influx';
import * as _ from 'lodash';
const config = {
INFLUXDB_HOST: 'waffle-server-monitoring.gapminderdev.org',
INFLUXDB_PORT: 8086,
INFLUXDB_DATABASE_NAME: 'waffle-server-dev',
INFLUXDB_USER: 'gapminderdev',
INFLUXDB_PASSWORD: '',
}
const influxdbConfig: ISingleHostConfig = {
host: config.INFLUXDB_HOST,
port: +config.INFLUXDB_PORT,
username: config.INFLUXDB_USER,
password: config.INFLUXDB_PASSWORD,
database: config.INFLUXDB_DATABASE_NAME
};
const tagName = 'hostname';
const influxService: InfluxDB = new InfluxDB(influxdbConfig);
function run(dbNames: string[]): void {
const query = `SELECT hostname FROM (SELECT LAST(_active), hostname FROM instances GROUP BY hostname) WHERE time > now() - 2d ORDER BY time DESC`;
dbNames.forEach(async function (database: string): Promise<void> {
try {
const hosts = await influxService.query(query, {database});
hosts.forEach((host: string) => dropSeriesByHostname(_.get(host, 'hostname'), database));
} catch (error) {
console.error(error);
}
});
}
async function dropSeriesByHostname(hostname: string, database: string): Promise<void> {
const fn = (e: IExpressionHead): IExpressionHead => {
return e.tag(tagName).equals.value(hostname);
};
try {
console.log(database, hostname);
//await influxService.dropSeries({where: fn, database});
} catch (error) {
console.error(error);
}
}
run(['waffle-server-prod', 'waffle-server-dev', 'waffle-server-local']);
console.log('Finish');