# AI ऊर्जा observability कैसे बनाएँ

> OpenTelemetry, Prometheus और Kepler से हर AI अनुरोध और एजेंट चरण के लिए टोकन, latency, ऊर्जा और ग्रिड कार्बन दर्ज करें, और ऊर्जा बजट तय करें।

Source: https://greenai.guide/hi/इंजीनियरिंग/ai-ऊर्जा-observability-कैसे-बनाएँ/  
Updated: 2026-11-26

## संक्षेप में

AI ऊर्जा observability का मतलब है हर मॉडल कॉल और एजेंट चरण के लिए यह दर्ज करना कि उसने क्या किया (मॉडल, टोकन, cache hits, retries, टूल कॉल), उसमें कितना समय लगा, और उसने कितनी ऊर्जा इस्तेमाल की, जहाँ आप हार्डवेयर चलाते हैं वहाँ मापी हुई और जहाँ नहीं चलाते वहाँ अनुमानित। पावर node पर मापें, उसे busy time या टोकनों के हिसाब से सेवाओं और अनुरोधों में बाँटें, हर आँकड़े को measured, attributed या estimated के रूप में टैग करें, और query के समय उसे ग्रिड की कार्बन तीव्रता से जोड़ें। फिर प्रति सफल काम ऊर्जा को latency के लक्ष्य की तरह संभालें।

## मुख्य बातें

- हर मॉडल कॉल के लिए मॉडल, अंदर और बाहर जाने वाले टोकन, cached टोकन, latency, retries, टूल कॉल, नतीजा, हार्डवेयर pool और क्षेत्र दर्ज करें; डिफ़ॉल्ट रूप से prompt का टेक्स्ट कभी नहीं।
- OpenTelemetry GenAI semantic conventions अपनी अलग repository में चली गईं और नवंबर 2026 में v0.1.0 जारी हुआ; ये अभी Development स्थिति में हैं और कोई ऊर्जा metric परिभाषित नहीं करतीं।
- Kepler, एक CNCF Sandbox परियोजना, मापी गई सक्रिय पावर को CPU समय के अनुपात में बाँटकर node, pod और container की ऊर्जा Prometheus को export करता है; इसका NVIDIA GPU समर्थन प्रयोगात्मक है।
- ऊर्जा को joules के counter के रूप में export करें; तब Prometheus का rate() watts देता है।
- प्रति सफल काम ऊर्जा ट्रैक करें, साथ में कुल भी, और इसके बढ़ने पर वैसे ही alert दें जैसे latency के लिए देते।

## AI ऊर्जा observability क्या है? {#what-is-ai-energy-observability}

**यह हर AI अनुरोध और एजेंट चरण के लिए latency, errors और लागत के बगल में ऊर्जा दर्ज करने का तरीका है, ताकि आप देख सकें कि कौन-सा फ़ीचर,
मॉडल या workflow ऊर्जा इस्तेमाल करता है और किसी बदलाव से मदद मिली या नहीं।** यह आपकी पहले से चल रही tracing और metrics को बढ़ाता है,
उनकी जगह नहीं लेता।

दो विचार इसे काम करवाते हैं। **टोकन और कॉल आगे का संकेतक (leading indicator) हैं**: सस्ते, सटीक और हर कॉल के लिए उपलब्ध, होस्ट किए गए
API समेत। और **हर ऊर्जा आँकड़े के साथ तरीके का लेबल होता है**: *measured* (आपके नियंत्रण वाले हार्डवेयर पर meter), *attributed* (मापा गया
node का कुल, अनुरोधों में बाँटा गया) या *estimated* (टोकनों से बना मॉडल, जैसे होस्ट किए गए API के लिए)। सीमाएँ और अनिश्चितता
[AI ऊर्जा कैसे मापें](/hi/अच्छी-प्रथाएँ/ai-की-ऊर्जा-और-कार्बन-कैसे-मापें/) में हैं; यह गाइड ऊर्जा को production telemetry में जोड़ने के बारे में है।

## हर अनुरोध या एजेंट चरण के लिए मुझे क्या दर्ज करना चाहिए? {#what-should-i-record-for-each-request-or-agent-step}

**दर्ज करें कि कॉल ने क्या किया, कितना समय लिया, किस पर और कहाँ चली, और कैसे ख़त्म हुई, कम cardinality वाले metrics और प्रति कॉल एक trace
span के रूप में।** सामग्री छोड़ दें।

