awsecscontainermetrics

package
v0.39.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointEnvKey = "ECS_CONTAINER_METADATA_URI_V4"
)

Constant attributes for aws ecs container metrics.

Variables

This section is empty.

Functions

func MetricsData

func MetricsData(containerStatsMap map[string]*ContainerStats, metadata TaskMetadata, logger *zap.Logger) []pdata.Metrics

MetricsData generates OTLP metrics from endpoint raw data

Types

type CPUStats

type CPUStats struct {
	CPUUsage       *CPUUsage `json:"cpu_usage,omitempty"`
	OnlineCpus     *uint64   `json:"online_cpus,omitempty"`
	SystemCPUUsage *uint64   `json:"system_cpu_usage,omitempty"`
	CPUUtilized    *uint64
	CPUReserved    *uint64
}

CPUStats defines Cpu stats

type CPUUsage

type CPUUsage struct {
	TotalUsage        *uint64   `json:"total_usage,omitempty"`
	UsageInKernelmode *uint64   `json:"usage_in_kernelmode,omitempty"`
	UsageInUserMode   *uint64   `json:"usage_in_usermode,omitempty"`
	PerCPUUsage       []*uint64 `json:"percpu_usage,omitempty"`
}

CPUUsage defines raw Cpu usage

type Client

type Client interface {
	Get(path string) ([]byte, error)
}

Client defines the rest client interface

type ClientProvider

type ClientProvider interface {
	BuildClient() Client
}

ClientProvider defines

func NewClientProvider

func NewClientProvider(endpoint url.URL, logger *zap.Logger) ClientProvider

NewClientProvider creates the default rest client provider

type ContainerMetadata

type ContainerMetadata struct {
	DockerID      string            `json:"DockerId,omitempty"`
	ContainerName string            `json:"Name,omitempty"`
	DockerName    string            `json:"DockerName,omitempty"`
	Image         string            `json:"Image,omitempty"`
	Labels        map[string]string `json:"Labels,omitempty"`
	Limits        Limit             `json:"Limits,omitempty"`
	ImageID       string            `json:"ImageID,omitempty"`
	CreatedAt     string            `json:"CreatedAt,omitempty"`
	StartedAt     string            `json:"StartedAt,omitempty"`
	FinishedAt    string            `json:"FinishedAt,omitempty"`
	KnownStatus   string            `json:"KnownStatus,omitempty"`
	ExitCode      *int64            `json:"ExitCode,omitempty"`
}

ContainerMetadata defines container metadata for a container

type ContainerStats

type ContainerStats struct {
	Name         string    `json:"name"`
	ID           string    `json:"id"`
	Read         time.Time `json:"read"`
	PreviousRead time.Time `json:"preread"`

	Memory      *MemoryStats            `json:"memory_stats,omitempty"`
	Disk        *DiskStats              `json:"blkio_stats,omitempty"`
	Network     map[string]NetworkStats `json:"networks,omitempty"`
	NetworkRate *NetworkRateStats       `json:"network_rate_stats,omitempty"`
	CPU         *CPUStats               `json:"cpu_stats,omitempty"`
	PreviousCPU *CPUStats               `json:"precpu_stats,omitempty"`
}

ContainerStats defines the structure for container stats

type DiskStats

type DiskStats struct {
	IoServiceBytesRecursives []IoServiceBytesRecursive `json:"io_service_bytes_recursive,omitempty"`
}

DiskStats defines the storage stats

type ECSMetrics

type ECSMetrics struct {
	MemoryUsage    uint64
	MemoryMaxUsage uint64
	MemoryLimit    uint64
	MemoryUtilized uint64
	MemoryReserved uint64

	CPUTotalUsage        uint64
	CPUUsageInKernelmode uint64
	CPUUsageInUserMode   uint64
	CPUOnlineCpus        uint64
	SystemCPUUsage       uint64
	NumOfCPUCores        uint64
	CPUReserved          float64
	CPUUtilized          float64
	CPUUsageInVCPU       float64

	NetworkRateRxBytesPerSecond float64
	NetworkRateTxBytesPerSecond float64

	NetworkRxBytes   uint64
	NetworkRxPackets uint64
	NetworkRxErrors  uint64
	NetworkRxDropped uint64
	NetworkTxBytes   uint64
	NetworkTxPackets uint64
	NetworkTxErrors  uint64
	NetworkTxDropped uint64

	StorageReadBytes  uint64
	StorageWriteBytes uint64
}

