metrics

package
v1.3.0-rc.0...-d217119 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SELECT host_ip::tag, mem_used::field FROM host_summary WHERE cluster_name::tag=$cluster_name
	// usage rate , distribution rate , usage percent of distribution
	//NodeCpuUsageSelectStatement    = `SELECT last(cpu_cores_usage::field) FROM host_summary WHERE cluster_name::tag=$cluster_name AND host_ip::tag=$host_ip `
	NodeResourceUsageSelectStatement = `` /* 187-byte string literal not displayed */
	//NodeResourceUsageSelectStatement = `SELECT  mem_usage::field  ,cpu_cores_usage::field, host_ip FROM host_summary WHERE cluster_name::tag=$cluster_name GROUP BY host_ip::tag`
	//PodCpuUsageSelectStatement     = `SELECT SUM(cpu_allocation::field) * 100 / SUM(cpu_limit::field) as cpuRate, pod_name FROM docker_container_summary WHERE pod_namespace::tag=$pod_namespace and podsandbox != true GROUP BY pod_name::tag`
	PodResourceUsageSelectStatement = `` /* 359-byte string literal not displayed */

	DiskResourceUsageSelectStatement = `` /* 138-byte string literal not displayed */

	Memory  = "memory"
	Cpu     = "cpu"
	Disk    = "disk"
	NodeAll = "nodeall" // cpu + disk + memory

	Pod  = "pod"
	Node = "node"
)

Variables

View Source
var (
	ResourceNotSupport = errors.New("resource type not support")
	QueryTimeoutError  = errors.New("metrics query timeout")
	ParameterNotFound  = errors.New("parameter required")
)

Functions

func GenerateNodeAllKey

func GenerateNodeAllKey(cluster string) string

func GenerateNodeallAllKey

func GenerateNodeallAllKey(orgName string) string

func GeneratePodAllKey

func GeneratePodAllKey(cluster string) string

func GetAllCache

func GetAllCache(key string) map[string]*MetricsData

func SetCache

func SetCache(k string, d interface{})

Types

type Basic

type Basic interface {
	OrgName() string
	ResourceType() string
	ResourceKind() string
	ClusterName() string
}

type Interface

type Interface interface {
	NodeMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)
	PodMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)
	NodeAllMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)
}

type Key

type Key interface {
	CacheKey() string
}

type Metric

type Metric struct {
	Metricq pb.MetricServiceServer
	// contains filtered or unexported fields
}

func New

func New(metricq pb.MetricServiceServer, ctx context.Context) *Metric

func (*Metric) NodeAllMetrics

func (m *Metric) NodeAllMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)

func (*Metric) NodeMetrics

func (m *Metric) NodeMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)

NodeMetrics query cpu and memory metrics from es database, return immediately if cache hit.

func (*Metric) PodMetrics

func (m *Metric) PodMetrics(ctx context.Context, req *MetricsRequest) (map[string]*MetricsData, error)

func (*Metric) Store

func (m *Metric) Store(response *pb.QueryWithInfluxFormatResponse, metricsRequest *MetricsReq) map[string]*MetricsData

func (*Metric) ToInfluxReq

func (m *Metric) ToInfluxReq(request *MetricsRequest, reqKind string) ([]*MetricsReq, map[string]*MetricsData, error)

type MetricsAllRequest

type MetricsAllRequest struct {
	*MetricsRequest
}

func (*MetricsAllRequest) CacheKey

func (m *MetricsAllRequest) CacheKey() string

func (*MetricsAllRequest) ClusterName

func (m *MetricsAllRequest) ClusterName() string

func (*MetricsAllRequest) IP

func (m *MetricsAllRequest) IP() string

func (*MetricsAllRequest) Namespace

func (m *MetricsAllRequest) Namespace() string

func (*MetricsAllRequest) OrgName

func (m *MetricsAllRequest) OrgName() string

func (*MetricsAllRequest) PodName

func (m *MetricsAllRequest) PodName() string

func (*MetricsAllRequest) ResourceKind

func (m *MetricsAllRequest) ResourceKind() string

func (*MetricsAllRequest) ResourceType

func (m *MetricsAllRequest) ResourceType() string

func (*MetricsAllRequest) UserID

func (m *MetricsAllRequest) UserID() string

type MetricsData

type MetricsData struct {
	// if qurey pod resource, used means usedPercent. request and total are useless.
	Used       float64 `json:"used"`
	Unallocate float64 `json:"unallocate"`
	Left       float64 `json:"left"`
}

func GetCache

func GetCache(key string) *MetricsData

type MetricsNodeRequest

type MetricsNodeRequest struct {
	*MetricsRequest
	Ip string
}

func (*MetricsNodeRequest) CacheKey

func (m *MetricsNodeRequest) CacheKey() string

func (*MetricsNodeRequest) ClusterName

func (m *MetricsNodeRequest) ClusterName() string

func (*MetricsNodeRequest) IP

func (m *MetricsNodeRequest) IP() string

func (*MetricsNodeRequest) Namespace

func (m *MetricsNodeRequest) Namespace() string

func (*MetricsNodeRequest) OrgName

func (m *MetricsNodeRequest) OrgName() string

func (*MetricsNodeRequest) PodName

func (m *MetricsNodeRequest) PodName() string

func (*MetricsNodeRequest) ResourceKind

func (m *MetricsNodeRequest) ResourceKind() string

func (*MetricsNodeRequest) ResourceType

func (m *MetricsNodeRequest) ResourceType() string

func (*MetricsNodeRequest) UserID

func (m *MetricsNodeRequest) UserID() string

type MetricsPodRequest

type MetricsPodRequest struct {
	*MetricsRequest
	Name         string
	PodNamespace string
}

func (MetricsPodRequest) CacheKey

func (m MetricsPodRequest) CacheKey() string

func (*MetricsPodRequest) ClusterName

func (m *MetricsPodRequest) ClusterName() string

func (MetricsPodRequest) IP

func (m MetricsPodRequest) IP() string

func (*MetricsPodRequest) Namespace

func (m *MetricsPodRequest) Namespace() string

func (*MetricsPodRequest) PodName

func (m *MetricsPodRequest) PodName() string

func (*MetricsPodRequest) ResourceKind

func (m *MetricsPodRequest) ResourceKind() string

func (*MetricsPodRequest) ResourceType

func (m *MetricsPodRequest) ResourceType() string

type MetricsReq

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

type MetricsReqInterface

type MetricsReqInterface interface {
	Key
	PodMetrics
	NodeMetrics
}

type MetricsRequest

type MetricsRequest struct {
	UserId           string
	OrgId            string
	OrganizationName string
	Cluster          string
	Type             string
	Kind             string
	PodRequests      []MetricsReqInterface
	NodeRequests     []MetricsReqInterface
	AllRequests      []MetricsReqInterface
}

func (MetricsRequest) ClusterName

func (m MetricsRequest) ClusterName() string

func (MetricsRequest) OrgName

func (m MetricsRequest) OrgName() string

func (MetricsRequest) ResourceKind

func (m MetricsRequest) ResourceKind() string

func (MetricsRequest) ResourceType

func (m MetricsRequest) ResourceType() string

func (MetricsRequest) UserID

func (m MetricsRequest) UserID() string

type NodeMetrics

type NodeMetrics interface {
	Basic
	IP() string
}

type PodMetrics

type PodMetrics interface {
	Basic
	PodName() string
	Namespace() string
}

type ResourceType

type ResourceType string

Jump to

Keyboard shortcuts

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