jvde-github / AIS-catcher

AIS receiver for RTL SDR dongles, Airspy R2, Airspy Mini, Airspy HF+, HackRF, SDRplay and SoapySDR

Home Page:https://aiscatcher.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request - Current counts of vessels, SAR, Base stations etc. published for Prometheus consumption

AlNotSteve opened this issue · comments

This is merely a feature request to make counts of sender type available to Prometheus.

This info is available in the UI and would be useful to consume via Prometheus into Grafana.

Screenshot from 2023-12-29 18-27-42

This classification is calculated in the UI, but I am planning (in due course) to move part of this calculation to the server side (see classification below). The picture you show is further aggregated and makes a distinction between moving and not moving (speed < .5 kts). We can push the below class to Prometheus if useful?

		const ShippingClass = {
			OTHER: 0,
			UNKNOWN: 1,
			CARGO: 2,
			B: 3,
			PASSENGER: 4,
			SPECIAL: 5,
			TANKER: 6,
			HIGHSPEED: 7,
			FISHING: 8,
			PLANE: 9,
			HELICOPTER: 10,
			STATION: 11,
			ATON: 12,
			SARTEPIRB: 13,
		};

I have added something, but cannot fully test it. The metrics output now includes moving and stationary ships:

# HELP ais_stat_ship_moving Total number of ships moving
# TYPE ais_stat_ship_moving counter
ais_stat_ship_moving 0
# HELP ais_stat_ship_stationary Total number of ships stationary
# TYPE ais_stat_ship_stationary counter
ais_stat_ship_stationary 2

and a counter per ship class:

# HELP ais_stat_count_shipclass_0 Total number of messages of shipclass 0
# TYPE ais_stat_count_shipclass_0 counter
ais_stat_count_shipclass_0 0
# HELP ais_stat_count_shipclass_1 Total number of messages of shipclass 1
# TYPE ais_stat_count_shipclass_1 counter
ais_stat_count_shipclass_1 2

Etc.

This uses the following classification:

	CLASS_OTHER = 0,
	CLASS_UNKNOWN = 1,
	CLASS_CARGO = 2,
	CLASS_B = 3,
	CLASS_PASSENGER = 4,
	CLASS_SPECIAL = 5,
	CLASS_TANKER = 6,
	CLASS_HIGHSPEED = 7,
	CLASS_FISHING = 8,
	CLASS_PLANE = 9,
	CLASS_HELICOPTER = 10,
	CLASS_STATION = 11,
	CLASS_ATON = 12,
	CLASS_SARTEPIRB = 13

Please have a look and see if this works. It contains all the information you were looking for.

Just installed and ran a quick test. Doesn't appear to be doing what's intended.

I've attached 2 screenshots - one is the output from /metrics and the other from the UI. Totals don't line up.

Screenshot 2024-01-01 at 9 57 48 am Screenshot 2024-01-01 at 9 57 34 am

Took a few samples in this screenshot. Looks like it's continuously adding up.

Screenshot 2024-01-01 at 11 30 56 am

It should be monotonically increasing as it is a counter, but your right it there is a subtle difference with the table and you cannot approximately reproduce the table from this.

Let me try to be more clear on what the output is.

What is on the screen is the number of vessels (which is essentially all MMSIs that have been sending in the last 30 minutes). Prometheus input (/metrics) counts the number of messages of a particular ship class type we have heard at the last pull (over the lifetime).

If there is just one vessel, a "passenger ship", broadcasting every minute. Then the UI table would show 1 as it is the vessel count at that point in time on screen. The counter and Grafana will show that we receive 1 msg per minute from the class "passenger ship".

Maybe we need to pivot.

I think you can calculate in PROMQL the number of MMSIs picked up in the last 2 minutes with (note the UI shows for 30m by default):

count(sum(count_over_time(ais_msg_ppm[2m])) by (mmsi))

I have just added speed and shipclass to the ais_msg_ppm gauge, this should allow us to show the number of ships we heard from in the last 2 minutes per shipclass:

count(sum(count_over_time(ais_msg_ppm[2m])) by (mmsi,shipclass)) by (shipclass)

or per speed:

count(sum(count_over_time(ais_msg_ppm[2m])) by (mmsi,speed)) by (speed)

and combined:

count(sum(count_over_time(ais_msg_ppm[2m])) by (mmsi,speed,shipclass)) by (speed,shipclass)

Does this help?

Btw, this is not 100% aligned either as the shipclass and speed can change over time when we pick up more information on the vessel. Not sure how to best solve this without too much work.

Hi Jasper,

Thanks for the advice and info.

I've had a fiddle in Grafana and came up with figures closely matching the UI.

Screenshot 2024-01-01 at 9 45 58 pm

I removed the other code with the counters (saves some cpu cycles). The small double count in case a shipclass or speed label changes still annoys me but has to wait until another time.