Logs and metrics
Metrics
Set or change a number from your code, such as signups, orders or queue length, and watch it on a chart per minute, hour or day.
A metric is a named number, such as users, orders or queue_length. Your code sets it or changes it, and Logdash keeps its history and draws it on a chart. There is nothing to create first: a metric appears with its first value.
Send metrics
import { Logdash } from '@logdash/node';
const logdash = new Logdash(process.env.LOGDASH_API_KEY);
// to set absolute value
logdash.setMetric('users', 0);
// to modify existing metric
logdash.mutateMetric('users', 1); import os
from logdash import create_logdash
logdash = create_logdash({"api_key": os.environ["LOGDASH_API_KEY"]})
metrics = logdash.metrics
# to set absolute value
metrics.set("users", 0)
# to modify existing metric
metrics.mutate("users", 1) package main
import (
"context"
"os"
"time"
"github.com/logdash-io/go-sdk/logdash"
)
func main() {
ld := logdash.New(logdash.WithAPIKey(os.Getenv("LOGDASH_API_KEY")))
metrics := ld.Metrics
// to set absolute value
metrics.Set("users", 0)
// or increment / decrement by
metrics.Mutate("users", 1)
// Shutdown waits for every enqueued log, metric and event to flush.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ld.Shutdown(ctx)
} // to set absolute value
metrics.Set("key", 2);
// or increment / decrement by
metrics.Mutate("key", 3); // Gauges - track current values
metrics.set("active_users", 1_250);
// Counters - track events and occurrences
metrics.mutate("api_requests", 1); let (_, metrics) = logdash::create_logdash(logdash::Config::default());
// create a metric
metrics.set("users".into(), 0.0);
// or increment / decrement by
metrics.mutate("users".into(), 1.0); metrics.set('users', 0)
metrics.mutate('users', 1) $metrics->set('active_users', 150);
$metrics->mutate('login_count', 1); // Increment by 1
$metrics->mutate('error_count', -1); // Decrement by 1 curl -X PUT https://api.logdash.io/metrics \
-H "project-api-key: $LOGDASH_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "users", "value": 1, "operation": "change"}' Set or change
| Operation | What it does | Use it for |
|---|---|---|
set | Replaces the value. | Numbers you can read, such as queue length, memory use or active users. |
change | Adds to the value. Send a negative number to subtract. | Things you count as they happen, such as signups or failed payments. |
The SDKs name these operations differently, such as setMetric and mutateMetric in Node.js, or metrics.set and metrics.mutate in Python. Over HTTP, send them in operation.
Apps
Metrics belong to an app. Two apps can each have a metric called users, and they stay apart. Name the app with the app option of the SDK or the app field over HTTP. See Apps.
Read a metric
Open your domain and go to Metrics. Click a metric to see its chart, with its current value under Now. New values show up as they arrive.
- Pick the range of the chart: 1h, 24h or 7d on every plan, and 12h or 30d on paid plans.
- Short ranges show a point per minute, 24h a point per hour and 7d and 30d a point per day. Your plan sets how long each of them is kept, so a range can show less than its full length.
- Focus the chart and use the arrow keys to read each point.
- Delete metric deletes the metric and its history, and frees its place for a new metric.
Limits
- Names can be up to 255 characters, and values have to be numbers.
- Each app can have a fixed number of metrics. A value for a new metric past that answers
409with "You have reached the maximum number of metrics for this service", and values of existing metrics keep working.
| Limit | Hobby | Builder | Pro |
|---|---|---|---|
| Metrics per app | 5 | 10 | 30 |
| Per-minute points kept | 1 hour | 6 hours | 1 day |
| Hourly points kept | 1 day | 3 days | 7 days |
| Daily points kept | - | 7 days | 30 days |
For the full request and the read API, see HTTP API.