diff --git a/README.md b/README.md index b000e8e..12b5fad 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,24 @@ docker run -d -p 9401:9401 -e OCTONET_IP=172.20.20.121 octonet-exporter ## How to compile a binary? To compile a binary, run `mvn clean compile assembly:single` in the project directory. This will create a JAR file in the `target` directory that you can run using `java -jar octonet-exporter-1.0-SNAPSHOT-jar-with-dependencies.jar`. + +## Prometheus config +This exporter does not need any special configuration in Prometheus. + +```yaml +scrape_configs: + - job_name: "octonet-exporter" + static_configs: + - targets: ["octonet-exporter:9401"] +``` +This will completely suffice. + +## Getting this running quickly: +1. Run this program in any way you prefer. I recommend using Docker or Podman in order to avoid cluttering your system with dependencies. +2. Configure Prometheus to scrape this exporter. You can use the provided example configuration as a starting point. +3. Configure your Grafana to use Prometheus as a data source. (If you've already have been running Grafana, you have probably already done this.) +4. Create a dashboard in any way you like! :) + +Happy DXing, + +Fey. diff --git a/pom.xml b/pom.xml index 441109e..b498a40 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ moe.yo3explorer octonet-exporter - 1.0-SNAPSHOT + 1.1 11 diff --git a/src/main/java/moe/yo3explorer/octonet_exporter/Main.java b/src/main/java/moe/yo3explorer/octonet_exporter/Main.java index f03ffbc..6746882 100644 --- a/src/main/java/moe/yo3explorer/octonet_exporter/Main.java +++ b/src/main/java/moe/yo3explorer/octonet_exporter/Main.java @@ -3,9 +3,7 @@ package moe.yo3explorer.octonet_exporter; import com.fasterxml.jackson.databind.ObjectMapper; import io.prometheus.metrics.core.metrics.Gauge; import io.prometheus.metrics.exporter.httpserver.HTTPServer; -import moe.yo3explorer.octonet_exporter.entities.FanspeedResponse; -import moe.yo3explorer.octonet_exporter.entities.Tuner; -import moe.yo3explorer.octonet_exporter.entities.TunerResponse; +import moe.yo3explorer.octonet_exporter.entities.*; import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -16,6 +14,7 @@ import org.apache.logging.log4j.Logger; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; +import java.util.HashSet; import java.util.Map; public class Main { @@ -49,9 +48,11 @@ public class Main { .buildAndStart(); logger.info("Server started on port 9401"); - String fanspeedUrl = "http:/%s/system/fanspeed?_=%d"; + String fanspeedUrl = "http://%s/system/fanspeed?_=%d"; String temperaturUrl = "http://%s/log/Temperatur.log?_=%d"; String tunerstatusUrl = "http://%s/octoserve/tunerstatus.json"; + String streamStatusUrl = "http://%s/octoserve/streamstatus.json"; + ObjectMapper objectMapper = new ObjectMapper(); Gauge fanspeed = Gauge.builder().name("octonetExporter_fanspeed").help("Fan speed").register(); Gauge temperature = Gauge.builder().name("octonetExporter_temperature").help("Temperature").register(); @@ -60,6 +61,8 @@ public class Main { Gauge snr = Gauge.builder().name("octonetExporter_snr").help("Signal to noise ratio").labelNames("input").register(); Gauge quality = Gauge.builder().name("octonetExporter_quality").help("Signal quality").labelNames("input").register(); Gauge level = Gauge.builder().name("octonetExporter_level").help("Signal level").labelNames("input").register(); + Gauge packets = Gauge.builder().name("octonetExporter_packets").help("Packets").labelNames("input").register(); + Gauge bytes = Gauge.builder().name("octonetExporter_bytes").help("Bytes").labelNames("input").register(); OkHttpClient client = new OkHttpClient.Builder().build(); int state = 1; @@ -108,9 +111,27 @@ public class Main { } if (!safeSleep()) break; + + request = new Request.Builder().url(String.format(streamStatusUrl,octonetIp)).build(); + call = client.newCall(request); + execute = call.execute(); + string = execute.body().string(); + StreamStatusResponse streamStatusResponse = objectMapper.readValue(string, StreamStatusResponse.class); + HashSet inputNames = new HashSet<>(); + for (StreamStatus streamStatus : streamStatusResponse.streamList) + { + if (inputNames.add(Integer.toString(streamStatus.input))) + { + packets.labelValues(Integer.toString(streamStatus.input)).set(streamStatus.packets); + bytes.labelValues(Integer.toString(streamStatus.input)).set(streamStatus.bytes); + } + } + if (!safeSleep()) + break; + if (state == 2) { - logger.info("Scraping loop successfully started."); + logger.info("Scraping loop successfully finished once."); state++; } } diff --git a/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatus.java b/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatus.java new file mode 100644 index 0000000..ca2f893 --- /dev/null +++ b/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatus.java @@ -0,0 +1,20 @@ +package moe.yo3explorer.octonet_exporter.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class StreamStatus { + @JsonProperty("Status") + public String status; + + @JsonProperty("Input") + public int input; + + @JsonProperty("Packets") + public long packets; + + @JsonProperty("Bytes") + public long bytes; + + @JsonProperty("Client") + public String client; +} diff --git a/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatusResponse.java b/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatusResponse.java new file mode 100644 index 0000000..10530a1 --- /dev/null +++ b/src/main/java/moe/yo3explorer/octonet_exporter/entities/StreamStatusResponse.java @@ -0,0 +1,13 @@ +package moe.yo3explorer.octonet_exporter.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class StreamStatusResponse { + @JsonProperty("TimeStamp") + public long timeStamp; + + @JsonProperty("StreamList") + public List streamList; +}