4 Commits

6 changed files with 131 additions and 20 deletions
Split View
  1. +24
    -1
      Cargo.toml
  2. +21
    -0
      LICENSE.txt
  3. +58
    -0
      README.md
  4. +20
    -0
      debian/config.toml
  5. +8
    -0
      debian/systemd/mqtt2statsd.service
  6. +0
    -19
      readme.md

+ 24
- 1
Cargo.toml View File

@ -1,9 +1,32 @@
[package]
name = "mqtt2statsd"
description = "MQTT to StatsD bridge"
authors = [ "n0m1s <git@homnomnom.fr>" ]
license = "MIT"
readme = "README.md"
homepage = "https://git.homnomnom.fr/nomis/mqtt2statsd"
repository = "https://git.homnomnom.fr/nomis/mqtt2statsd"
version = "0.1.0"
description = "MQTT to Statsd bridge"
edition = "2021"
[package.metadata.deb]
license-file = [ "LICENSE.txt", "2" ]
depends = "$auto"
section = "utility"
revision = ""
extended-description = """\
A service that translates numeric MQTT messages into StatsD gauge metrics."""
maintainer-scripts = "debian/systemd"
systemd-units = { enable = false }
assets = [
[ "target/release/mqtt2statsd", "/usr/bin/", "755" ],
[ "README.md", "usr/share/doc/mqtt2statsd/README", "644"],
[ "debian/config.toml", "etc/mqtt2statsd/config.toml", "644"]
]
conf-files = [
"etc/mqtt2statsd/config.toml"
]
[dependencies]
clap = { version = "4.3", features = [ "derive", "cargo" ]}
paho-mqtt = "0.12"


+ 21
- 0
LICENSE.txt View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 n0m1s
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

+ 58
- 0
README.md View File

@ -0,0 +1,58 @@
# mqtt2statsd
mqtt2statsd is a service that translates numeric MQTT messages into statsd gauge metrics.
## Installing and running
Currently, only supported on debian-based distributions.
For other distributions, see the "Building" section below.
Download the provided `.deb` file, and install it using `apt`:
```bash
$ sudo apt install ./mqtt2statsd_0.1.0_amd64.deb
```
Configure the MQTT and StasD server, as well as the topics to subscribe to in the
configuration file `/etc/mqtt2statsd/config.toml`.
Once configured, enable and start the systemd service:
```bash
$ sudo systemctl enable mqtt2statsd.service
$ sudo systemctl start mqtt2statsd.service
```
## Configuration
mqtt2statsd is configured via a toml configuration file.
Check [example.toml](./example.toml) for an example configuration.
## Building
To build the package, you need the following dependencies (shown here for Ubuntu, actual package names may vary slightly)
```bash
$ sudo apt install \
libssl-dev \
pkg-config \
cmake \
gcc
```
Then, install the latest version of rust with `rustup` ([documentation here](https://rustup.rs/)).
If building the debian package, install `cargo-deb` with:
```bash
$ cargo install cargo-deb
```
Clone the repository, and build the package:
```bash
$ git clone https://git.homnomnom.fr/nomis/mqtt2statsd.git
$ cd mqtt2statsd
$ cargo build --release
$ cargo deb # optional, if building deb package
```
You can now run the mqtt2statsd:
```bash
$ ./target/release/mqtt2statsd ./example.toml
```

+ 20
- 0
debian/config.toml View File

@ -0,0 +1,20 @@
# How to subscribe to the MQTT server
[mqtt]
hostname = "localhost"
#port = 1883 # optional, default: 1883
#timeout = 60 # in seconds, optional, default: 60
# Which Statsd server to send data to
[statsd]
hostname = "localhost"
#port = 8125 # optional, default: 8125
#prefix = "mqtt.stats" # optional, default: "mqtt.stats"
# List of topics to subscribe to, and corresponding stat
#[[topics]]
#mqtt = "$SYS/broker/messages/publish/sent"
#statsd = "publish_message_sent"
#
#[[topics]]
#mqtt = "$SYS/broker/clients/connected"
#statsd = "connected_clients"

+ 8
- 0
debian/systemd/mqtt2statsd.service View File

@ -0,0 +1,8 @@
[Unit]
Description=MQTT to StatsD bridge
[Service]
ExecStart=/usr/bin/mqtt2statsd /etc/mqtt2statsd/config.toml
[Install]
WantedBy=multi-user.target

+ 0
- 19
readme.md View File

@ -1,19 +0,0 @@
# mqtt2statsd
mqtt2statsd is a service that translates numeric MQTT messages into statsd gauge metrics.
## Dependencies
Ubuntu:
```
$ sudo apt install \
libssl-dev \
pkg-config \
cmake \
gcc
```
## Configuration
mqtt2statsd is configured via a toml configuration file.
Check [example.toml](./example.toml) for an example configuration.

Loading…
Cancel
Save