Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 68e1bf3

Browse files
author
Florian Lautenschlager
committed
Added example with Chronix-Kassiopeia.
1 parent 5da7352 commit 68e1bf3

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

chronix-server-integration/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,15 @@ dependencies {
3232
//Chronix
3333
compile 'de.qaware.chronix:chronix-api:0.1'
3434
compile 'de.qaware.chronix:chronix-server-client:0.1.1'
35+
36+
//Kassiopeia-Simple
3537
compile 'de.qaware.chronix:chronix-kassiopeia-simple:0.1.1'
3638
compile 'de.qaware.chronix:chronix-kassiopeia-simple-converter:0.1.1'
3739

40+
//Kassiopeia
41+
compile 'de.qaware.chronix:chronix-kassiopeia:0.1.1'
42+
compile 'de.qaware.chronix:chronix-kassiopeia-converter:0.1.1'
43+
3844
//Solr
3945
compile 'org.apache.solr:solr-solrj:5.4.0'
4046

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2015 QAware GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package de.qaware.chronix.examples.server;
17+
18+
import de.qaware.chronix.ChronixClient;
19+
import de.qaware.chronix.converter.KassiopeiaConverter;
20+
import de.qaware.chronix.solr.client.ChronixSolrStorage;
21+
import de.qaware.chronix.timeseries.TimeSeries;
22+
import org.apache.solr.client.solrj.SolrClient;
23+
import org.apache.solr.client.solrj.SolrQuery;
24+
import org.apache.solr.client.solrj.impl.HttpSolrClient;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
28+
import java.util.List;
29+
import java.util.function.BinaryOperator;
30+
import java.util.function.Function;
31+
import java.util.stream.Collectors;
32+
33+
import static de.qaware.chronix.timeseries.TimeSeries.merge;
34+
35+
/**
36+
* An example showcase of how to integrate chronix into your application.
37+
* Works with the release 0.1.1 of the chronix-server
38+
* Download at <a href="https://github.com/ChronixDB/chronix.server/releases/download/v0.1/chronix-0.1.zip">chronix-server-0.1.1</a>
39+
* Note: The example data stored in the release
40+
*
41+
* @author f.lautenschlager
42+
*/
43+
public class ChronixClientExampleWithKassiopeia {
44+
45+
private static final Logger LOGGER = LoggerFactory.getLogger(ChronixClientExampleWithKassiopeia.class);
46+
47+
public static void main(String[] args) {
48+
SolrClient solr = new HttpSolrClient("http://localhost:8983/solr/chronix/");
49+
50+
//Define a group by function for the time series records
51+
Function<TimeSeries<Long, Double>, String> groupBy = ts -> ts.getAttribute("metric") + "-" + ts.getAttribute("host");
52+
53+
//Define a reduce function for the grouped time series records. We use the average.
54+
BinaryOperator<TimeSeries<Long, Double>> reduce = (ts1, ts2) -> merge(ts1, ts2, (y1, y2) -> (y1 + y2) / 2);
55+
56+
//Instantiate a Chronix Client
57+
ChronixClient<TimeSeries<Long, Double>, SolrClient, SolrQuery> chronix = new ChronixClient<>(
58+
new KassiopeiaConverter(), new ChronixSolrStorage<>(200, groupBy, reduce));
59+
60+
//We want the maximum of all time series that metric matches *load*.
61+
SolrQuery query = new SolrQuery("metric:*Load*");
62+
query.addFilterQuery("ag=max");
63+
64+
//The result is a Java Stream. We simply collect the result into a list.
65+
List<TimeSeries<Long, Double>> maxTS = chronix.stream(solr, query).collect(Collectors.toList());
66+
67+
//Just print it out.
68+
LOGGER.info("Result for query {} is: {}", query, maxTS);
69+
}
70+
71+
72+
}

chronix-server-integration/src/main/java/de/qaware/chronix/examples/server/ChronixClientExample.java renamed to chronix-server-integration/src/main/java/de/qaware/chronix/examples/server/ChronixClientExampleWithKassiopeiaSimple.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333
import java.util.stream.Collectors;
3434

3535
/**
36-
* An example showcase of how to integrate chronix into your application.
37-
* Works with the release 0.1 of the chronix-server
38-
* Download at <a href="https://github.com/ChronixDB/chronix.server/releases/download/v0.1/chronix-0.1.zip">chronix-server-0.1</a>
36+
* An example showcase of how to integrate chronix into your application using kassiopeia-simple
37+
* Works with the release 0.1.1 of the chronix-server
38+
* Download at <a href="https://github.com/ChronixDB/chronix.server/releases/download/v0.1.1/chronix-0.1.1.zip">chronix-server-0.1.1</a>
3939
*
4040
* @author f.lautenschlager
4141
*/
42-
public class ChronixClientExample {
42+
public class ChronixClientExampleWithKassiopeiaSimple {
43+
44+
private static final Logger LOGGER = LoggerFactory.getLogger(ChronixClientExampleWithKassiopeiaSimple.class);
4345

44-
private static final Logger LOGGER = LoggerFactory.getLogger(ChronixClientExample.class);
4546

4647
public static void main(String[] args) {
4748
SolrClient solr = new HttpSolrClient("http://localhost:8983/solr/chronix/");
@@ -91,6 +92,7 @@ private static LongList concat(LongList first, LongList second) {
9192
first.addAll(second);
9293
return first;
9394
}
95+
9496
private static DoubleList concat(DoubleList first, DoubleList second) {
9597
first.addAll(second);
9698
return first;

0 commit comments

Comments
 (0)