Skip to content

Commit

Permalink
#14 Send to InfluxDb ok
Browse files Browse the repository at this point in the history
  • Loading branch information
baardl committed Aug 1, 2017
1 parent 453f4c8 commit ecd1bf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ public class CommandSendActivities extends HystrixCommand<String> {
private static final Logger log = getLogger(CommandSendActivities.class);


private final String prefix;
private final List<ObservedActivity> observedActivities;
private final String reporterHost;
private final String reporterPort;
// private ObjectMapper mapper = new ObjectMapper();

private static final int STATUS_OK = 200;
private static final int STATUS_NO_CONTENT = 204;
private static final int STATUS_FORBIDDEN = 403;
Expand Down Expand Up @@ -55,14 +52,11 @@ public CommandSendActivities(URI influxDbUri, String databaseName, List<Observed
this.databaseName = databaseName;
observedActivitiesJson = buildBody(observedActivities);
no_of_activities = observedActivities.size();
this.reporterHost = null;
this.reporterPort = null;
this.prefix = null;
this.observedActivities = observedActivities;
}

protected String buildBody(List<ObservedActivity> observedActivities) {
String json = "client-access,host=dev.shareproc.com,service=api,function=login,ip=127.0.0.1 count=1\n";
//"client-access,host=whydahdev.cantara.no,service=sts,function=login,ip=127.0.0.1 count=1\n";
String body = "";
String line = "";
for (ObservedActivity activity : observedActivities) {
Expand Down Expand Up @@ -100,6 +94,7 @@ String buildTags(ObservedActivity activity) {

@Override
protected String run() {
String status = "OK";
String observationUrl = influxDbUri + "/write?db=" + databaseName;
// http://influxdb-component-ox6b3xp9td0-772793266.eu-west-1.elb.amazonaws.com:8086/write?db=shareproc";
log.info("Connection to InfluxDb on {} num of activities: {}" , observationUrl,no_of_activities);
Expand All @@ -115,6 +110,7 @@ protected String run() {
break;
case STATUS_FORBIDDEN:
log.warn("Can not access InfluxDb. The application will function as normally, though Observation statistics will not be stored. URL {}, HttpStatus {}, Response {}, ", observationUrl,statusCode, responseBody);
status = "FORBIDDEN";
break;
default:
log.trace("Retrying access to InfluxDb");
Expand All @@ -125,9 +121,10 @@ protected String run() {
log.trace("Retry via http ok. Response is {}", responseBody);
} else {
log.error("Error while accessing InfluxDb. The application will function as normally, though Observation statistics will not be stored. URL {}, HttpStatus {},Response from InfluxDb {}", observationUrl, statusCode, responseBody);
status = "FAILED";
}
}
return "OK";
return status;


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.valuereporter.activity.timeseries;

import org.slf4j.Logger;
import org.valuereporter.activity.CountedActivity;
import org.valuereporter.activity.ObservedActivity;

Expand All @@ -9,10 +10,13 @@
import java.util.List;
import java.util.Map;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Created by baardl on 31.07.17.
*/
public class ManualSendActivitiesTest {
private static final Logger log = getLogger(ManualSendActivitiesTest.class);

public static void main(String[] args) {
URI influxDbUri = URI.create("http://influxdb-component-ox6b3xp9td0-772793266.eu-west-1.elb.amazonaws.com:8086"); ///write?db=";
Expand All @@ -30,7 +34,8 @@ public static void main(String[] args) {
ObservedActivity activity = new CountedActivity(name,startTime,data);
observedActivities.add(activity);
CommandSendActivities sendActivities = new CommandSendActivities(influxDbUri, database, observedActivities);
sendActivities.execute();
String status = sendActivities.execute();
log.info("DONE. Status {}", status);
}

}

0 comments on commit ecd1bf9

Please sign in to comment.