Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ngerakines/countdown-metrics-rs
A daemon that publishes the number of seconds until a given date to a statsd sink.
https://github.com/ngerakines/countdown-metrics-rs
kubernetes metrics statsd
Last synced: 2 months ago
JSON representation
A daemon that publishes the number of seconds until a given date to a statsd sink.
- Host: GitHub
- URL: https://github.com/ngerakines/countdown-metrics-rs
- Owner: ngerakines
- License: mit
- Created: 2023-04-19T18:06:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-29T08:52:58.000Z (6 months ago)
- Last Synced: 2024-10-31T11:58:14.619Z (2 months ago)
- Topics: kubernetes, metrics, statsd
- Language: Rust
- Homepage: https://crates.io/crates/countdown-metrics-rs
- Size: 123 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Countdown Metrics
A daemon that publishes the number of seconds until a given date to a statsd sink.
# Configuration
The daemon is configured via environment variables:
* `ENV_PREFIX`: The prefix for environment variables. Defaults to `COUNTDOWNS_`.
* `INTERVAL`: The number of seconds between publishing metrics. Defaults to `10`.
* `STATSD_HOST`: The host to publish metrics to. Defaults to `127.0.0.1:8125`.
* `METRIC_PREFIX`: The prefix to use for metrics. Blank by default.
* `METRIC_TAGS`: A comma separated list of tags to add to all metrics. Blank by default.
* `COUNTDOWN_KEY`: The name of the countdown metric. Defaults to `countdown`.
* `COUNTDOWN_ID`: The name of the countdown metric tag. Defaults to `name`.
* `HEARTBEAT_METRIC`: The name of the heartbeat metric. Defaults to `heartbeat`.The metrics to watch are read as environment variables that start with the value of the `ENV_PREFIX` environment variable. The value of the environment variable should be a date in the format `YYYY-MM-DDTHH:MM:SSZ`. The prefix is stripped and the remaining text is used as the name of the metric.
For example, consider the following environment variables:
```
ENV_PREFIX=SURGE
METRIC_PREFIX=wildmagic_rocks
SURGE_FOO="2024-01-01T14:00:00-04:00"
WATCH_THIS_BAR="2024-01-01T14:00:00-04:00"
```The above environment variable would result in a metric named `wildmagic_rocks.foo` with a value of the number of seconds until the date `2024-01-01T14:00:00-04:00` and a tag named `name` with a value of `foo` published every 10 seconds. The `WATCH_THIS_BAR` environment variable would be ignored because it is not one of the configuration environment variables nor does it have the prefix `SURGE` as defined by the `ENV_PREFIX` environment variable.
# Example
First start a fake statsd sink:
$ nc -u -l -p 8125
Then run the daemon with an example metric:
$ COUNTDOWNS_FOO="2024-01-01T14:00:00-04:00" cargo run
You'll see metrics published with the default values:
```
countdown:22192887|g|#name:foo
heatbeat:1681939112|g
countdown:22192877|g|#name:foo
heatbeat:1681939122|g
countdown:22192867|g|#name:foo
heatbeat:1681939132|g
```## Global Tags
When running:
$ METRIC_TAGS="DD_SERVICE=cntdwn,DD_VERSION=1.2.0" COUNTDOWNS_FOO="2024-01-01T14:00:00-04:00" cargo run
You'll get:
```
countdown:22132947|g|#DD_SERVICE:cntdwn,DD_VERSION:1.2.0,name:foo
heatbeat:1681999052|g|#DD_SERVICE:cntdwn,DD_VERSION:1.2.0
```# Usage
Use this to monitor your stuff.
Deploy it with something like this:
```yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cntdwn
labels:
app: cntdwn
spec:
revisionHistoryLimit: 1
selector:
matchLabels:
app: cntdwn
template:
metadata:
labels:
app: cntdwn
spec:
containers:
- name: app
image: ngerakines/countdown-metrics:v1.2.0
env:
- name: COUNTDOWNS_SITE_CERT
value: "2024-01-01T14:00:00-04:00"
- name: COUNTDOWNS_TS_KEY_DC1
value: "2024-02-01T14:00:00-04:00"
```Then create a monitor in your observability stack that alerts when the value of the metric is less than 345600 (4 days) or 950400 (11 days).