Query StreamStatus from the OctopusNET.

This commit is contained in:
fey 2026-09-16 19:16:00 +02:00
parent f489e4bad1
commit 76824b9789
5 changed files with 81 additions and 6 deletions

View File

@ -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.

View File

@ -6,7 +6,7 @@
<groupId>moe.yo3explorer</groupId>
<artifactId>octonet-exporter</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.1</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>

View File

@ -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<String> 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++;
}
}

View File

@ -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;
}

View File

@ -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<StreamStatus> streamList;
}