@Test
    public void testNodeMetricsReadWrite() {
        String dataDir = createEmptyDataDir("QuestMetricsDbReadWrite", "metrics");
        ManualClock clock = new ManualClock("2020-10-01T00:00:00");
        QuestMetricsDb db = new QuestMetricsDb(dataDir, clock);
        Instant startTime = clock.instant();

        clock.advance(Duration.ofSeconds(1));
        db.addNodeMetrics(nodeTimeseries(1000, Duration.ofSeconds(1), clock, "host1", "host2", "host3"));

        clock.advance(Duration.ofSeconds(1));

        // Read all of one host
        List<NodeTimeseries> nodeTimeSeries1 = db.getNodeTimeseries(Duration.between(startTime, clock.instant()),
                                                                    Set.of("host1"));
        assertEquals(1, nodeTimeSeries1.size());
        assertEquals("host1", nodeTimeSeries1.get(0).hostname());
        assertEquals(1000, nodeTimeSeries1.get(0).size());
        NodeMetricSnapshot snapshot = nodeTimeSeries1.get(0).asList().get(0);
        assertEquals(startTime.plus(Duration.ofSeconds(1)), snapshot.at());
        assertEquals(0.1, snapshot.load().cpu(), delta);
        assertEquals(0.2, snapshot.load().memory(), delta);
        assertEquals(0.4, snapshot.load().disk(), delta);
        assertEquals(0.5, snapshot.load().gpu(), delta);
        assertEquals(0.6, snapshot.load().gpuMemory(), delta);
        assertEquals(1, snapshot.generation(), delta);
        assertEquals(30, snapshot.queryRate(), delta);

        // Read all from 2 hosts
        List<NodeTimeseries> nodeTimeSeries2 = db.getNodeTimeseries(Duration.between(startTime, clock.instant()),
                                                                    Set.of("host2", "host3"));
        assertEquals(2, nodeTimeSeries2.size());
        assertEquals(Set.of("host2", "host3"), nodeTimeSeries2.stream().map(ts -> ts.hostname()).collect(Collectors.toSet()));
        assertEquals(1000, nodeTimeSeries2.get(0).size());
        assertEquals(1000, nodeTimeSeries2.get(1).size());

        // Read a short interval from 3 hosts
        List<NodeTimeseries> nodeTimeSeries3 = db.getNodeTimeseries(Duration.ofSeconds(3),
                                                                    Set.of("host1", "host2", "host3"));
        assertEquals(3, nodeTimeSeries3.size());
        assertEquals(Set.of("host1", "host2", "host3"), nodeTimeSeries3.stream().map(ts -> ts.hostname()).collect(Collectors.toSet()));
        assertEquals(2, nodeTimeSeries3.get(0).size());
        assertEquals(2, nodeTimeSeries3.get(1).size());
        assertEquals(2, nodeTimeSeries3.get(2).size());
    }
Print query rate from a real database.

How to use:

1. Download data from a production config server: rsync -az --progress cfgN.example.com:/data/vespa/storage/cfgN/opt/vespa/var/db/vespa/autoscaling /tmp/cfgN-questdb
2. Set application ID and cluster ID
3. Adjust start and end instant as necessary
4. Run test to print data
5. Output from test can be used as test input in {@link ClusterTimeseriesTest}
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/QuestMetricsDbTest.java