πΉ @metrics Operator in TuskLang - Go Guide
@metrics Operator in TuskLang - Go Guide
π Metrics Mastery: @metrics Operator Unleashed
TuskLang's @metrics
operator is your observability superpower. We don't bow to any kingβespecially not to blind spots in production. Here's how to use @metrics
in Go projects to collect, monitor, and alert on your system's performance.
π Table of Contents
- What is @metrics? - Basic Usage - Metric Types - Prometheus Integration - Go Integration - Best Practicesπ What is @metrics?
The @metrics
operator collects and exposes metrics directly from your config. No more scattered monitoringβjust pure, centralized observability.
π οΈ Basic Usage
[monitoring]
startup_time: @metrics("startup_time_ms", 123)
user_count: @metrics("user_count", @query("SELECT COUNT(*) FROM users"))
response_time: @metrics("api_response_time_ms", 45)
π Metric Types
Counters
[counters]
requests_total: @metrics("requests_total", 1000)
errors_total: @metrics("errors_total", 5)
Gauges
[gauges]
active_connections: @metrics("active_connections", 42)
memory_usage: @metrics("memory_usage_bytes", 1073741824)
Histograms
[histograms]
request_duration: @metrics("request_duration_seconds", 0.123)
π Prometheus Integration
// Go - Prometheus metrics
import "github.com/prometheus/client_golang/prometheus"var (
requestsTotal = prometheus.NewCounter(prometheus.CounterOpts{
Name: "requests_total",
Help: "Total number of requests",
})
activeConnections = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "active_connections",
Help: "Number of active connections",
})
)
func init() {
prometheus.MustRegister(requestsTotal)
prometheus.MustRegister(activeConnections)
}
π Go Integration
// Record metrics from config
startupTime := config.GetInt("startup_time")
userCount := config.GetInt("user_count")// Update Prometheus metrics
activeConnections.Set(float64(userCount))
π₯ Best Practices
- Use descriptive metric names - Include units in metric names - Set up alerts for critical metrics - Monitor all key performance indicators---
TuskLang: See everything with @metrics.