| 1 |
// Code generated from semantic convention specification. DO NOT EDIT. |
| 2 |
|
| 3 |
// Copyright The OpenTelemetry Authors |
| 4 |
// SPDX-License-Identifier: Apache-2.0 |
| 5 |
|
| 6 |
// Package cpuconv provides types and functionality for OpenTelemetry semantic |
| 7 |
// conventions in the "cpu" namespace. |
| 8 |
package cpuconv |
| 9 |
|
| 10 |
import ( |
| 11 |
"context" |
| 12 |
"sync" |
| 13 |
|
| 14 |
"go.opentelemetry.io/otel/attribute" |
| 15 |
"go.opentelemetry.io/otel/metric" |
| 16 |
"go.opentelemetry.io/otel/metric/noop" |
| 17 |
) |
| 18 |
|
| 19 |
var ( |
| 20 |
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }} |
| 21 |
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }} |
| 22 |
) |
| 23 |
|
| 24 |
// ModeAttr is an attribute conforming to the cpu.mode semantic conventions. It |
| 25 |
// represents the mode of the CPU. |
| 26 |
type ModeAttr string |
| 27 |
|
| 28 |
var ( |
| 29 |
// ModeUser is the none. |
| 30 |
ModeUser ModeAttr = "user" |
| 31 |
// ModeSystem is the none. |
| 32 |
ModeSystem ModeAttr = "system" |
| 33 |
// ModeNice is the none. |
| 34 |
ModeNice ModeAttr = "nice" |
| 35 |
// ModeIdle is the none. |
| 36 |
ModeIdle ModeAttr = "idle" |
| 37 |
// ModeIOWait is the none. |
| 38 |
ModeIOWait ModeAttr = "iowait" |
| 39 |
// ModeInterrupt is the none. |
| 40 |
ModeInterrupt ModeAttr = "interrupt" |
| 41 |
// ModeSteal is the none. |
| 42 |
ModeSteal ModeAttr = "steal" |
| 43 |
// ModeKernel is the none. |
| 44 |
ModeKernel ModeAttr = "kernel" |
| 45 |
) |
| 46 |
|
| 47 |
// Frequency is an instrument used to record metric values conforming to the |
| 48 |
// "cpu.frequency" semantic conventions. It represents the operating frequency of |
| 49 |
// the logical CPU in Hertz. |
| 50 |
type Frequency struct { |
| 51 |
metric.Int64Gauge |
| 52 |
} |
| 53 |
|
| 54 |
// NewFrequency returns a new Frequency instrument. |
| 55 |
func NewFrequency( |
| 56 |
m metric.Meter, |
| 57 |
opt ...metric.Int64GaugeOption, |
| 58 |
) (Frequency, error) { |
| 59 |
// Check if the meter is nil. |
| 60 |
if m == nil { |
| 61 |
return Frequency{noop.Int64Gauge{}}, nil |
| 62 |
} |
| 63 |
|
| 64 |
i, err := m.Int64Gauge( |
| 65 |
"cpu.frequency", |
| 66 |
append([]metric.Int64GaugeOption{ |
| 67 |
metric.WithDescription("Operating frequency of the logical CPU in Hertz."), |
| 68 |
metric.WithUnit("Hz"), |
| 69 |
}, opt...)..., |
| 70 |
) |
| 71 |
if err != nil { |
| 72 |
return Frequency{noop.Int64Gauge{}}, err |
| 73 |
} |
| 74 |
return Frequency{i}, nil |
| 75 |
} |
| 76 |
|
| 77 |
// Inst returns the underlying metric instrument. |
| 78 |
func (m Frequency) Inst() metric.Int64Gauge { |
| 79 |
return m.Int64Gauge |
| 80 |
} |
| 81 |
|
| 82 |
// Name returns the semantic convention name of the instrument. |
| 83 |
func (Frequency) Name() string { |
| 84 |
return "cpu.frequency" |
| 85 |
} |
| 86 |
|
| 87 |
// Unit returns the semantic convention unit of the instrument |
| 88 |
func (Frequency) Unit() string { |
| 89 |
return "Hz" |
| 90 |
} |
| 91 |
|
| 92 |
// Description returns the semantic convention description of the instrument |
| 93 |
func (Frequency) Description() string { |
| 94 |
return "Operating frequency of the logical CPU in Hertz." |
| 95 |
} |
| 96 |
|
| 97 |
// Record records val to the current distribution. |
| 98 |
// |
| 99 |
// All additional attrs passed are included in the recorded value. |
| 100 |
func (m Frequency) Record( |
| 101 |
ctx context.Context, |
| 102 |
val int64, |
| 103 |
attrs ...attribute.KeyValue, |
| 104 |
) { |
| 105 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 106 |
defer func() { |
| 107 |
*o = (*o)[:0] |
| 108 |
recOptPool.Put(o) |
| 109 |
}() |
| 110 |
|
| 111 |
*o = append( |
| 112 |
*o, |
| 113 |
metric.WithAttributes( |
| 114 |
attrs..., |
| 115 |
), |
| 116 |
) |
| 117 |
|
| 118 |
m.Int64Gauge.Record(ctx, val, *o...) |
| 119 |
} |
| 120 |
|
| 121 |
// AttrLogicalNumber returns an optional attribute for the "cpu.logical_number" |
| 122 |
// semantic convention. It represents the logical CPU number [0..n-1]. |
| 123 |
func (Frequency) AttrLogicalNumber(val int) attribute.KeyValue { |
| 124 |
return attribute.Int("cpu.logical_number", val) |
| 125 |
} |
| 126 |
|
| 127 |
// Time is an instrument used to record metric values conforming to the |
| 128 |
// "cpu.time" semantic conventions. It represents the seconds each logical CPU |
| 129 |
// spent on each mode. |
| 130 |
type Time struct { |
| 131 |
metric.Float64ObservableCounter |
| 132 |
} |
| 133 |
|
| 134 |
// NewTime returns a new Time instrument. |
| 135 |
func NewTime( |
| 136 |
m metric.Meter, |
| 137 |
opt ...metric.Float64ObservableCounterOption, |
| 138 |
) (Time, error) { |
| 139 |
// Check if the meter is nil. |
| 140 |
if m == nil { |
| 141 |
return Time{noop.Float64ObservableCounter{}}, nil |
| 142 |
} |
| 143 |
|
| 144 |
i, err := m.Float64ObservableCounter( |
| 145 |
"cpu.time", |
| 146 |
append([]metric.Float64ObservableCounterOption{ |
| 147 |
metric.WithDescription("Seconds each logical CPU spent on each mode"), |
| 148 |
metric.WithUnit("s"), |
| 149 |
}, opt...)..., |
| 150 |
) |
| 151 |
if err != nil { |
| 152 |
return Time{noop.Float64ObservableCounter{}}, err |
| 153 |
} |
| 154 |
return Time{i}, nil |
| 155 |
} |
| 156 |
|
| 157 |
// Inst returns the underlying metric instrument. |
| 158 |
func (m Time) Inst() metric.Float64ObservableCounter { |
| 159 |
return m.Float64ObservableCounter |
| 160 |
} |
| 161 |
|
| 162 |
// Name returns the semantic convention name of the instrument. |
| 163 |
func (Time) Name() string { |
| 164 |
return "cpu.time" |
| 165 |
} |
| 166 |
|
| 167 |
// Unit returns the semantic convention unit of the instrument |
| 168 |
func (Time) Unit() string { |
| 169 |
return "s" |
| 170 |
} |
| 171 |
|
| 172 |
// Description returns the semantic convention description of the instrument |
| 173 |
func (Time) Description() string { |
| 174 |
return "Seconds each logical CPU spent on each mode" |
| 175 |
} |
| 176 |
|
| 177 |
// AttrLogicalNumber returns an optional attribute for the "cpu.logical_number" |
| 178 |
// semantic convention. It represents the logical CPU number [0..n-1]. |
| 179 |
func (Time) AttrLogicalNumber(val int) attribute.KeyValue { |
| 180 |
return attribute.Int("cpu.logical_number", val) |
| 181 |
} |
| 182 |
|
| 183 |
// AttrMode returns an optional attribute for the "cpu.mode" semantic convention. |
| 184 |
// It represents the mode of the CPU. |
| 185 |
func (Time) AttrMode(val ModeAttr) attribute.KeyValue { |
| 186 |
return attribute.String("cpu.mode", string(val)) |
| 187 |
} |
| 188 |
|
| 189 |
// Utilization is an instrument used to record metric values conforming to the |
| 190 |
// "cpu.utilization" semantic conventions. It represents the for each logical |
| 191 |
// CPU, the utilization is calculated as the change in cumulative CPU time |
| 192 |
// (cpu.time) over a measurement interval, divided by the elapsed time. |
| 193 |
type Utilization struct { |
| 194 |
metric.Int64Gauge |
| 195 |
} |
| 196 |
|
| 197 |
// NewUtilization returns a new Utilization instrument. |
| 198 |
func NewUtilization( |
| 199 |
m metric.Meter, |
| 200 |
opt ...metric.Int64GaugeOption, |
| 201 |
) (Utilization, error) { |
| 202 |
// Check if the meter is nil. |
| 203 |
if m == nil { |
| 204 |
return Utilization{noop.Int64Gauge{}}, nil |
| 205 |
} |
| 206 |
|
| 207 |
i, err := m.Int64Gauge( |
| 208 |
"cpu.utilization", |
| 209 |
append([]metric.Int64GaugeOption{ |
| 210 |
metric.WithDescription("For each logical CPU, the utilization is calculated as the change in cumulative CPU time (cpu.time) over a measurement interval, divided by the elapsed time."), |
| 211 |
metric.WithUnit("1"), |
| 212 |
}, opt...)..., |
| 213 |
) |
| 214 |
if err != nil { |
| 215 |
return Utilization{noop.Int64Gauge{}}, err |
| 216 |
} |
| 217 |
return Utilization{i}, nil |
| 218 |
} |
| 219 |
|
| 220 |
// Inst returns the underlying metric instrument. |
| 221 |
func (m Utilization) Inst() metric.Int64Gauge { |
| 222 |
return m.Int64Gauge |
| 223 |
} |
| 224 |
|
| 225 |
// Name returns the semantic convention name of the instrument. |
| 226 |
func (Utilization) Name() string { |
| 227 |
return "cpu.utilization" |
| 228 |
} |
| 229 |
|
| 230 |
// Unit returns the semantic convention unit of the instrument |
| 231 |
func (Utilization) Unit() string { |
| 232 |
return "1" |
| 233 |
} |
| 234 |
|
| 235 |
// Description returns the semantic convention description of the instrument |
| 236 |
func (Utilization) Description() string { |
| 237 |
return "For each logical CPU, the utilization is calculated as the change in cumulative CPU time (cpu.time) over a measurement interval, divided by the elapsed time." |
| 238 |
} |
| 239 |
|
| 240 |
// Record records val to the current distribution. |
| 241 |
// |
| 242 |
// All additional attrs passed are included in the recorded value. |
| 243 |
func (m Utilization) Record( |
| 244 |
ctx context.Context, |
| 245 |
val int64, |
| 246 |
attrs ...attribute.KeyValue, |
| 247 |
) { |
| 248 |
o := recOptPool.Get().(*[]metric.RecordOption) |
| 249 |
defer func() { |
| 250 |
*o = (*o)[:0] |
| 251 |
recOptPool.Put(o) |
| 252 |
}() |
| 253 |
|
| 254 |
*o = append( |
| 255 |
*o, |
| 256 |
metric.WithAttributes( |
| 257 |
attrs..., |
| 258 |
), |
| 259 |
) |
| 260 |
|
| 261 |
m.Int64Gauge.Record(ctx, val, *o...) |
| 262 |
} |
| 263 |
|
| 264 |
// AttrLogicalNumber returns an optional attribute for the "cpu.logical_number" |
| 265 |
// semantic convention. It represents the logical CPU number [0..n-1]. |
| 266 |
func (Utilization) AttrLogicalNumber(val int) attribute.KeyValue { |
| 267 |
return attribute.Int("cpu.logical_number", val) |
| 268 |
} |
| 269 |
|
| 270 |
// AttrMode returns an optional attribute for the "cpu.mode" semantic convention. |
| 271 |
// It represents the mode of the CPU. |
| 272 |
func (Utilization) AttrMode(val ModeAttr) attribute.KeyValue { |
| 273 |
return attribute.String("cpu.mode", string(val)) |
| 274 |
} |