public static BatchPoints create(String db, ZeitreihenDTO... zeitreihenDTOs) throws ParseException { BatchPoints batchPoints = BatchPoints.database(db).retentionPolicy("default").build(); for (ZeitreihenDTO zeitreihenDTO : zeitreihenDTOs) { for (Long timestamp : timestamps(zeitreihenDTO)) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTimeInMillis(timestamp); int monat = calendar.get(Calendar.MONTH) + 1; int jahr = calendar.get(Calendar.YEAR); batchPoints.point( Point.measurement("lastgang") .tag("zaehlpunktbezeichnung", zeitreihenDTO.zaehlpunktbezeichnung) .tag("commodity", zeitreihenDTO.commodity) .tag("zaehlverfahren", zeitreihenDTO.zaehlverfahren) .tag("monat", String.valueOf(monat)) .tag("jahr", String.valueOf(jahr)) .time(timestamp, TimeUnit.MILLISECONDS) .field("value", randomValue()) .build()); } } return batchPoints; }
/** * Save list of points to influxDB * * @param points list */ private void savePointsToDb(List<Point> points) { // add points to container if (points != null) { // ask for new container, we have to save each page on its own, so we don't run out of memory BatchPoints container = dbClient.giveMeEmptyContainer(); for (Point point : points) { container.point(point); } dbClient.saveContainerToDB(container); } }