The native Java Client
A Java client that is used to store and stream time series from Chronix.
The following code snippet shows how to setup an connection to Chronix and stream time series.
The examples uses the Chronix API, Chronix Server Client,
//An connection to Solr
SolrClient solr = new HttpSolrClient("http://localhost:8983/solr/chronix/");
//Define a group by function for the time series records
Function<MetricTimeSeries, String> groupBy = ts -> ts.getMetric() + "-" + ts.attribute("host");
//Define a reduce function for the grouped time series records
BinaryOperator<MetricTimeSeries> reduce = (ts1, ts2) -> {
MetricTimeSeries.Builder reduced = new MetricTimeSeries.Builder(ts1.getMetric())
.points(concat(ts1.getTimestamps(), ts2.getTimestamps()),
concat(ts1.getValues(), ts2.getValues()))
.attributes(ts1.attributes());
return reduced.build();
};
//Create a Chronix Client with Kassiopeia Simple and the Chronix Solr Storage
ChronixClient<MetricTimeSeries,SolrClient,SolrQuery> chronix =
new ChronixClient<>(new KassiopeiaSimpleConverter(),
new ChronixSolrStorage<>(nrOfDocsPerBatch,groupBy,reduce));
//Lets stream time series from Chronix. We want the maximum of all time series that metric matches *load*.
SolrQuery query = new SolrQuery("metric:*load*");
query.addFilterQuery("function=max");
//The result is a Java Stream. We simply collect the result into a list.
List<MetricTimeSeries> maxTS = chronix.stream(solr, query).collect(Collectors.toList());