instmetrics

package
v0.0.0-...-2e8aeb9 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package instmetrics contains the main logic and helpers for the crownlabs custom-metrics-server component.

Index

Constants

This section is empty.

Variables

View Source
var File_instmetrics_proto protoreflect.FileDescriptor
View Source
var InstanceMetrics_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "instmetrics.InstanceMetrics",
	HandlerType: (*InstanceMetricsServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "ContainerMetrics",
			Handler:    _InstanceMetrics_ContainerMetrics_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "instmetrics.proto",
}

InstanceMetrics_ServiceDesc is the grpc.ServiceDesc for InstanceMetrics service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterInstanceMetricsServer

func RegisterInstanceMetricsServer(s grpc.ServiceRegistrar, srv InstanceMetricsServer)

Types

type CRIMetricsScraper

type CRIMetricsScraper struct {
	RuntimeClient *RemoteRuntimeServiceClient
}

CRIMetricsScraper extracts container stats using the CRI-API.

type ContainerMetricsRequest

type ContainerMetricsRequest struct {

	// Filter needed to find target "application container"
	PodName string `protobuf:"bytes,1,opt,name=pod_name,json=podName,proto3" json:"pod_name,omitempty"`
	// contains filtered or unexported fields
}

func (*ContainerMetricsRequest) Descriptor deprecated

func (*ContainerMetricsRequest) Descriptor() ([]byte, []int)

Deprecated: Use ContainerMetricsRequest.ProtoReflect.Descriptor instead.

func (*ContainerMetricsRequest) GetPodName

func (x *ContainerMetricsRequest) GetPodName() string

func (*ContainerMetricsRequest) ProtoMessage

func (*ContainerMetricsRequest) ProtoMessage()

func (*ContainerMetricsRequest) ProtoReflect

func (x *ContainerMetricsRequest) ProtoReflect() protoreflect.Message

func (*ContainerMetricsRequest) Reset

func (x *ContainerMetricsRequest) Reset()

func (*ContainerMetricsRequest) String

func (x *ContainerMetricsRequest) String() string

type ContainerMetricsResponse

type ContainerMetricsResponse struct {
	CpuPerc   float32 `protobuf:"fixed32,1,opt,name=cpu_perc,json=cpuPerc,proto3" json:"cpu_perc,omitempty"`
	MemBytes  uint64  `protobuf:"varint,2,opt,name=mem_bytes,json=memBytes,proto3" json:"mem_bytes,omitempty"`
	DiskBytes uint64  `protobuf:"varint,3,opt,name=disk_bytes,json=diskBytes,proto3" json:"disk_bytes,omitempty"`
	// contains filtered or unexported fields
}

func (*ContainerMetricsResponse) Descriptor deprecated

func (*ContainerMetricsResponse) Descriptor() ([]byte, []int)

Deprecated: Use ContainerMetricsResponse.ProtoReflect.Descriptor instead.

func (*ContainerMetricsResponse) GetCpuPerc

func (x *ContainerMetricsResponse) GetCpuPerc() float32

func (*ContainerMetricsResponse) GetDiskBytes

func (x *ContainerMetricsResponse) GetDiskBytes() uint64

func (*ContainerMetricsResponse) GetMemBytes

func (x *ContainerMetricsResponse) GetMemBytes() uint64

func (*ContainerMetricsResponse) ProtoMessage

func (*ContainerMetricsResponse) ProtoMessage()

func (*ContainerMetricsResponse) ProtoReflect

func (x *ContainerMetricsResponse) ProtoReflect() protoreflect.Message

func (*ContainerMetricsResponse) Reset

func (x *ContainerMetricsResponse) Reset()

func (*ContainerMetricsResponse) String

func (x *ContainerMetricsResponse) String() string

type ContainerStats

type ContainerStats struct {
	// Timestamp in nanoseconds at which the information were collected
	CPUTimestamp int64
	// Cumulative CPU usage (sum across all cores) since object creation.
	UsageCoreNanoSeconds uint64
	// Total memory in use.
	MemoryUsageInBytes uint64
	// UsedBytes represents the bytes used for images on the filesystem.
	// This may differ from the total bytes used on the filesystem and may not
	// equal CapacityBytes - AvailableBytes.
	DiskUsageInBytes uint64
	// contains filtered or unexported fields
}

ContainerStats used to compute metrics.

type ContainerStatsResponse

type ContainerStatsResponse struct {
	MemoryStats struct {
		Usage uint64 `json:"usage"`
	} `json:"memory_stats"`

	CPUStats struct {
		Timestamp int64  `json:"system_cpu_usage"`
		Cores     uint64 `json:"online_cpus"`

		Usage struct {
			Total uint64 `json:"total_usage"`
		} `json:"cpu_usage"`
	} `json:"cpu_stats"`
}

