Junior — Middle
Where are system metrics and indicators collected?
sobes.tech AI
Answer from AI
System metrics and indicators are usually collected from the following places:
-
Inside the application — using built-in monitoring libraries (e.g., Prometheus client for Go). Here, performance metrics, request counts, errors, etc., are collected.
-
At the infrastructure level — metrics from servers, containers, network equipment (CPU, memory, network).
-
In logging and tracing systems — for behavior and error analysis.
-
In specialized monitoring services — which aggregate and visualize data (Grafana, Datadog).
Example in Go using Prometheus:
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)
var requests = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "Number of HTTP requests",
},
)
func init() {
prometheus.MustRegister(requests)
}
func handler(w http.ResponseWriter, r *http.Request) {
requests.Inc()
w.Write([]byte("Hello, metrics!"))
}
func main() {
http.HandleFunc("/", handler)
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8080", nil)
}