🐹 @metrics Operator in TuskLang - Go Guide

Go Documentation

@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.