Skip to content

Commit

Permalink
Moved all monitoring stuff into single package
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbodart committed Jan 19, 2017
1 parent c7810f7 commit cddd796
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.googlecode.utterlyidle.graphite;
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.time.Clock;
import com.googlecode.totallylazy.time.Seconds;
import com.googlecode.utterlyidle.statsd.TcpMessenger;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -11,7 +10,7 @@

import static java.lang.String.format;

public interface CarbonSender extends Closeable {
public interface CarbonClient extends Closeable {
/**
* A gauge is an instantaneous measurement of a value, like the gas gauge in a car. It differs from a counter by being
* calculated at the client rather than the server.
Expand All @@ -22,9 +21,9 @@ public interface CarbonSender extends Closeable {
default void close() throws IOException {
}

static CarbonSender carbonSender(SocketAddress socketAddress, Clock clock) throws IOException {
static CarbonClient carbonSender(SocketAddress socketAddress, Clock clock) throws IOException {
TcpMessenger messenger = new TcpMessenger(SocketChannel.open(socketAddress));
return new CarbonSender() {
return new CarbonClient() {
@Override
public void gauge(final String name, final long value) throws IOException {
messenger.message(format("%s %s %s", name, value, Seconds.sinceEpoch(clock.now())));
Expand All @@ -37,7 +36,7 @@ public void close() throws IOException {
};
}

static CarbonSender noOp() {
static CarbonClient noOp() {
return (name, value) -> {
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import java.io.IOException;
import java.nio.channels.WritableByteChannel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.gelf;
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.LazyException;
import com.googlecode.totallylazy.Maps;
Expand All @@ -17,10 +17,10 @@
import static com.googlecode.totallylazy.security.GZip.gzip;
import static java.nio.ByteBuffer.wrap;

public interface GelfSender {
public interface GelfClient {
void send(String host, String shortMessage, Option<Date> timestamp, Severity severity, Map<String, Object> data);

static GelfSender udpGelfSender(SocketAddress socketAddress, Clock clock) throws IOException {
static GelfClient udpGelfClient(SocketAddress socketAddress, Clock clock) throws IOException {
DatagramChannel channel = DatagramChannel.open().connect(socketAddress);
return (host, shortMessage, timestamp, severity, data) -> {
Date time = timestamp.getOrElse(clock.now());
Expand All @@ -43,7 +43,7 @@ static Map<String, Object> gelf(String host, String shortMessage, Severity sever
return gelf;
}

static GelfSender noOp() {
static GelfClient noOp() {
return (String host, String shortMessage, Option<Date> timestamp, Severity severity, Map<String, Object> data) -> {};
}

Expand Down
36 changes: 36 additions & 0 deletions src/com/googlecode/utterlyidle/monitoring/JsonLinesClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.json.Json;

import java.io.Closeable;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.SocketChannel;

public interface JsonLinesClient extends Closeable {
void send(Object value) throws IOException;

@Override
default void close() throws IOException {
}

static JsonLinesClient jsonSender(SocketAddress socketAddress) throws IOException {
TcpMessenger messenger = new TcpMessenger(SocketChannel.open(socketAddress));
return new JsonLinesClient() {
@Override
public void send(final Object value) throws IOException {
messenger.message(Json.json(value));
}

@Override
public void close() throws IOException {
messenger.close();
}
};
}

static JsonLinesClient noOp() {
return value -> {
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.gelf;
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import java.io.Closeable;
import java.io.IOException;
Expand All @@ -22,7 +22,7 @@ static StatsDClient statsDClient(SocketAddress socketAddress) throws IOException
static StatsDClient statsDClient(final Messenger messenger) {
return () -> messenger;
}

static StatsDClient noOp() {
return Messenger::noOp;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.LazyException;

import java.io.IOException;
import java.net.SocketAddress;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SocketChannel;

public class TcpMessenger extends ChannelMessenger<SocketChannel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import com.googlecode.totallylazy.LazyException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.googlecode.utterlyidle.statsd;
package com.googlecode.utterlyidle.monitoring;

import org.junit.Ignore;
import org.junit.Test;

import java.util.ArrayList;
Expand All @@ -9,7 +8,7 @@
import static com.googlecode.totallylazy.Assert.assertThat;
import static com.googlecode.totallylazy.Sequences.sequence;
import static com.googlecode.totallylazy.predicates.Predicates.is;
import static com.googlecode.utterlyidle.statsd.StatsDClient.statsDClient;
import static com.googlecode.utterlyidle.monitoring.StatsDClient.statsDClient;

public class StatsDClientTest {
private List<String> messages = new ArrayList<>();
Expand Down

0 comments on commit cddd796

Please sign in to comment.