| फ़ील्ड | उदाहरण attribute | ऊर्जा के लिए यह क्यों मायने रखता है |
|---|---|---|
| Operation और प्रदाता | `gen_ai.operation.name`, `gen_ai.provider.name` | चैट, embeddings, टूल रन और retrieval को अलग करता है |
| माँगा गया और serve किया गया मॉडल | `gen_ai.request.model`, `gen_ai.response.model` | मॉडल का आकार सबसे बड़ा अकेला कारक है; routers इसे हर कॉल पर बदलते हैं |
| अंदर और बाहर जाने वाले टोकन | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` | ऊर्जा प्रोसेस और generate किए गए टोकनों के साथ बढ़ती है |
| Cached और reasoning टोकन | `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.reasoning.output_tokens` | Cache reads काम से बचाते हैं; छिपी reasoning काम जोड़ती है |
| आउटपुट सीमा | `gen_ai.request.max_tokens` | दिखाता है कि सीमाएँ तय भी हैं या नहीं |
| Latency | `gen_ai.client.inference.duration`, पहले chunk तक का समय | Busy time बाँटने की एक key है; धीमी कॉल हार्डवेयर को रोके रखती हैं |
| नतीजा | `error.type`; आपके काम का अपना नतीजा | विफल और दोबारा की गई कॉल ऊर्जा ख़र्च करती हैं और कुछ नहीं देतीं |
| Retries और response-cache hits | आपके अपने counters | Retries लागत कई गुना करते हैं; आपके अपने cache hits कॉल से पूरी तरह बचाते हैं |
| एजेंट और टूल चरण | `gen_ai.agent.name`, `gen_ai.tool.name`; प्रति एजेंट रन inference और टूल कॉल | एजेंट लूप बेक़ाबू टोकन इस्तेमाल का आम स्रोत हैं |
| हार्डवेयर pool और utilisation | आपका pool लेबल; node से GPU और CPU utilisation | प्रति टोकन ऊर्जा समझाता है; ख़ाली pools यहाँ दिखते हैं |
| ऊर्जा | joules में आपका अपना metric, measured, attributed या estimated तरीके के साथ | वही चीज़ जिसे आप संभालना चाहते हैं |
| क्षेत्र और समय | `cloud.region`, timestamp | ग्रिड कार्बन तीव्रता लागू करने के लिए ज़रूरी |

दूसरे कॉलम के नाम OpenTelemetry GenAI semantic conventions (नीचे देखें) से हैं, सिवाय जहाँ "आपका अपना" लिखा है। request IDs, user IDs और
conversation IDs सिर्फ़ spans पर रखें, metric labels के रूप में कभी नहीं।

## मैं node की पावर से एक अकेले अनुरोध तक कैसे पहुँचूँ? {#how-do-i-get-from-node-power-to-a-single-request}

**किसी node या डिवाइस की ऊर्जा एक छोटी window में मापें, फिर उसे उस window में हुए काम में किसी बताए गए नियम से बाँटें, और जाँचें कि हिस्से
जुड़कर मापे गए कुल के बराबर हों।** प्रति अनुरोध कोई power meter नहीं है।

आम तरीका, और वही जो Kepler CPUs के लिए इस्तेमाल करता है, हर window की ऊर्जा को दो हिस्सों में बाँटता है:

- **Idle ऊर्जा**: वह आधार रेखा जो node काम के बिना भी खींचता है।
- **सक्रिय ऊर्जा**: बाक़ी, जो वर्कलोड में उनके संसाधन इस्तेमाल के अनुपात में बाँटी जाती है। Kepler का नियम है: हर अंतराल के लिए, वर्कलोड
  पावर = (वर्कलोड CPU समय ÷ node CPU समय) × सक्रिय पावर।

मॉडल serving के लिए आप यही विचार अनुरोधों तक ले जा सकते हैं:

1. **हर डिवाइस, हर window** (मान लीजिए 15 से 60 सेकंड) के लिए RAPL, NVML ऊर्जा काउंटर या node-स्तर की रीडिंग से मापी गई ऊर्जा लें।
2. **Idle घटाएँ**, जो उसी node पर मॉडल लोड रहते और बिना ट्रैफ़िक के मापी गई हो।
3. **सक्रिय ऊर्जा को अनुरोधों में बाँटें**, किसी भार (weight) के अनुपात में: जहाँ आपका सर्वर बताए वहाँ GPU या CPU busy time, या टोकन भार।
   Fernandez और साथियों ने पाया कि prefill की तुलना में decoding प्रति टोकन ज़्यादा ऊर्जा-सघन है, इसलिए अगर आप टोकनों से भार देते हैं, तो
   आउटपुट टोकनों को ज़्यादा भार दें, जो अपने बेंचमार्क रन से fit किया गया हो (देखें
   [CPU बनाम GPU inference को बेंचमार्क कैसे करें](/hi/इंजीनियरिंग/ऊर्जा-के-लिए-cpu-बनाम-gpu-inference-को-बेंचमार्क-कैसे-करें/))।
4. **Idle ऊर्जा को हर pool के लिए अलग पंक्ति में रिपोर्ट करें**, या उसे अनुपात में बाँटें और यह बताएँ। इसे प्रति अनुरोध आँकड़ों में छिपाने से
   आधा ख़ाली GPU pool कुशल दिखता है।
5. **मिलान करें।** बाँटी गई ऊर्जा और idle का योग window के मापे गए कुल के बराबर होना चाहिए। जब न हो तो alert दें।

**सीमाएँ जानें।** Kepler की अपनी गाइड इन्हें गिनाती है: एक जैसे CPU समय वाली दो processes sleep states, frequency scaling, vector
instructions और memory-bound रुकावटों की वजह से अलग पावर खींच सकती हैं, और उसी window में स्थिर काम की तुलना में रुक-रुककर होने वाले काम को
कम ऊर्जा बाँटी जाती है। यह absolute बजट फ़ैसलों के बजाय रुझानों और सापेक्ष तुलनाओं के लिए इस तरीके की सलाह देती है। NVIDIA GPUs के लिए Kepler
का प्रयोगात्मक समर्थन सक्रिय डिवाइस पावर को streaming-multiprocessor utilisation के हिसाब से processes में बाँटता है, एक NVML पावर रीडिंग
इस्तेमाल करते हुए जिसकी औसत window GPU मॉडल पर निर्भर करती है।

होस्ट किए गए API की कॉल को आप बिल्कुल meter नहीं कर सकते; टोकनों से अनुमान लगाएँ और नतीजे को *estimated* लेबल करें। देखें
[AI API कॉल की ऊर्जा का अनुमान कैसे लगाएँ](/hi/कैसे/मैं-अपनी-ai-api-कॉल्स-की-ऊर्जा-का-अनुमान-कैसे-लगाऊँ/)।

<!-- figure: Attribution flow: measured node energy per window splits into idle energy (reported per pool) and active energy, which is divided between requests by busy time or token weight, with a reconciliation check that the parts sum to the measured total. -->

## OpenTelemetry GenAI conventions क्या कवर करती हैं? {#what-do-the-opentelemetry-genai-conventions-cover}

**ये मॉडल कॉल, एजेंटों, टूल और retrieval के लिए मानक span और metric नाम परिभाषित करती हैं, टोकन गिनती समेत, लेकिन ऊर्जा के लिए कुछ नहीं,
और ये अभी Development स्थिति में हैं।** जो कुछ ये कवर करती हैं उसके लिए इन्हें इस्तेमाल करें, और अपना namespaced ऊर्जा metric जोड़ें।

26 नवंबर 2026 को जाँची गई स्थिति:

- **नया घर, पहला release.** GenAI conventions मुख्य OpenTelemetry semantic conventions से निकलकर अपनी अलग repository में चली गईं और
  21 नवंबर 2026 को अपना पहला स्वतंत्र release, v0.1.0, प्रकाशित किया। opentelemetry.io के पुराने पेज अब कहते हैं कि सामग्री कहीं और चली
  गई है।
- **Development स्थिति।** conventions, और उनमें मौजूद GenAI attributes और metrics, Development के रूप में चिह्नित हैं, और v0.1.0 पिछले
  release से breaking बदलावों की सूची देता है। उदाहरण के लिए, इसने `gen_ai.client.token.usage` histogram की जगह अलग-अलग
  `gen_ai.client.inference.operation.input_tokens` और `...output_tokens` histograms रखे, और inference timing को
  `gen_ai.client.operation.duration` से `gen_ai.client.inference.duration` पर ले गया। जो संस्करण आप लागू करते हैं उसे pin करें और नाम
  बदलने की उम्मीद रखें।
- **Inference spans** का नाम `{gen_ai.operation.name} {gen_ai.request.model}` होता है (उदाहरण के लिए `chat small-model`) और इनमें मॉडल,
  प्रदाता और `gen_ai.usage.*` टोकन attributes होते हैं, cache reads और writes और reasoning टोकन समेत।
- **एजेंट और टूल spans.** एक in-process एजेंट रन INTERNAL प्रकार का `invoke_agent {gen_ai.agent.name}` span है; हर टूल रन एक
  `execute_tool {gen_ai.tool.name}` span है। metrics में `gen_ai.invoke_agent.inference_calls` और `gen_ai.invoke_agent.tool_calls` शामिल
  हैं, यानी प्रति एजेंट रन मॉडल और टूल कॉल की संख्या, जो लूप की अच्छी शुरुआती चेतावनी हैं।
- **सामग्री opt-in है।** Prompts, जवाब, system निर्देश और टूल definitions (`gen_ai.input.messages`, `gen_ai.output.messages` और दूसरे)
  Opt-In attributes हैं, और conventions चेतावनी देती हैं कि इनमें निजी डेटा समेत संवेदनशील जानकारी होने की संभावना है।
- **हार्डवेयर ऊर्जा कहीं और है।** OpenTelemetry की hardware conventions `hw.energy`, joules में एक counter, और `hw.power`, watts में एक
  gauge, परिभाषित करती हैं, ये भी Development स्थिति में, और जहाँ संभव हो `hw.power` के बजाय `hw.energy` रिपोर्ट करने की सलाह देती हैं।
  इन्हें उस node और डिवाइस telemetry के लिए इस्तेमाल करें जो आप ख़ुद इकट्ठा करते हैं।

## Prometheus, Grafana और Kepler कहाँ आते हैं? {#where-do-prometheus-grafana-and-kepler-fit}

**Prometheus time series स्टोर करता है, Grafana या ऐसा कोई टूल dashboards बनाता है, और Kepler, NVIDIA का DCGM exporter और आपका inference
सर्वर जैसे exporters पावर और serving metrics देते हैं।** OpenTelemetry से एप्लिकेशन metrics भी उसी store में जाते हैं।

- **watts नहीं, joules export करें।** Prometheus की naming गाइड ऊर्जा के लिए joules को आधार इकाई बताती है और joules का counter export करने
  की सलाह देती है, ताकि `rate(joules[5m])` watts में पावर दे। Counters scrape के अंतराल झेल लेते हैं; तात्कालिक watts के gauges नहीं।
- **नामों का ध्यान रखें।** OpenTelemetry के Prometheus compatibility नियमों के तहत इकाई `J` वाले counter में `_joules` suffix और `_total`
  suffix जुड़ता है, इसलिए `example.inference.energy` `example_inference_energy_joules_total` के रूप में दिखता है।
- **Cardinality का ध्यान रखें।** Prometheus चेतावनी देता है कि हर label मेल एक नई time series है और labels में user IDs या email पतों जैसे
  असीमित मान नहीं होने चाहिए।
- **Kubernetes के लिए Kepler.** Kepler एक CNCF Sandbox परियोजना है जो node, pod, container, process और virtual-machine स्तर पर ऊर्जा
  Prometheus को export करती है। इसके 0.10 rewrite के बाद से metrics में `kepler_node_cpu_joules_total`, `kepler_pod_cpu_joules_total` और
  `kepler_pod_gpu_joules_total` शामिल हैं। CPU metrics में एक `zone` लेबल होता है (`package`, `core`, `uncore`, `dram`, `psys`); zones
  एक-दूसरे पर चढ़े हैं, इसलिए एक पर filter करें। DRAM सिर्फ़ वहाँ दिखता है जहाँ हार्डवेयर उसे दिखाता है, जो कई client CPUs, AMD प्रोसेसर
  और virtual machines नहीं करते। GPU monitoring, और Redfish के ज़रिए सर्वर के management controller से पढ़ी गई platform पावर, प्रयोगात्मक
  हैं और डिफ़ॉल्ट रूप से बंद हैं।
- **GPU exporters.** NVIDIA का DCGM exporter, संस्करण 4.9.0 में, अपने डिफ़ॉल्ट में `DCGM_FI_DEV_GPU_ENERGY_JOULES_TOTAL` (driver reload
  होने के बाद से ऊर्जा) और `DCGM_FI_DEV_BOARD_POWER_WATTS` प्रकाशित करता है। releases के बीच metric नाम बदले हैं, इसलिए जो संस्करण आप
  लगाते हैं उसकी counters फ़ाइल जाँचें।
- **Serving metrics.** Inference सर्वर अपने counters दिखाते हैं; उदाहरण के लिए llama.cpp का सर्वर `--metrics` के साथ शुरू होने पर एक
  Prometheus endpoint पर `llamacpp:prompt_tokens_total` और `llamacpp:tokens_predicted_total` प्रकाशित करता है। मापी गई node ऊर्जा भाग
  सर्वर की तरफ़ के टोकन आपके बँटवारे की एक उपयोगी जाँच है।

## एक पूरा आर्किटेक्चर कैसा दिखता है? {#what-does-a-worked-architecture-look-like}

**चार परतें: एप्लिकेशन प्रति कॉल और प्रति काम spans और metrics भेजता है; node exporters ऊर्जा मापते हैं; एक छोटा job बाँटता और मिलान करता है;
dashboards ऊर्जा को ग्रिड कार्बन तीव्रता से जोड़ते हैं।** आप इन्हें एक-एक सेवा करके जोड़ सकते हैं।

1. **एप्लिकेशन।** हर मॉडल कॉल GenAI attributes वाला एक client span है। उपयोगकर्ता के सामने आने वाला हर काम एक parent `invoke_agent` span
   है। ऐप टोकन और अवधि के histograms, नतीजे के हिसाब से एक task counter, और तरीके के लेबल वाला एक ऊर्जा counter दर्ज करता है: calibrate किए
   गए प्रति टोकन गुणांकों से *estimated*, या जब मिलान job आँकड़े दे तब *attributed*।
2. **Nodes.** Kubernetes nodes पर Kepler (CPU और, अगर चालू हो, GPU), GPU nodes पर DCGM exporter, और wall पर जाँच के लिए जहाँ मिल सके वहाँ
   BMC या smart-meter रीडिंग।
3. **बँटवारे का job.** हर window में यह node और pod की ऊर्जा पढ़ता है, idle घटाता है, serving metrics से busy time या टोकनों के हिसाब से
   सक्रिय ऊर्जा बाँटता है, हर सेवा और मॉडल के लिए बाँटी गई ऊर्जा लिखता है, और हिस्से और कुल मेल न खाएँ तो alert देता है।
4. **Storage और dashboards.** Metrics कम resolution पर महीनों तक रखे जाते हैं; traces दिनों तक; ग्रिड कार्बन तीव्रता हर क्षेत्र के लिए एक
   gauge के रूप में स्टोर होती है।

<!-- figure: Worked architecture: application services emit OpenTelemetry spans and metrics to a collector; Kepler, the DCGM exporter and BMC readings feed Prometheus; an attribution job reconciles node energy with per-request tokens; a carbon-intensity exporter adds a gauge per region; Grafana shows energy per task, idle share and carbon. -->

### उदाहरण metric नाम {#example-metric-names}

| Metric (Prometheus में स्टोर होने वाला रूप) | प्रकार | स्रोत |
|---|---|---|
| `gen_ai_client_inference_duration_seconds` | Histogram | एप्लिकेशन (OpenTelemetry GenAI convention) |
| `gen_ai_client_inference_operation_input_tokens`, `..._output_tokens` | Histogram | एप्लिकेशन (convention) |
| `example_inference_energy_joules_total{example_energy_method=...}` | Counter | एप्लिकेशन (आपका अपना नाम) |
| `example_task_completed_total{example_outcome="success"}` | Counter | एप्लिकेशन (आपका अपना नाम) |
| `kepler_pod_cpu_joules_total{zone="package"}`, `kepler_pod_gpu_joules_total` | Counter | Kepler |
| `DCGM_FI_DEV_GPU_ENERGY_JOULES_TOTAL` | Counter | DCGM exporter |
| `grid_carbon_intensity_gco2_per_kwh{cloud_region=...}` | Gauge | आपका अपना exporter |

### उदाहरण कोड {#example-code}

नीचे का snippet एक OpenAI-compatible चैट कॉल को OpenTelemetry span में लपेटता है, convention के टोकन और अवधि metrics दर्ज करता है, और एक
ऊर्जा counter जोड़ता है। यह ढालने के लिए एक उदाहरण है: ऊर्जा का आँकड़ा उतना ही अच्छा है जितने अच्छे वे प्रति टोकन गुणांक जो आप अपने मापों से
fit करते हैं, यह अभी cached इनपुट को अलग नहीं मानता, और `example.*` नामों को आपके संगठन का अपना namespace बनना चाहिए।

```python
"""Illustrative: record tokens, latency and an energy figure for each model call with OpenTelemetry.

Adapt before use. Attribute and metric names under gen_ai.* follow the OpenTelemetry GenAI
semantic conventions (v0.1.0, status Development); names under example.* are our own,
because the conventions define no energy metric for model calls.
"""
import json
import time
from contextlib import contextmanager

