Collect MQTT messages
Publish two sensor readings, collect them with the agent, and query their values.
Collect MQTT messages
This walkthrough sends two temperature readings through a local MQTT broker into Logship. You will verify the original messages and render a chart.
Before you begin
Use a Linux host with Docker and an approved, running Logship agent. If you have not connected an agent yet, complete Monitor your first machine using the Linux option, including approval and the incoming-data check. The commands below use that guide's service name and /opt/logship-agent/appsettings.json configuration path. Keep its existing Output settings and data directory.
Run the broker on the same host as the native agent. This example binds only to localhost and needs no MQTT credentials. It is a local test, not a broker configuration for other machines.
1. Start a test broker
Create a dedicated configuration directory and start Mosquitto:
mkdir -p "$HOME/logship-mqtt-demo"
printf 'listener 1883\nallow_anonymous true\n' > "$HOME/logship-mqtt-demo/mosquitto.conf"
docker run -d --name logship-mqtt-demo \
-p 127.0.0.1:1883:1883 \
-v "$HOME/logship-mqtt-demo/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro" \
eclipse-mosquitto:2
docker logs logship-mqtt-demoThe logs should show a listener on port 1883. If the port is already occupied, stop here and use a free port consistently in both the Docker mapping and the agent's brokerPort below. Do not stop another broker just to run this example.
2. Subscribe with the agent
Edit /opt/logship-agent/appsettings.json. Add this MQTT entry inside the existing Sources object; preserve the other sources and all Output settings. Remember the comma between JSON entries.
"MQTT": {
"enabled": true,
"brokerAddress": "127.0.0.1",
"brokerPort": 1883,
"clientId": "logship-mqtt-demo",
"topic": "logship_demo",
"useTls": false,
"combined": false
}This subscribes to one topic and writes its messages to the per-topic table MQTT.logship_demo. The payload stays a string; Logship does not automatically turn JSON payload fields into columns.
sudo systemctl restart logship-agent
sudo journalctl -u logship-agent -n 50 --no-pagerCheck for broker connection or subscription errors before publishing. If the agent runs in a container, localhost points to that container; this walkthrough assumes the native agent described above.
3. Publish two readings
Run these commands after the agent connects. Retained messages let the agent receive the latest reading if it reconnects.
docker exec logship-mqtt-demo mosquitto_pub -h localhost -t logship_demo -m '21.5' -q 1 -r
sleep 5
docker exec logship-mqtt-demo mosquitto_pub -h localhost -t logship_demo -m '24.0' -q 1 -r4. Verify the records
In Logship, select the account configured in the agent's Output, open Query, paste this query, and choose Execute:
MQTT.logship_demo
| where timestamp > ago(15m)
| project timestamp, topic, payload
| order by timestamp ascAllow up to a minute for the table to become queryable. Look for topic logship_demo and payloads 21.5 and 24.0. MQTT can redeliver messages, and repeating the commands adds records, so the total may exceed two. If only 24.0 appears, the agent subscribed after the first publish: rerun both commands while it is connected.
If there are no records, check the selected account, agent approval, broker address, and agent logs. A missing table usually means no message has arrived yet. The topic spelling determines the table name.
5. Chart the readings
MQTT.logship_demo
| where timestamp > ago(15m)
| project timestamp, temperature = todouble(payload)
| order by timestamp asc
| render timechartChoose Execute, then Render. The chart should contain temperatures 21.5 and 24.0. In an account where you can save dashboards, open Dashboards → Create Dashboard, name it Sensor readings, choose Add Chart, and select Kusto. Paste this query, save the chart, then save the dashboard.
The query shows only the last 15 minutes. Publish another numeric reading to see it appear on the next execution. For a real device, configure the broker's authentication and TLS, then adjust the agent's topic and credentials using the MQTT configuration reference.
Optional cleanup
Remove the MQTT entry you added to the agent configuration and restart logship-agent. Then stop and remove this test broker:
docker stop logship-mqtt-demo
docker rm logship-mqtt-demoThe ingested records remain in Logship. Your configuration file remains in $HOME/logship-mqtt-demo for reuse.
Broker image reference: Eclipse Mosquitto official image.