ECSMetrics defines the structure container/task level metrics

type HTTPRestClient

type HTTPRestClient struct {
	// contains filtered or unexported fields
}

HTTPRestClient is a thin wrapper around an ecs task metadata client, encapsulating endpoints and their corresponding http methods.

func NewRestClient

func NewRestClient(client Client) *HTTPRestClient

NewRestClient creates a new copy of the Rest Client

func (*HTTPRestClient) EndpointResponse

func (c *HTTPRestClient) EndpointResponse() ([]byte, []byte, error)

EndpointResponse gets the task metadata and docker stats from ECS Task Metadata Endpoint

type IoServiceBytesRecursive

type IoServiceBytesRecursive struct {
	Major *uint64 `json:"major,omitempty"`
	Minor *uint64 `json:"minor,omitempty"`
	Op    string  `json:"op,omitempty"`
	Value *uint64 `json:"value,omitempty"`
}

IoServiceBytesRecursive defines the IO device stats

type Limit

type Limit struct {
	CPU    *float64 `json:"CPU,omitempty"`
	Memory *uint64  `json:"Memory,omitempty"`
}

Limit defines the Cpu and Memory limts

type MemoryStats

type MemoryStats struct {
	Usage          *uint64 `json:"usage,omitempty"`
	MaxUsage       *uint64 `json:"max_usage,omitempty"`
	Limit          *uint64 `json:"limit,omitempty"`
	MemoryUtilized *uint64
	MemoryReserved *uint64
	Stats          map[string]uint64 `json:"stats,omitempty"`
}

MemoryStats defines the memory stats

type NetworkRateStats

type NetworkRateStats struct {
	RxBytesPerSecond *float64 `json:"rx_bytes_per_sec,omitempty"`
	TxBytesPerSecond *float64 `json:"tx_bytes_per_sec,omitempty"`
}

NetworkRateStats doesn't come from docker stat. The rates are being calculated in ECS agent

type NetworkStats

type NetworkStats struct {
	RxBytes   *uint64 `json:"rx_bytes,omitempty"`
	RxPackets *uint64 `json:"rx_packets,omitempty"`
	RxErrors  *uint64 `json:"rx_errors,omitempty"`
	RxDropped *uint64 `json:"rx_dropped,omitempty"`
	TxBytes   *uint64 `json:"tx_bytes,omitempty"`
	TxPackets *uint64 `json:"tx_packets,omitempty"`
	TxErrors  *uint64 `json:"tx_errors,omitempty"`
	TxDropped *uint64 `json:"tx_dropped,omitempty"`
}

NetworkStats defines the network stats

type RestClient

type RestClient interface {
	EndpointResponse() ([]byte, []byte, error)
}

RestClient is swappable for testing.

type StatsProvider

type StatsProvider struct {
	// contains filtered or unexported fields
}

StatsProvider wraps a RestClient, returning an unmarshaled metadata and docker stats

func NewStatsProvider

func NewStatsProvider(rc RestClient) *StatsProvider

NewStatsProvider returns a new stats provider

func (*StatsProvider) GetStats

func (p *StatsProvider) GetStats() (map[string]*ContainerStats, TaskMetadata, error)

GetStats calls the ecs task metadata endpoint and unmarshals the data

type TaskMetadata

type TaskMetadata struct {
	Cluster          string `json:"Cluster,omitempty"`
	TaskARN          string `json:"TaskARN,omitempty"`
	Family           string `json:"Family,omitempty"`
	Revision         string `json:"Revision,omitempty"`
	AvailabilityZone string `json:"AvailabilityZone,omitempty"`
	PullStartedAt    string `json:"PullStartedAt,omitempty"`
	PullStoppedAt    string `json:"PullStoppedAt,omitempty"`
	KnownStatus      string `json:"KnownStatus,omitempty"`
	LaunchType       string `json:"LaunchType,omitempty"`

	Limits     Limit               `json:"Limits,omitempty"`
	Containers []ContainerMetadata `json:"Containers,omitempty"`
}

TaskMetadata defines task metadata for a task

type TaskStats

type TaskStats struct {
	Memory            MemoryStats
	NetworkRate       NetworkRateStats
	Network           NetworkStats
	CPU               CPUStats
	StorageReadBytes  *uint64
	StorageWriteBytes *uint64
}

TaskStats defines the stats for a task

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL