| | |
| | | import com.influxdb.client.InfluxDBClient; |
| | | import com.influxdb.client.InfluxDBClientFactory; |
| | | import com.influxdb.client.domain.Bucket; |
| | | import com.influxdb.client.domain.BucketRetentionRules; |
| | | import com.influxdb.client.domain.Organization; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | |
| | | private Set<String> isExistBucket = new HashSet<>(); |
| | | |
| | | private final static String BUCKET_NAME = "bucket_model_"; |
| | | private final static String BUCKET_NAME = "bucket_"; |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | private InfluxDBClient client; |
| | | // bucket过期时间 |
| | | private Integer everySeconds = 3600 * 24 * 10; |
| | | |
| | | public InfluxDBClient getClient() { |
| | | try { |
| | |
| | | Bucket bucketByName = client.getBucketsApi().findBucketByName(bucketName); |
| | | if (null == bucketByName) { |
| | | Organization organization = client.getOrganizationsApi().findOrganizations().stream().filter(e -> e.getName().equals(org)).findFirst().orElseThrow(() -> new RuntimeException("influxdb:org不存在,org:" + org)); |
| | | client.getBucketsApi().createBucket(bucketName,organization); |
| | | // 创建Bucket,并设置过期时间 |
| | | client.getBucketsApi().createBucket(bucketName,new BucketRetentionRules().everySeconds(everySeconds),organization); |
| | | }else { |
| | | isExistBucket.add(bucketName); |
| | | } |