from opentelemetry import metrics, trace
from opentelemetry.trace import SpanKind, Status, StatusCode

tracer = trace.get_tracer("example.inference")
meter = metrics.get_meter("example.inference")

input_tokens = meter.create_histogram(
    "gen_ai.client.inference.operation.input_tokens", unit="{token}",
    description="Input tokens per inference operation")
output_tokens = meter.create_histogram(
    "gen_ai.client.inference.operation.output_tokens", unit="{token}",
    description="Output tokens per inference operation")
duration = meter.create_histogram(
    "gen_ai.client.inference.duration", unit="s",
    description="Inference operation duration")
tasks = meter.create_counter(
    "example.task.completed", unit="{task}",
    description="User-facing tasks finished, by outcome")
energy = meter.create_counter(
    "example.inference.energy", unit="J",
    description="Energy attributed to inference operations (see example.energy.method)")

# Joules per input and output token for each model on each hardware pool, fitted from your
# own benchmark runs. Never ship made-up coefficients: no entry means no estimate.
with open("energy_coefficients.json") as f:
    COEFFICIENTS = json.load(f)  # {"model@pool": {"j_per_input": ..., "j_per_output": ...}}


def estimate_joules(model, pool, tokens_in, tokens_out):
    c = COEFFICIENTS.get(f"{model}@{pool}")
    if c is None:
        return None
    return c["j_per_input"] * tokens_in + c["j_per_output"] * tokens_out


