Commit e9e5cf66 authored by Kyriakos Kritikos's avatar Kyriakos Kritikos
Browse files

Javadoc updated

parent 17a5ae21
......@@ -8,6 +8,7 @@
package eu.paasage.executionware.metric_collector.kairosdb;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Date;
......@@ -17,6 +18,7 @@ import java.util.List;
import org.kairosdb.client.HttpClient;
import org.kairosdb.client.builder.Aggregator;
import org.kairosdb.client.builder.AggregatorFactory;
import org.kairosdb.client.builder.DataFormatException;
import org.kairosdb.client.builder.DataPoint;
import org.kairosdb.client.builder.Metric;
import org.kairosdb.client.builder.MetricBuilder;
......@@ -37,24 +39,28 @@ public class KairosDbClient{
/**
*
* @param Kairos DB url
* @param url The Kairos DB url
*/
public KairosDbClient(String url){
this.url = url;
}
private void copyMetric(Metric m1, Metric m2) throws Exception{
private void copyMetric(Metric m1, Metric m2) throws DataFormatException{
for (DataPoint dp: m1.getDataPoints()) m2.addDataPoint(dp.getTimestamp(), dp.doubleValue());
m2.addTags(m1.getTags());
}
/**
*
* @param Insert a Metric m which is already instantiated
* @param m A Metric that has already been instantiated
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
* @throws org.kairosdb.client.builder.DataFormatException
* Insert a Metric already instantiated
* MetricName, Tags and Values should not be null
*
*/
public void putMetric(Metric m) throws Exception{
public void putMetric(Metric m) throws DataFormatException, IOException, MalformedURLException{
MetricBuilder builder = MetricBuilder.getInstance();
Metric m2 = builder.addMetric(m.getName(),m.getType());
copyMetric(m,m2);
......@@ -80,40 +86,58 @@ public class KairosDbClient{
* Insert a Metric which is not instantiated
* MetricName, Timestamp Tags and Values should not be null
*
* @param metricName
* @param tag t
* @param timestamp
* @param value
* @param metricName the name of the metric to instantiate
* @param t the tag associated to the metric
* @param timestamp the time of measurement
* @param value the value of measurement
*/
public void putMetric(String metricName, Tag t ,long timestamp, double value ) throws Exception{
public void putMetric(String metricName, Tag t ,long timestamp, double value ){
MetricBuilder builder = MetricBuilder.getInstance();
builder.addMetric(metricName)
.addDataPoint(timestamp, value)
.addTag(t.getName(), t.getValue());
HttpClient client = new HttpClient(this.url);
HttpClient client = null;
boolean created = false;
try {
client = new HttpClient(this.url);
created = true;
Response response = client.pushMetrics(builder);
if (response.getErrors().size() >0 ){
for(String e : response.getErrors())
System.err.println("Response error: "+ e);
}
} catch (URISyntaxException e) {
}
catch (MalformedURLException e) {
System.err.println("PaaSage KairosDB Client : Error pushing metric, Malformed URL Exception");
e.printStackTrace();
}
catch (URISyntaxException e) {
System.err.println("PaaSage KairosDB Client : Error pushing metric, URI Syntax error");
e.printStackTrace();
} catch (IOException e) {
System.err.println("PaaSage KairosDB Client : Error pushing metric, Io Exception");
e.printStackTrace();
}
client.shutdown();
if (created){
try{
client.shutdown();
}
catch(IOException e){
System.err.println("PaaSage KairosDB Client : Error closing the Http client, Io Exception");
e.printStackTrace();
}
}
}
/**
* Lists all metrics stored in the KairosDB and returns an
* ArrayList of their String representation
* @return ArrayList<String>
* Lists all metrics stored in the KairosDB
* @return an ArrayList of their string-based representation of metrics stored in KairosDB
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
*/
public ArrayList<String> ListAllMetrics() throws Exception{
public ArrayList<String> ListAllMetrics() throws IOException, MalformedURLException{
HttpClient client = new HttpClient(this.url);
ArrayList<String> metricNames = new ArrayList<String>();
GetResponse response;
......@@ -131,11 +155,12 @@ public class KairosDbClient{
}
/**
* Lists all the tag names stored in the KairosDb and returns an
* ArrayList of their String representation
* @return ArrayList<String>
* Lists all the tag names stored in the KairosDb and
* @return an ArrayList of their string-based representation of tags associated to metrics
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
*/
public ArrayList<String> ListAllTags() throws Exception{
public ArrayList<String> ListAllTags() throws IOException, MalformedURLException{
HttpClient client = new HttpClient(this.url);
ArrayList<String> metricTags = new ArrayList<String>();
GetResponse response;
......@@ -160,13 +185,15 @@ public class KairosDbClient{
* * This Query Builder is used with Absolute Dates
* for example from now till 2 days ago
*
* @param metric
* @param start
* @param end
* @param unit
* @return
* @param metric the metric in which the query is posed
* @param start the starting time period for the query
* @param end the ending time period for the query
* @param unit the respective time unit for the time period bounds
* @return a list of data points/measurements
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
*/
public List<DataPoint> QueryDataPoints(String metric, int start, int end, TimeUnit unit ) throws Exception{
public List<DataPoint> QueryDataPoints(String metric, int start, int end, TimeUnit unit ) throws IOException, MalformedURLException{
QueryBuilder builder = QueryBuilder.getInstance();
if (start != -1 && end != -1 && end > start)
......@@ -213,12 +240,14 @@ public class KairosDbClient{
*/
/**
*
* @param metric
* @param start
* @param end
* @return
* @param metric the metric on which the query is posed
* @param start the starting time period of the query
* @param end the ending time period of the query
* @return a list of data points / measurements
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
*/
public List<DataPoint> QueryDataPointsAbsolute(String metric, Date start, Date end) throws Exception{
public List<DataPoint> QueryDataPointsAbsolute(String metric, Date start, Date end) throws IOException, MalformedURLException{
QueryBuilder builder = QueryBuilder.getInstance();
builder.setStart(start)
......@@ -252,14 +281,16 @@ public class KairosDbClient{
* Same as Relative Query Builder plus the aggregator instance
*
*
* @param metric
* @param start
* @param end
* @param unit
* @param ag
* @return
* @param metric the metric on which the query is posed
* @param start the starting time period of the query
* @param end the ending time period of the query
* @param unit the time unit of the time period bounds
* @param ag the aggregator (e.g., average/mean) used for the query
* @throws IOException when something is wrong while closing the HttpClient
* @throws MalformedURLException when a wrong URL is provided
* @return a list of aggregated data points on measurements
*/
public List<DataPoint> QueryAggregatedDataPoints(String metric, int start, int end, TimeUnit unit, Aggregator ag ) throws Exception{
public List<DataPoint> QueryAggregatedDataPoints(String metric, int start, int end, TimeUnit unit, Aggregator ag ) throws IOException, MalformedURLException{
QueryBuilder builder = QueryBuilder.getInstance();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment