提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.influxdb.common.config; |
H |
2 |
|
585be5
|
3 |
import com.iailab.framework.tenant.core.context.TenantContextHolder; |
a6de49
|
4 |
import com.influxdb.client.InfluxDBClient; |
H |
5 |
import com.influxdb.client.InfluxDBClientFactory; |
|
6 |
import org.slf4j.Logger; |
|
7 |
import org.slf4j.LoggerFactory; |
|
8 |
import org.springframework.beans.factory.annotation.Value; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
|
|
11 |
/** |
|
12 |
* @author PanZhibao |
|
13 |
* @Description |
|
14 |
* @createTime 2023年04月25日 17:13:00 |
|
15 |
*/ |
|
16 |
@Component |
|
17 |
public class InfluxDBInstance { |
|
18 |
|
|
19 |
@Value("${influx-db.org}") |
|
20 |
public String org; |
|
21 |
|
d41f14
|
22 |
/*@Value("${influx-db.bucket}") |
潘 |
23 |
public String bucket;*/ |
52487d
|
24 |
|
a6de49
|
25 |
@Value("${influx-db.token}") |
H |
26 |
public String token; |
|
27 |
|
|
28 |
@Value("${influx-db.url}") |
|
29 |
public String url; |
585be5
|
30 |
|
d41f14
|
31 |
private final static String BUCKET_NAME = "bucket_"; |
a6de49
|
32 |
|
H |
33 |
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
34 |
|
|
35 |
private InfluxDBClient client; |
|
36 |
|
|
37 |
public InfluxDBClient getClient() { |
|
38 |
try { |
|
39 |
if (client == null) { |
|
40 |
client = InfluxDBClientFactory.create(url, token.toCharArray()); |
|
41 |
} |
|
42 |
} catch (Exception ex) { |
|
43 |
ex.printStackTrace(); |
|
44 |
logger.error("创建InfluxDBClient失败!"); |
|
45 |
} |
|
46 |
return client; |
|
47 |
} |
|
48 |
|
585be5
|
49 |
public String getBucket() { |
潘 |
50 |
return BUCKET_NAME + TenantContextHolder.getRequiredTenantId(); |
|
51 |
} |
0fbd01
|
52 |
|
a6de49
|
53 |
} |