diff --git a/Cargo.toml b/Cargo.toml index 8d72c19..654db7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "mqtt2statsd" description = "MQTT to StatsD bridge" +authors = [ "n0m1s " ] license = "MIT" readme = "README.md" homepage = "https://git.homnomnom.fr/nomis/mqtt2statsd" @@ -8,6 +9,24 @@ repository = "https://git.homnomnom.fr/nomis/mqtt2statsd" version = "0.1.0" 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" diff --git a/README.md b/README.md index 531b4dc..be4e63e 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,34 @@ mqtt2statsd is a service that translates numeric MQTT messages into statsd gauge metrics. -## Dependencies +## Installing and running -Ubuntu: +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 \ @@ -13,7 +37,22 @@ cmake \ gcc ``` -## Configuration +Then, install the latest version of rust with `rustup` ([documentation here](https://rustup.rs/)). -mqtt2statsd is configured via a toml configuration file. -Check [example.toml](./example.toml) for an example configuration. +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 +``` diff --git a/debian/config.toml b/debian/config.toml new file mode 100644 index 0000000..bb72f87 --- /dev/null +++ b/debian/config.toml @@ -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" diff --git a/debian/systemd/mqtt2statsd.service b/debian/systemd/mqtt2statsd.service new file mode 100644 index 0000000..23a443a --- /dev/null +++ b/debian/systemd/mqtt2statsd.service @@ -0,0 +1,8 @@ +[Unit] +Description=MQTT to StatsD bridge + +[Service] +ExecStart=/usr/bin/mqtt2statsd /etc/mqtt2statsd/config.toml + +[Install] +WantedBy=multi-user.target