ContainerStatsResponse is the response from the docker API for container stats.

type CustomMetrics

type CustomMetrics struct {
	CPUPerc   float32 `json:"cpu"`
	MemBytes  uint64  `json:"mem"`
	DiskBytes uint64  `json:"disk"`
}

CustomMetrics stores desired metrics of a container.

func (CustomMetrics) String

func (c CustomMetrics) String() string

type DockerMetricsScraper

type DockerMetricsScraper struct {
	// Client is the API client that performs all operations against a docker server.
	DockerClient       *client.Client
	ContStatsListMutex *sync.RWMutex
}

DockerMetricsScraper extracts container stats using the docker API client.

type InstanceMetricsClient

type InstanceMetricsClient interface {
	// ContainerMetrics returns metrics of the "application container" related to the required PodName.
	// If the container does not exist, the call returns an error.
	ContainerMetrics(ctx context.Context, in *ContainerMetricsRequest, opts ...grpc.CallOption) (*ContainerMetricsResponse, error)
}

InstanceMetricsClient is the client API for InstanceMetrics service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type InstanceMetricsServer

type InstanceMetricsServer interface {
	// ContainerMetrics returns metrics of the "application container" related to the required PodName.
	// If the container does not exist, the call returns an error.
	ContainerMetrics(context.Context, *ContainerMetricsRequest) (*ContainerMetricsResponse, error)
	// contains filtered or unexported methods
}

InstanceMetricsServer is the server API for InstanceMetrics service. All implementations must embed UnimplementedInstanceMetricsServer for forward compatibility

type MetricsScraper

type MetricsScraper struct {
	Log           logr.Logger
	UpdatePeriod  time.Duration
	RuntimeClient *RemoteRuntimeServiceClient
	// contains filtered or unexported fields
}

MetricsScraper interface.

func (*MetricsScraper) Start

func (ms *MetricsScraper) Start(ctx context.Context)

Start scraping metrics.

type ReadinessProbeHandler

type ReadinessProbeHandler struct {
	RuntimeClient *RemoteRuntimeServiceClient
	Log           logr.Logger
	Ready         bool
}

ReadinessProbeHandler is the handler for the readiness probe requests.

func (*ReadinessProbeHandler) ServeHTTP

ServeHTTP is the handler for the ReadinessProbeHandler.

type RemoteRuntimeServiceClient

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

RemoteRuntimeServiceClient is a gRPC implementation of criapi.RuntimeServiceClient.

func GetRuntimeService

func GetRuntimeService(ctx context.Context, connectionTimeout time.Duration, runtimeEndpoint string) (*RemoteRuntimeServiceClient, error)

GetRuntimeService creates and returns a new RuntimeServiceClient.

func (*RemoteRuntimeServiceClient) ListContainerStats

ListContainerStats returns the list of ContainerStats given the filter.

func (*RemoteRuntimeServiceClient) ListContainers

func (r *RemoteRuntimeServiceClient) ListContainers(ctx context.Context, filter *criapi.ContainerFilter) ([]*criapi.Container, error)

ListContainers lists containers by filters.

func (*RemoteRuntimeServiceClient) ListPodSandbox

ListPodSandbox returns a list of PodSandboxes.

type Server

type Server struct {
	// MetricsScraperPeriod indicates the update interval for CustomMetrics update.
	MetricsScraperPeriod time.Duration
	Port                 int
	Log                  logr.Logger
	RuntimeClient        *RemoteRuntimeServiceClient
	StatsScraper         *StatsScraper

	UnimplementedInstanceMetricsServer
	// contains filtered or unexported fields
}

Server interface.

func (*Server) ContainerMetrics

func (instmetrics *Server) ContainerMetrics(ctx context.Context, in *ContainerMetricsRequest) (*ContainerMetricsResponse, error)

ContainerMetrics receives the PodName and returns a ContainerMetricsResponse with resource utilization.

func (Server) Start

func (instmetrics Server) Start(ctx context.Context) error

Start metricsScraper and RPC server.

type StatsScraper

type StatsScraper interface {
	// contains filtered or unexported methods
}

StatsScraper interface.

type UnimplementedInstanceMetricsServer

type UnimplementedInstanceMetricsServer struct {
}

UnimplementedInstanceMetricsServer must be embedded to have forward compatible implementations.

func (UnimplementedInstanceMetricsServer) ContainerMetrics

type UnsafeInstanceMetricsServer

type UnsafeInstanceMetricsServer interface {
	// contains filtered or unexported methods
}

UnsafeInstanceMetricsServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to InstanceMetricsServer will result in compilation errors.

Jump to

Keyboard shortcuts

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