SendAlarmTool.java
1.14 KB
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
/**
*
*/
package com.yoho.jobs.server.alarm;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.influxdb.dto.Point;
import org.influxdb.dto.Point.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author yanzhang.fu
*
*/
public class SendAlarmTool {
private Logger logger = LoggerFactory.getLogger(SendAlarmTool.class);
private InfluxDbSource dbSource;
private static final String DATABASE = "yoho-monitor";
private static final String MEASUREMENT = "yoho_job_alarm";
public void sendAlarm(Map<String, String> tags, Map<String, Object> fields) {
logger.info("send job alarm");
try {
Builder builder = Point.measurement(MEASUREMENT).time(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
builder.tag(tags);
builder.fields(fields);
dbSource.getInfluxDb().write(DATABASE, "default", builder.build());
logger.info("send alarm {} success", this.MEASUREMENT);
} catch (Exception e) {
logger.error("send job alarm failed.", e);
}
}
public InfluxDbSource getDbSource() {
return dbSource;
}
public void setDbSource(InfluxDbSource dbSource) {
this.dbSource = dbSource;
}
}