def chat(client, model, messages, *, provider, pool, region, feature, max_tokens=300):
    """Call an OpenAI-compatible chat endpoint inside a span; never record the prompt itself."""
    base = {"gen_ai.operation.name": "chat", "gen_ai.provider.name": provider,
            "gen_ai.request.model": model}
    # Low-cardinality labels only: no user IDs, request IDs or prompt text on metrics.
    labels = {**base, "example.pool": pool, "cloud.region": region, "example.feature": feature}
    with tracer.start_as_current_span(f"chat {model}", kind=SpanKind.CLIENT,
                                      attributes={**base, "gen_ai.request.max_tokens": max_tokens}) as span:
        start = time.monotonic()
        try:
            response = client.chat.completions.create(model=model, messages=messages,
                                                      max_tokens=max_tokens)
        except Exception as exc:
            error = {**labels, "error.type": type(exc).__qualname__}
            span.set_status(Status(StatusCode.ERROR))
            span.set_attribute("error.type", type(exc).__qualname__)
            duration.record(time.monotonic() - start, error)
            input_tokens.record(0, error)   # the conventions ask for 0 when usage is missing
            output_tokens.record(0, error)
            raise
        usage = response.usage
        details = getattr(usage, "prompt_tokens_details", None)
        cached = getattr(details, "cached_tokens", None) or 0
        span.set_attributes({
            "gen_ai.response.model": response.model,
            "gen_ai.usage.input_tokens": usage.prompt_tokens,
            "gen_ai.usage.output_tokens": usage.completion_tokens,
            "gen_ai.usage.cache_read.input_tokens": cached,
        })
        duration.record(time.monotonic() - start, labels)
        input_tokens.record(usage.prompt_tokens, labels)
        output_tokens.record(usage.completion_tokens, labels)
        joules = estimate_joules(model, pool, usage.prompt_tokens, usage.completion_tokens)
        if joules is not None:
            span.set_attribute("example.energy.joules", joules)
            span.set_attribute("example.energy.method", "estimated")
            energy.add(joules, {**labels, "example.energy.method": "estimated"})
        return response


