Documentation ¶
Index ¶
- Variables
- type EntityMetric
- type IntervalList
- type Manager
- func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error)
- func (m *Manager) CounterInfo(ctx context.Context) ([]types.PerfCounterInfo, error)
- func (m *Manager) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCounterInfo, error)
- func (m *Manager) CounterInfoByName(ctx context.Context) (map[string]*types.PerfCounterInfo, error)
- func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error)
- func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error)
- func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error)
- func (m *Manager) QueryCounter(ctx context.Context, ids []int32) ([]types.PerfCounterInfo, error)
- func (m *Manager) SampleByName(ctx context.Context, spec types.PerfQuerySpec, metrics []string, ...) ([]types.BasePerfEntityMetricBase, error)
- func (m *Manager) ToMetricSeries(ctx context.Context, series []types.BasePerfEntityMetricBase) ([]EntityMetric, error)
- type MetricList
- type MetricSeries
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Intervals maps name to seconds for the built-in historical intervals Intervals = map[string]int32{ "real": 0, "day": 300, "week": 1800, "month": 7200, "year": 86400, } )
Functions ¶
This section is empty.
Types ¶
type EntityMetric ¶
type EntityMetric struct { Entity types.ManagedObjectReference `json:"entity"` SampleInfo []types.PerfSampleInfo `json:"sampleInfo"` Value []MetricSeries `json:"value"` }
EntityMetric contains the same data as types.PerfEntityMetric, but with MetricSeries type for the Value field.
func (*EntityMetric) SampleInfoCSV ¶
func (m *EntityMetric) SampleInfoCSV() string
SampleInfoCSV converts the SampleInfo field to a CSV string
type IntervalList ¶
type IntervalList []types.PerfInterval
IntervalList wraps []types.PerfInterval.
func (IntervalList) Enabled ¶
func (l IntervalList) Enabled() map[int32][]string
Enabled returns a map with Level as the key and enabled PerfInterval.Name(s) as the value.
type Manager ¶
Manager wraps mo.PerformanceManager.
func NewManager ¶
NewManager creates a new Manager instance.
func (*Manager) AvailableMetric ¶
func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error)
AvailableMetric wraps the QueryAvailablePerfMetric method. The MetricList is sorted by PerfCounterInfo.GroupInfo.Key if Manager.Sort == true.
func (*Manager) CounterInfo ¶
CounterInfo gets the PerformanceManager.PerfCounter property. The property value is only collected once, subsequent calls return the cached value.
func (*Manager) CounterInfoByKey ¶
CounterInfoByKey converts the PerformanceManager.PerfCounter property to a map, where key is types.PerfCounterInfo.Key.
func (*Manager) CounterInfoByName ¶
CounterInfoByName converts the PerformanceManager.PerfCounter property to a map, where key is types.PerfCounterInfo.Name().
func (*Manager) HistoricalInterval ¶
func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error)
HistoricalInterval gets the PerformanceManager.HistoricalInterval property and wraps as an IntervalList.
func (*Manager) ProviderSummary ¶
func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error)
ProviderSummary wraps the QueryPerfProviderSummary method, caching the value based on entity.Type.
func (*Manager) Query ¶
func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error)
Query wraps the QueryPerf method.
func (*Manager) QueryCounter ¶ added in v0.26.0
QueryCounter wraps the QueryPerfCounter method.
func (*Manager) SampleByName ¶
func (m *Manager) SampleByName(ctx context.Context, spec types.PerfQuerySpec, metrics []string, entity []types.ManagedObjectReference) ([]types.BasePerfEntityMetricBase, error)
SampleByName uses the spec param as a template, constructing a []types.PerfQuerySpec for the given metrics and entities and invoking the Query method. The spec template can specify instances using the MetricId.Instance field, by default all instances are collected. The spec template MaxSample defaults to 1. If the spec template IntervalId is a historical interval and StartTime is not specified, the StartTime is set to the current time - (IntervalId * MaxSample).
func (*Manager) ToMetricSeries ¶
func (m *Manager) ToMetricSeries(ctx context.Context, series []types.BasePerfEntityMetricBase) ([]EntityMetric, error)
ToMetricSeries converts []BasePerfEntityMetricBase to []EntityMetric
Example ¶
package main import ( "context" "fmt" "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/performance" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/view" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/types" ) func main() { simulator.Run(func(ctx context.Context, c *vim25.Client) error { // Get virtual machines references m := view.NewManager(c) v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, nil, true) if err != nil { return err } defer v.Destroy(ctx) vmsRefs, err := v.Find(ctx, []string{"VirtualMachine"}, nil) if err != nil { return err } // Create a PerfManager perfManager := performance.NewManager(c) // Retrieve counters name list counters, err := perfManager.CounterInfoByName(ctx) if err != nil { return err } var names []string for name := range counters { names = append(names, name) } // Create PerfQuerySpec spec := types.PerfQuerySpec{ MaxSample: 1, MetricId: []types.PerfMetricId{{Instance: "*"}}, IntervalId: 300, } // Query metrics sample, err := perfManager.SampleByName(ctx, spec, names, vmsRefs) if err != nil { return err } result, err := perfManager.ToMetricSeries(ctx, sample) if err != nil { return err } // Read result for _, metric := range result { vm := object.NewVirtualMachine(c, metric.Entity) name, err := vm.ObjectName(ctx) if err != nil { return err } for _, v := range metric.Value { counter := counters[v.Name] units := counter.UnitInfo.GetElementDescription().Label instance := v.Instance if instance == "" { instance = "-" } if len(v.Value) != 0 && v.Name == "sys.uptime.latest" { fmt.Printf("%s\t%s\t%s\t%s\n", name, instance, v.Name, units) break } } } return nil }) }
Output: DC0_H0_VM0 * sys.uptime.latest s DC0_H0_VM1 * sys.uptime.latest s DC0_C0_RP0_VM0 * sys.uptime.latest s DC0_C0_RP0_VM1 * sys.uptime.latest s
type MetricList ¶
type MetricList []types.PerfMetricId
MetricList wraps []types.PerfMetricId
func (MetricList) ByKey ¶
func (l MetricList) ByKey() map[int32][]*types.PerfMetricId
ByKey converts MetricList to map, where key is types.PerfMetricId.CounterId / types.PerfCounterInfo.Key
type MetricSeries ¶
type MetricSeries struct { Name string `json:"name"` Unit string `json:"unit"` Instance string `json:"instance"` Value []int64 `json:"value"` }
MetricSeries contains the same data as types.PerfMetricIntSeries, but with the CounterId converted to Name.
func (*MetricSeries) Format ¶
func (s *MetricSeries) Format(val int64) string
func (*MetricSeries) ValueCSV ¶
func (s *MetricSeries) ValueCSV() string
ValueCSV converts the Value field to a CSV string