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

Commit a5b0b33

Browse files
author
Florian Lautenschlager
committed
Added simple client example.
1 parent 1217925 commit a5b0b33

File tree

11 files changed

+436
-1
lines changed

11 files changed

+436
-1
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: java
2+
3+
jdk:
4+
- oraclejdk8
5+
6+
before_install:
7+
- chmod +x gradlew
8+
9+
script: ./gradlew clean build

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ subprojects {
109109

110110
additionalSourceDirs = project.files(sourceSets.main.allSource.srcDirs)
111111
sourceDirectories = project.files(sourceSets.main.allSource.srcDirs)
112-
classDirectories = project.files(sourceSets.main.output)
112+
classDirectories = project.files(sourceSets.main.output)
113113

114114
reports {
115115
xml.enabled = true

chronix-server-integration/LICENSE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (C) 2015 QAware GmbH
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
17+
repositories {
18+
mavenCentral()
19+
maven {
20+
url "http://dl.bintray.com/chronix/maven"
21+
}
22+
}
23+
24+
dependencies {
25+
26+
//Some logging stuff
27+
compile 'org.slf4j:slf4j-api:1.7.12'
28+
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.4'
29+
compile 'org.apache.logging.log4j:log4j-api:2.4'
30+
compile 'org.apache.logging.log4j:log4j-core:2.4'
31+
32+
//Chronix
33+
compile 'de.qaware.chronix:chronix-api:0.1'
34+
compile 'de.qaware.chronix:chronix-server-client:0.1'
35+
compile 'de.qaware.chronix:chronix-kassiopeia-simple:0.1'
36+
compile 'de.qaware.chronix:chronix-kassiopeia-simple-converter:0.1'
37+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package de.qaware.chronix.examples.server;/*
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+
17+
import de.qaware.chronix.ChronixClient;
18+
import de.qaware.chronix.converter.KassiopeiaSimpleConverter;
19+
import de.qaware.chronix.solr.client.ChronixSolrStorage;
20+
import de.qaware.chronix.timeseries.MetricTimeSeries;
21+
import org.apache.solr.client.solrj.SolrClient;
22+
import org.apache.solr.client.solrj.SolrQuery;
23+
import org.apache.solr.client.solrj.impl.HttpSolrClient;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
import java.util.List;
28+
import java.util.function.BinaryOperator;
29+
import java.util.function.Function;
30+
import java.util.stream.Collectors;
31+
import java.util.stream.Stream;
32+
33+
/**
34+
* An example showcase of how to integrate chronix into your application.
35+
* Works with the release 0.1 of the chronix-server
36+
* Download at <a href="https://github.com/ChronixDB/chronix.server/releases/download/v0.1/chronix-0.1.zip">chronix-server-0.1</a>
37+
*
38+
* @author f.lautenschlager
39+
*/
40+
public class ChronixClientExample {
41+
42+
private static final Logger LOGGER = LoggerFactory.getLogger(ChronixClientExample.class);
43+
44+
public static void main(String[] args) {
45+
SolrClient solr = new HttpSolrClient("http://localhost:8983/solr/chronix/");
46+
47+
//Define a group by function for the time series records
48+
Function<MetricTimeSeries, String> groupBy = ts -> ts.getMetric() + "-" + ts.attribute("host");
49+
50+
//Define a reduce function for the grouped time series records
51+
BinaryOperator<MetricTimeSeries> reduce = (ts1, ts2) -> {
52+
MetricTimeSeries.Builder reduced = new MetricTimeSeries
53+
.Builder(ts1.getMetric())
54+
.data(concat(ts1.getTimestamps(), ts2.getTimestamps()),
55+
concat(ts1.getValues(), ts2.getValues()))
56+
.attributes(ts2.attributes());
57+
return reduced.build();
58+
};
59+
//Instantiate a Chronix Client
60+
ChronixClient<MetricTimeSeries, SolrClient, SolrQuery> chronix = new ChronixClient<>(
61+
new KassiopeiaSimpleConverter(), new ChronixSolrStorage<>(200, groupBy, reduce));
62+
63+
//We want the maximum of all time series that metric matches *load*.
64+
SolrQuery query = new SolrQuery("metric:*Load*");
65+
query.addFilterQuery("ag=max");
66+
67+
//The result is a Java Stream. We simply collect the result into a list.
68+
List<MetricTimeSeries> maxTS = chronix.stream(solr, query).collect(Collectors.toList());
69+
70+
//Just print it out.
71+
LOGGER.info("Result for query {} is: {}", query, prettyPrint(maxTS));
72+
}
73+
74+
private static String prettyPrint(List<MetricTimeSeries> maxTS) {
75+
StringBuilder sb = new StringBuilder("\n");
76+
77+
for (MetricTimeSeries ts : maxTS) {
78+
sb.append("metric:[")
79+
.append(ts.getMetric())
80+
.append("] with value: [")
81+
.append(ts.getValues().collect(Collectors.toList()))
82+
.append("]")
83+
.append("\n");
84+
}
85+
return sb.toString();
86+
}
87+
88+
private static <T> List<T> concat(Stream<T> timestamps, Stream<T> timestamps1) {
89+
return Stream.concat(timestamps, timestamps1).collect(Collectors.toList());
90+
}
91+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="info" packages="de.qaware.chronix.examples.exploration.ui.log">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="info">
10+
<AppenderRef ref="Console"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>
14+

chronix-timeseries-exploration/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
*/
116
dependencies {
217

318
//SLF4J interface

gradlew

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/usr/bin/env bash
2+
3+
##############################################################################
4+
##
5+
## Gradle start up script for UN*X
6+
##
7+
##############################################################################
8+
9+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10+
DEFAULT_JVM_OPTS=""
11+
12+
APP_NAME="Gradle"
13+
APP_BASE_NAME=`basename "$0"`
14+
15+
# Use the maximum available, or set MAX_FD != -1 to use that value.
16+
MAX_FD="maximum"
17+
18+
warn ( ) {
19+
echo "$*"
20+
}
21+
22+
die ( ) {
23+
echo
24+
echo "$*"
25+
echo
26+
exit 1
27+
}
28+
29+
# OS specific support (must be 'true' or 'false').
30+
cygwin=false
31+
msys=false
32+
darwin=false
33+
case "`uname`" in
34+
CYGWIN* )
35+
cygwin=true
36+
;;
37+
Darwin* )
38+
darwin=true
39+
;;
40+
MINGW* )
41+
msys=true
42+
;;
43+
esac
44+
45+
# For Cygwin, ensure paths are in UNIX format before anything is touched.
46+
if $cygwin ; then
47+
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48+
fi
49+
50+
# Attempt to set APP_HOME
51+
# Resolve links: $0 may be a link
52+
PRG="$0"
53+
# Need this for relative symlinks.
54+
while [ -h "$PRG" ] ; do
55+
ls=`ls -ld "$PRG"`
56+
link=`expr "$ls" : '.*-> \(.*\)$'`
57+
if expr "$link" : '/.*' > /dev/null; then
58+
PRG="$link"
59+
else
60+
PRG=`dirname "$PRG"`"/$link"
61+
fi
62+
done
63+
SAVED="`pwd`"
64+
cd "`dirname \"$PRG\"`/" >&-
65+
APP_HOME="`pwd -P`"
66+
cd "$SAVED" >&-
67+
68+
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69+
70+
# Determine the Java command to use to start the JVM.
71+
if [ -n "$JAVA_HOME" ] ; then
72+
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73+
# IBM's JDK on AIX uses strange locations for the executables
74+
JAVACMD="$JAVA_HOME/jre/sh/java"
75+
else
76+
JAVACMD="$JAVA_HOME/bin/java"
77+
fi
78+
if [ ! -x "$JAVACMD" ] ; then
79+
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80+
81+
Please set the JAVA_HOME variable in your environment to match the
82+
location of your Java installation."
83+
fi
84+
else
85+
JAVACMD="java"
86+
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87+
88+
Please set the JAVA_HOME variable in your environment to match the
89+
location of your Java installation."
90+
fi
91+
92+
# Increase the maximum file descriptors if we can.
93+
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94+
MAX_FD_LIMIT=`ulimit -H -n`
95+
if [ $? -eq 0 ] ; then
96+
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97+
MAX_FD="$MAX_FD_LIMIT"
98+
fi
99+
ulimit -n $MAX_FD
100+
if [ $? -ne 0 ] ; then
101+
warn "Could not set maximum file descriptor limit: $MAX_FD"
102+
fi
103+
else
104+
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105+
fi
106+
fi
107+
108+
# For Darwin, add options to specify how the application appears in the dock
109+
if $darwin; then
110+
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111+
fi
112+
113+
# For Cygwin, switch paths to Windows format before running java
114+
if $cygwin ; then
115+
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116+
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117+
118+
# We build the pattern for arguments to be converted via cygpath
119+
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120+
SEP=""
121+
for dir in $ROOTDIRSRAW ; do
122+
ROOTDIRS="$ROOTDIRS$SEP$dir"
123+
SEP="|"
124+
done
125+
OURCYGPATTERN="(^($ROOTDIRS))"
126+
# Add a user-defined pattern to the cygpath arguments
127+
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128+
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129+
fi
130+
# Now convert the arguments - kludge to limit ourselves to /bin/sh
131+
i=0
132+
for arg in "$@" ; do
133+
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134+
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135+
136+
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137+
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138+
else
139+
eval `echo args$i`="\"$arg\""
140+
fi
141+
i=$((i+1))
142+
done
143+
case $i in
144+
(0) set -- ;;
145+
(1) set -- "$args0" ;;
146+
(2) set -- "$args0" "$args1" ;;
147+
(3) set -- "$args0" "$args1" "$args2" ;;
148+
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149+
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150+
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151+
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152+
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153+
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154+
esac
155+
fi
156+
157+
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158+
function splitJvmOpts() {
159+
JVM_OPTS=("$@")
160+
}
161+
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162+
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163+
164+
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

0 commit comments

Comments
 (0)