@contextmanager
def task(agent_name, feature):
    """One user-facing task: every model call inside it becomes a child span of this one."""
    with tracer.start_as_current_span(f"invoke_agent {agent_name}", kind=SpanKind.INTERNAL, attributes={
            "gen_ai.operation.name": "invoke_agent", "gen_ai.agent.name": agent_name}):
        result = {"outcome": "failure"}  # the caller sets "success" once the task's check passes
        try:
            yield result
        finally:
            tasks.add(1, {"example.feature": feature, "example.outcome": result["outcome"]})
```

ऐसे इस्तेमाल होता है:

```python
with task("ticket-tagger", feature="support-tagging") as t:
    reply = chat(client, "small-model", messages, provider="openai",
                 pool="cpu-pool-a", region="eu-west-2", feature="support-tagging")
    if passes_schema_check(reply):
        t["outcome"] = "success"
```

### उदाहरण queries {#example-queries}

```promql
# Power drawn by inference, per feature (watts)
sum by (example_feature) (rate(example_inference_energy_joules_total[5m]))

# Energy per successful task over a day (joules): all energy, including failures, over successes
sum(increase(example_inference_energy_joules_total[1d]))
  / sum(increase(example_task_completed_total{example_outcome="success"}[1d]))

# Calibration check: estimated energy for a pool against Kepler's measured pod energy
sum(rate(example_inference_energy_joules_total{example_pool="gpu-pool-a"}[1h]))
  / (sum(rate(kepler_pod_gpu_joules_total{pod_namespace="inference"}[1h]))
     + sum(rate(kepler_pod_cpu_joules_total{pod_namespace="inference", zone="package"}[1h])))

# Grams of CO2 per hour by region: J/s x 3,600 s/h / 3,600,000 J/kWh x gCO2/kWh
sum by (cloud_region) (rate(example_inference_energy_joules_total[1h])) * 3600 / 3.6e6
  * on (cloud_region) group_left grid_carbon_intensity_gco2_per_kwh
