https://github.com/nir0s/shtatsd
A bash client for emitting statsd-formatted metrics
https://github.com/nir0s/shtatsd
Last synced: 2 months ago
JSON representation
A bash client for emitting statsd-formatted metrics
- Host: GitHub
- URL: https://github.com/nir0s/shtatsd
- Owner: nir0s
- Created: 2019-03-09T10:03:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-09T21:10:40.000Z (about 6 years ago)
- Last Synced: 2025-01-18T16:20:40.173Z (4 months ago)
- Language: Shell
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
shtatsd
=======[](https://circleci.com/gh/strigo/shtatsd)
shtatsd is a statsd client for bash. It is the reasonable alternative to: `echo -n "my_metric:60|g" >/dev/udp/localhost/8125`
Note that the following documentation relates to the code currently in the master branch. If you want to view docs for previous versions, please choose the relevant release in the "releases" tab.
All basic metric types are supported. You can also emit labels (for Prometheus, dogstatsd, etc..) by adding them to the metric.
## Installation
```bash
Install locally:[[ ! -f "statsd" ]] && \
curl -LO https://github.com/strigo/shtatsd/raw/master/statsd && \
chmod +x statsdor directly to your path (Yes, we sudo):
[[ ! -f "/usr/bin/statsd" ]] && \
sudo curl -L https://github.com/strigo/shtatsd/raw/master/statsd -o /usr/bin/statsd && \
sudo chmod +x /usr/bin/statsd
```## Usage
```shell
. statsdstatsd.increment "my_counter"
statsd.increment "my_counter" 2
statsd.increment "my_counter" 5 0.1statsd.decrement "my_counter"
statsd.decrement "my_counter" 2
statsd.decrement "my_counter" 5 0.1statsd.gauge "my_gauge" 113
statsd.gauge "my_gauge" 113 0.3statsd.timing "my_timer" 314
statsd.timing "my_timer" 314 0.5statsd.histogram "my_histogram" 5
statsd.set "my_set" 1092
```Don't, forget, bash, expansion, everywhere. Spaces are evil.
### Calculating time in milliseconds
The `statsd.timing` function expects time in milliseconds. `shtatsd` provides a helper for this, and you can use it like so:
```
. ./statsdfunction example_function() {
statsd.increment 'function_call_count,key=value'
local -r start_time=$(statsd.helper.now)sleep 3
local -r end_time=$(statsd.helper.now)
statsd.timing 'function_duration_ms,key=value' $(($end_time-$start_time))
}example_function "$@"
```## Env var based config
You can use environment variables to set the STATSD_HOST and STATSD_PORT to emit to (defaulting to 127.0.0.1 and 8125 respectively).
## Tests
To run tests locally:
```shell
$ npm install bats
...
$ git submodule init
$ git submodule update --remote
$ node_modules/bats/bin/bats test/*.bats
```