cmd

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RRDStorageStep300Secs constant defining a 5-min storage step for RRD databases
	RRDStorageStep300Secs = 300
	// RRDStorageStep3600Secs constant defining a 1-hour storage step for RRD databases
	RRDStorageStep3600Secs = 3600
)
View Source
const (
	AuthTypeUnknown     = 0
	AuthTypeBearerToken = 1
	AuthTypeX509Cert    = 2
	AuthTypeBasicToken  = 3
	KubeConfigKey       = "kubeconfig"
)
View Source
const KrossboardVersion = "1.3.0"

Variables

This section is empty.

Functions

func DiscoveryHandler

func DiscoveryHandler(w http.ResponseWriter, r *http.Request)

DiscoveryHandler returns current system status along with Kubernetes Opex Analytics instances' endpoints

func Execute

func Execute()

func GetAllClustersCurrentUsageHandler

func GetAllClustersCurrentUsageHandler(w http.ResponseWriter, r *http.Request)

GetAllClustersCurrentUsageHandler returns current usage of all clusters

func GetClustersUsageHistoryHandler

func GetClustersUsageHistoryHandler(w http.ResponseWriter, r *http.Request)

GetClustersUsageHistoryHandler returns all clusters usage history

func GetDatasetHandler

func GetDatasetHandler(w http.ResponseWriter, req *http.Request)

GetDatasetHandler provides reverse proxy to download dataset from KOA instances

func GetNodesUsageHandler

func GetNodesUsageHandler(w http.ResponseWriter, req *http.Request)

GetNodesUsageHandler returns the node usage for a cluster set in the "X-Krossboard-Cluster header

func KubeConfigHandler

func KubeConfigHandler(w http.ResponseWriter, req *http.Request)

KubeConfigHandler handles API calls to manage KUBECONFIG

func RoundTime

func RoundTime(t time.Time, resolution time.Duration) time.Time

RoundTime rounds the given time to the provided resolution.

func UserHomeDir

func UserHomeDir() string

UserHomeDir returns the current use home directory

Types

type DiscoveryResp

type DiscoveryResp struct {
	Status    string    `json:"status,omitempty"`
	Message   string    `json:"message,omitempty"`
	Instances []*KOAAPI `json:"instances,omitempty"`
}

DiscoveryResp holds the message returned by the discovery API

type ErrorResp

type ErrorResp struct {
	Status  string `json:"status,omitempty"`
	Message string `json:"message,omitempty"`
}

ErrorResp holds an error response

type GetAllClustersCurrentUsageResp

type GetAllClustersCurrentUsageResp struct {
	Status       string             `json:"status,omitempty"`
	Message      string             `json:"message,omitempty"`
	ClusterUsage []*K8sClusterUsage `json:"clusterUsage,omitempty"`
}

GetAllClustersCurrentUsageResp holds the message return edby the GetAllClustersCurrentUsageHandler API callback

type GetClusterUsageHistoryResp

type GetClusterUsageHistoryResp struct {
	Status             string                   `json:"status,omitempty"`
	Message            string                   `json:"message,omitempty"`
	ListOfUsageHistory map[string]*UsageHistory `json:"usageHistory,omitempty"`
}

GetClusterUsageHistoryResp holds the message returned by the GetClusterUsageHistoryHandler API callback

type K8sClusterUsage

type K8sClusterUsage struct {
	ClusterName       string  `json:"clusterName"`
	CPUUsed           float64 `json:"cpuUsed"`
	MemUsed           float64 `json:"memUsed"`
	CPUNonAllocatable float64 `json:"cpuNonAllocatable"`
	MemNonAllocatable float64 `json:"memNonAllocatable"`
	OutToDate         bool    `json:"outToDate"`
}

K8sClusterUsage holds used and non-allocatable memory and CPU resource of a K8s cluster

type KOAAPI

type KOAAPI struct {
	ClusterName string `json:"clusterName,omitempty"`
	Endpoint    string `json:"endpoint,omitempty"`
}

KOAAPI describes an instance Kubernetes Opex Analytics's API

type KbInstancesK8sList

type KbInstancesK8sList struct {
	Items []struct {
		Status struct {
			KoaInstances []KoaInstance `json:"koaInstances,omitempty"`
		} `json:"status,omitempty"`
	} `json:"items,omitempty"`
}

KbInstancesK8sList holds a list of Krossboard instances as returned by Kubernetes

func GetKrossboardInstances

func GetKrossboardInstances() (*KbInstancesK8sList, error)

GetKrossboardInstances queries Krossboard instanes from Kubernetes API

type KoaInstance

type KoaInstance struct {
	Name               string `json:"name,omitempty"`
	Image              string `json:"image,omitempty"`
	ContainerPort      int64  `json:"containerPort,omitempty"`
	ClusterName        string `json:"clusterName,omitempty"`
	ClusterEndpointURL string `json:"clusterEndpoint,omitempty"`
}

KoaInstance defines a desired state of a kube-opex-analytics instance