```

## मैं SLOs की तरह ऊर्जा बजट कैसे तय करूँ? {#how-do-i-set-energy-budgets-like-slos}

**एक संकेतक चुनें, हर फ़ीचर के लिए प्रति सफल काम ऊर्जा, अपने baseline से बजट तय करें, और लगातार बढ़त को latency regression की तरह लें।**
कुल को भी नज़र में रखें।

- **संकेतक।** 28 दिन जैसी चलती window में प्रति सफल काम ऊर्जा (सारी ऊर्जा, विफल कोशिशों और retries समेत, भाग वे काम जो अपनी जाँच में पास
  हुए)। जहाँ आपके पास सिर्फ़ टोकन हों, प्रति सफल काम टोकन इस्तेमाल करें; यह पहले हिलता है।
- **बजट।** इसे अनुमान से नहीं, एक मापे गए [baseline](/hi/कैसे/ai-से-ऊर्जा-की-बचत-साबित-करने-के-लिए-मैं-बेसलाइन-कैसे-तय-करूँ/) से तय करें, और जब छोटे मॉडल या cache
  जैसा कोई बदलाव गुंजाइश बनाए तो इसे कसें।
- **Alerts.** baseline से ऊपर लगातार बढ़त पर, प्रति एजेंट रन मॉडल या टूल कॉल में उछाल (एक लूप) पर, GPU pool में idle हिस्से पर, और मिलान की
  विफलताओं पर alert दें।
- **बदलावों पर gate लगाएँ।** जब कोई तय काम अपने टोकन या ऊर्जा बजट से आगे जाए तो CI build फ़ेल करें; देखें
  [CI में ऊर्जा टेस्टिंग](/hi/इंजीनियरिंग/ci-cd-में-ऊर्जा-दक्षता-की-टेस्टिंग-कैसे-जोड़ें/)।
- **कुल पर नज़र रखें।** बढ़ती कुल ऊर्जा के साथ घटती प्रति काम ऊर्जा [रिबाउंड प्रभाव](/hi/शब्दावली/#rebound-effect) है। दोनों को एक ही dashboard
  पर दिखाएँ; देखें [AI ऊर्जा और उत्सर्जन के लक्ष्य कैसे तय करें](/hi/कैसे/मैं-ai-की-ऊर्जा-और-उत्सर्जन-के-लिए-लक्ष्य-कैसे-तय-करूँ/)।


<!-- figure: An energy budget panel: energy per successful task for one feature over 28 days against its budget line, with total energy on a second axis and markers where a model change and a cache release moved the curve. -->
## मैं एजेंटों और distributed workflows को trace कैसे करूँ? {#how-do-i-trace-agents-and-distributed-workflows}

**उपयोगकर्ता के सामने आने वाले हर काम को एक trace दें, उसे सेवाओं और कतारों के पार ले जाएँ, और ऊर्जा को मॉडल-कॉल spans से काम तक जोड़ें।**
एजेंट प्रति कॉल संख्याओं को भ्रामक बना देते हैं; प्रति काम संख्याएँ वही हैं जो उपयोगकर्ता अनुभव करते हैं।

- **Context आगे बढ़ाएँ।** OpenTelemetry SDKs सेवाओं के बीच trace context आगे बढ़ाते हैं, डिफ़ॉल्ट रूप से W3C Trace Context और Baggage
  formats इस्तेमाल करते हुए। इसे HTTP के साथ-साथ message queues और background jobs से भी ले जाएँ, वरना कई सेवाओं वाले काम असंबंधित traces में
  टूट जाएँगे।
- **Trace की संरचना बनाएँ।** हर काम या sub-agent के लिए एक `invoke_agent` span, हर मॉडल कॉल के लिए एक inference span, हर टूल कॉल के लिए एक
  `execute_tool` span। retrieval और embedding कॉल को भी अपने spans मिलते हैं।
- **sampled traces से नहीं, metrics से जोड़ें।** अगर आप traces का नमूना लेते हैं, तो sampled traces आपको कुल नहीं दे सकते। हर कॉल पर ऊर्जा और
  टोकन metrics के रूप में दर्ज करें, और traces का इस्तेमाल अलग-अलग महँगे कामों को समझाने के लिए करें।
- **लूप के संकेतकों पर नज़र रखें।** प्रति एजेंट रन मॉडल और टूल कॉल का, और प्रति काम टोकनों का वितरण बेक़ाबू एजेंटों को बिल से पहले दिखा देता
  है। देखें [AI एजेंटों को टोकन बर्बाद करने से कैसे रोकें](/hi/कैसे/मैं-ai-एजेंटों-को-टोकन-बर्बाद-करने-से-कैसे-रोकूँ/) और
  [agentic AI और टोकन की बर्बादी](/hi/लेख/एजेंटिक-ai-और-टोकन-की-बर्बादी/)।
- **Retries और cache hits को साफ़ तौर पर गिनें।** retry एक दूसरी कॉल है; response-cache hit एक टाली गई कॉल है। देखें
  [LLM कॉल को cache कैसे करें](/hi/कैसे/caching-से-मैं-llm-कॉल-की-ऊर्जा-कैसे-घटाऊँ/)।

<!-- figure: One agent task as a trace tree: an invoke_agent span containing chat spans for each model call, execute_tool spans for tool calls and a retried call, each labelled with tokens and joules, with the task total rolled up at the root. -->

## मैं कार्बन कैसे जोड़ूँ? {#how-do-i-add-carbon}

**ऊर्जा को क्षेत्र और घंटे की ग्रिड कार्बन तीव्रता से, query के समय, गुणा करें, और ऊर्जा को मुख्य आँकड़ा रखें।** कार्बन ग्रिड पर निर्भर है;
ऊर्जा आपके कोड पर।

Green Software Foundation का Software Carbon Intensity स्पेसिफ़िकेशन स्कोर को SCI = ((E × I) + M) per R के रूप में व्यक्त करता है, जहाँ
E ऊर्जा है, I क्षेत्र-विशेष कार्बन तीव्रता है, M embodied उत्सर्जन है और R functional unit है, और यह बाज़ार-आधारित उपायों को बाहर रखता है।
व्यवहार में:

- एक छोटा exporter चलाएँ जो हर क्षेत्र के लिए कार्बन तीव्रता एक gauge के रूप में प्रकाशित करे। ग्रेट ब्रिटेन में Carbon Intensity API
  gCO2/kWh में क्षेत्रीय पूर्वानुमान और अनुमान देता है; Electricity Maps कई दूसरे देशों के लिए ऐतिहासिक, लाइव और पूर्वानुमानित ग्रिड डेटा
  एक साथ लाता है। देखें [ग्रिड कार्बन तीव्रता का डेटा कैसे खोजें](/hi/कैसे/मुझे-अपने-बिजली-ग्रिड-की-कार्बन-इंटेंसिटी-कैसे-पता-चलेगी/)।
- ऊर्जा को `cloud.region` (या अपने डेटा सेंटर के स्थान) से टैग करें और query में जोड़ें, जैसा ऊपर के उदाहरण में है।
- अगर embodied उत्सर्जन आपकी सीमा में हैं, तो उन्हें अलग से जोड़ें; देखें
  [किसी AI फ़ीचर के लिए SCI स्कोर की गणना कैसे करें](/hi/कैसे/मैं-किसी-ai-फ़ीचर-का-software-carbon-intensity-sci-स्कोर-कैसे-निकालूँ/)।

## गोपनीयता और डेटा रखने की अवधि का क्या? {#what-about-privacy-and-retention}

**सामग्री नहीं, गिनती लॉग करें, और विस्तृत traces को aggregate metrics से कम समय के लिए रखें।** ऊर्जा को टोकन गिनती, मॉडल, timings और
हार्डवेयर चाहिए, जिनमें से किसी के लिए prompt की ज़रूरत नहीं।

- **डिफ़ॉल्ट रूप से सामग्री बंद।** OpenTelemetry conventions prompt और जवाब के attributes को Opt-In रखती हैं और चेतावनी देती हैं कि इनमें निजी
  डेटा होने की संभावना है। production में इन्हें बंद रखें। अगर debugging के लिए सामग्री कैप्चर करनी ही पड़े, तो उसे access control के तहत अलग
  स्टोर करें और URI से उसका हवाला दें, जैसा conventions के `*_ref` attributes अनुमति देते हैं, कम expiry के साथ।
- **कम से कम रखें।** EU GDPR का, और UK GDPR का, Article 5 कहता है कि निजी डेटा ज़रूरत तक सीमित हो और ज़रूरत से ज़्यादा समय तक न रखा जाए।
  spans में user identifiers को hash करें या हटा दें, जब तक आपको उनकी ज़रूरत न हो।
- **स्तरों में डेटा रखना।** aggregate metrics, जिनमें labels ठीक से चुने जाएँ तो कोई निजी डेटा नहीं होता, रुझान और मौसमी बदलाव देखने लायक़
  समय तक रखें; traces दिनों या हफ़्तों तक रखें।
- **Telemetry का भी फ़ुटप्रिंट है।** traces का नमूना लें, metrics को aggregate करें, और ऐसे labels हटा दें जिन पर आप कभी query नहीं करते।

## आगे क्या करें {#what-to-do-next}

1. हर मॉडल कॉल में OpenTelemetry GenAI attributes और टोकन metrics जोड़ें, v0.1.0 पर pin करके, prompt कैप्चर बंद रखकर।
2. एक task span और एक task-outcome counter जोड़ें, और एक फ़ीचर के लिए प्रति सफल काम ऊर्जा (या टोकन) का chart बनाएँ।
3. Kepler install करें, या अपने inference nodes पर RAPL, NVML और DCGM पढ़ें, और हर pool की idle पावर दर्ज करें।
4. एक बेंचमार्क रन से प्रति टोकन ऊर्जा गुणांक fit करें (देखें
   [CPU बनाम GPU inference](/hi/इंजीनियरिंग/ऊर्जा-के-लिए-cpu-बनाम-gpu-inference-को-बेंचमार्क-कैसे-करें/)), और हर हफ़्ते अनुमानों का मापी गई node ऊर्जा से मिलान करें।
5. हर क्षेत्र के लिए एक कार्बन-तीव्रता gauge और ऊर्जा panel के बगल में एक कार्बन panel जोड़ें।
6. baseline से बजट तय करें, regressions पर alert दें, और CI में एक ऊर्जा टेस्ट जोड़ें।

## अक्सर पूछे जाने वाले सवाल

### क्या AI ऊर्जा के लिए कोई OpenTelemetry मानक है?

मॉडल कॉल के लिए अभी नहीं। OpenTelemetry GenAI semantic conventions inference, एजेंटों और टूल के लिए spans और metrics को कवर करती हैं, टोकन गिनती समेत, लेकिन कोई ऊर्जा attribute परिभाषित नहीं करतीं। OpenTelemetry की hardware conventions components के लिए joules में hw.energy परिभाषित करती हैं। जब तक कोई convention न आए, प्रति कॉल ऊर्जा के लिए अपना namespaced metric इस्तेमाल करें।

### जब मैं सिर्फ़ पूरे सर्वर को meter कर सकता हूँ, तो प्रति अनुरोध ऊर्जा कैसे पाऊँ?

उसे बाँटें (attribute करें)। किसी समय window में मापी गई ऊर्जा को उस window में serve हुए अनुरोधों में उनके busy time या टोकनों के अनुपात में बाँटें, और idle ऊर्जा अलग से रिपोर्ट करें या किसी बताए गए नियम से बाँटें। जाँचें कि बाँटे गए हिस्से मापे गए कुल के बराबर जुड़ते हैं।

### क्या ऊर्जा निकालने के लिए मुझे prompts लॉग करने चाहिए?

नहीं। ऊर्जा टोकन गिनती, मॉडल, हार्डवेयर और समय पर निर्भर करती है, शब्दों पर नहीं। OpenTelemetry conventions prompt और जवाब की सामग्री को opt-in रखती हैं और चेतावनी देती हैं कि इसमें निजी डेटा होने की संभावना है। सामग्री नहीं, गिनती लॉग करें।

### Kepler क्या है?

Kepler (Kubernetes-based Efficient Power Level Exporter) एक CNCF Sandbox परियोजना है जो Kubernetes nodes, pods और containers के ऊर्जा और पावर metrics Prometheus को export करती है। यह RAPL जैसे हार्डवेयर काउंटर पढ़ती है और सक्रिय पावर को CPU समय के हिसाब से वर्कलोड में बाँटती है।

### मैं dashboard पर ऊर्जा को कार्बन में कैसे बदलूँ?

ऊर्जा को उस क्षेत्र और घंटे की ग्रिड कार्बन तीव्रता से गुणा करें जहाँ और जब वह इस्तेमाल हुई, एप्लिकेशन में नहीं बल्कि query के समय। स्रोतों में ग्रेट ब्रिटेन के लिए GB Carbon Intensity API और दूसरी जगहों के लिए Electricity Maps शामिल हैं। ऊर्जा को मुख्य metric रखें, क्योंकि कार्बन ग्रिड के साथ बदलता है।

## स्रोत

- [OpenTelemetry GenAI semantic conventions (repository and v0.1.0 changelog)](https://github.com/open-telemetry/semantic-conventions-genai), OpenTelemetry (2026)
- [Semantic conventions for generative AI client inference (v0.1.0)](https://github.com/open-telemetry/semantic-conventions-genai/blob/v0.1.0/docs/gen-ai/client-inference.md), OpenTelemetry (2026)
- [Semantic conventions for generative AI agent spans (v0.1.0)](https://github.com/open-telemetry/semantic-conventions-genai/blob/v0.1.0/docs/gen-ai/gen-ai-agent-spans.md), OpenTelemetry (2026)
- [Semantic conventions for generative AI metrics (v0.1.0)](https://github.com/open-telemetry/semantic-conventions-genai/blob/v0.1.0/docs/gen-ai/gen-ai-metrics.md), OpenTelemetry (2026)
- [Semantic conventions for hardware metrics (hw.energy, hw.power)](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/hardware/common.md), OpenTelemetry (2026)
- [Prometheus and OpenMetrics compatibility](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md), OpenTelemetry specification (2026)
- [SDK environment variables (OTEL_PROPAGATORS)](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md), OpenTelemetry specification (2026)
- [Metric and label naming](https://prometheus.io/docs/practices/naming/), Prometheus documentation (2026)
- [Kepler: Kubernetes-based Efficient Power Level Exporter](https://github.com/sustainable-computing-io/kepler), Kepler project, CNCF (2026)
- [Kepler metrics (v0.14.0)](https://github.com/sustainable-computing-io/kepler/blob/v0.14.0/docs/user/metrics.md), Kepler project, CNCF (2026)
- [Kepler power attribution guide (v0.14.0)](https://github.com/sustainable-computing-io/kepler/blob/v0.14.0/docs/developer/power-attribution-guide.md), Kepler project, CNCF (2026)
- [Kepler configuration (v0.14.0): experimental GPU and Redfish options](https://github.com/sustainable-computing-io/kepler/blob/v0.14.0/docs/user/configuration.md), Kepler project, CNCF (2026)
- [DCGM exporter default counters (4.9.0)](https://github.com/NVIDIA/dcgm-exporter/blob/4.9.0/etc/default-counters.csv), NVIDIA (2026)
- [NVML API reference: device queries](https://docs.nvidia.com/deploy/nvml-api/api/group__nvmlDeviceQueries.html), NVIDIA (2026)
- [llama.cpp HTTP server (/metrics)](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md), llama.cpp project (2026)
- [Energy considerations of large language model inference and efficiency optimizations](https://arxiv.org/abs/2504.17674), Fernandez et al. (arXiv 2504.17674) (2025)
- [Software Carbon Intensity (SCI) specification](https://sci.greensoftware.foundation/), Green Software Foundation (2024)
- [Carbon Intensity API](https://carbonintensity.org.uk/), National Energy System Operator (2026)
- [Electricity Maps](https://www.electricitymaps.com/), Electricity Maps (2026)
- [General Data Protection Regulation, Article 5](https://gdpr-info.eu/art-5-gdpr/), Regulation (EU) 2016/679, via gdpr-info.eu (2016)
- [A guide to the data protection principles (UK GDPR)](https://ico.org.uk/for-organisations/uk-gdpr-guidance-and-resources/data-protection-principles/a-guide-to-the-data-protection-principles/), Information Commissioner's Office (2026)