type KubeConfig

type KubeConfig struct {
	Paths []string `json:"path,omitempty"`
}

KubeConfig holds an object describing a K8s Cluster

func NewKubeConfig

func NewKubeConfig() *KubeConfig

NewKubeConfig creates a new KubeConfig object

func NewKubeConfigFrom

func NewKubeConfigFrom(path string) *KubeConfig

NewKubeConfig creates a new KubeConfig from a given file path

func (*KubeConfig) GetAccessToken

func (m *KubeConfig) GetAccessToken(authInfo *kapi.AuthInfo) (string, error)

GetAccessToken retrieves access token from AuthInfo

func (*KubeConfig) ListClusters

func (m *KubeConfig) ListClusters() map[string]*ManagedCluster

ListClusters lists Kubernetes clusters available in KUBECONFIG

type ManagedCluster

type ManagedCluster struct {
	Name        string         `json:"name,omitempty"`
	APIEndpoint string         `json:"apiEndpoint,omitempty"`
	AuthInfo    *kapi.AuthInfo `json:"authInfo,omitempty"`
	CaData      []byte         `json:"cacert,omitempty"`
	AuthType    int            `json:"authType,omitempty"`
}

ManagedCluster holds an object describing managed clusters

type NodeUsage

type NodeUsage struct {
	DateUTC        time.Time `json:"dateUTC,omitempty"`
	Name           string    `json:"name,omitempty"`
	CPUCapacity    float64   `json:"cpuCapacity,omitempty"`
	CPUAllocatable float64   `json:"cpuAllocatable,omitempty"`
	CPUUsageByPods float64   `json:"cpuUsageByPods,omitempty"`
	MEMCapacity    float64   `json:"memCapacity,omitempty"`
	MEMAllocatable float64   `json:"memAllocatable,omitempty"`
	MEMUsageByPods float64   `json:"memUsageByPods,omitempty"`
	PodsUsage      []*struct {
		CPUUsage float64 `json:"cpuUsage,omitempty"`
		MEMUsage float64 `json:"memUsage,omitempty"`
	} `json:"podsRunning,omitempty"`
}

NodeUsage holds an instance of node usage as processed by kube-opex-analytics

type NodeUsageDb

type NodeUsageDb struct {
	AllocatableDb *UsageDb
	CapacityDb    *UsageDb
	UsageByPodsDb *UsageDb
}

func NewNodeUsageDB

func NewNodeUsageDB(nodeName string) *NodeUsageDb

type ResourceUsageItem

type ResourceUsageItem struct {
	DateUTC time.Time `json:"dateUTC"`
	Value   float64   `json:"value"`
}

ResourceUsageItem holds a resource usage at a timestamp

type UsageDb

type UsageDb struct {
	RRDFile  string
	Step     uint
	MinValue float64
	MaxValue float64
	Xfs      float64
}

UsageDb holds a wrapper on a RRD database file along with appropriated settinfgs to store a usage data

func NewUsageDb

func NewUsageDb(dbname string, maxValue float64) *UsageDb

NewUsageDb instanciate a new UsageDb object wrapper

func (*UsageDb) CreateRRD

func (m *UsageDb) CreateRRD() error

CreateRRD create a new RRD database

func (*UsageDb) FetchUsage

func (m *UsageDb) FetchUsage(startTimeUTC time.Time, endTimeUTC time.Time, step time.Duration) (*UsageHistory, error)

FetchUsage retrieves from the given RRD file data between startTimeUTC and endTimeUTC and a step

func (*UsageDb) FetchUsage5Minutes

func (m *UsageDb) FetchUsage5Minutes(startTimeUTC time.Time, endTimeUTC time.Time) (*UsageHistory, error)

FetchUsageHourly retrieves from the managed RRD file, 5 minutes-step usage data between startTimeUTC and endTimeUTC

func (*UsageDb) FetchUsageHourly

func (m *UsageDb) FetchUsageHourly(startTimeUTC time.Time, endTimeUTC time.Time) (*UsageHistory, error)

FetchUsageHourly retrieves from the managed RRD file, hour-step usage data between startTimeUTC and endTimeUTC

func (*UsageDb) FetchUsageMonthly

func (m *UsageDb) FetchUsageMonthly(startTimeUTC time.Time, endTimeUTC time.Time) (*UsageHistory, error)

FetchUsageMonthly retrieves from the managed RRD file, month-step usage data between startTimeUTC and endTimeUTC

func (*UsageDb) UpdateRRD

func (m *UsageDb) UpdateRRD(ts time.Time, cpuUsage float64, memUsage float64) error

UpdateRRD adds a new entry into a RRD database

type UsageHistory

type UsageHistory struct {
	CPUUsage []*ResourceUsageItem `json:"cpuUsage"`
	MEMUsage []*ResourceUsageItem `json:"memUsage"`
}

UsageHistory holds resource usage history for all kinds of managed resources (CPU, memory)

Jump to

Keyboard shortcuts

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