promutils

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PromQCpuClust           = `sum(rate(container_cpu_usage_seconds_total{id="/"}[1m]))/sum(machine_cpu_cores)*100`
	PromQMemClust           = `sum(container_memory_working_set_bytes{id="/"})/sum(machine_memory_bytes)*100`
	PromQDiskClust          = `` /* 145-byte string literal not displayed */
	PromQSentBytesRateClust = `sum(irate(container_network_transmit_bytes_total[1m]))`
	PromQRecvBytesRateClust = `sum(irate(container_network_receive_bytes_total[1m]))`
	PromQTcpConnClust       = "node_netstat_Tcp_CurrEstab"
	PromQTcpRetransClust    = "node_netstat_Tcp_RetransSegs"
	PromQUdpSentPktsClust   = "node_netstat_Udp_OutDatagrams"
	PromQUdpRecvPktsClust   = "node_netstat_Udp_InDatagrams"
	PromQUdpRecvErr         = "node_netstat_Udp_InErrors"

	PromQCloudletCpuTotal  = "sum(machine_cpu_cores)"
	PromQCloudletMemUse    = `sum(container_memory_working_set_bytes{id="/"})`
	PromQCloudletMemTotal  = "sum(machine_memory_bytes)"
	PromQCloudletDiskUse   = `sum(container_fs_usage_bytes{device=~"^/dev/[sv]d[a-z][1-9]$",id="/"})`
	PromQCloudletDiskTotal = `sum(container_fs_limit_bytes{device=~"^/dev/[sv]d[a-z][1-9]$",id="/"})`

	// This is a template which takes a pod query and adds instance label to it
	PromQAppLabelsWrapperFmt = "" /* 209-byte string literal not displayed */

	PromQCpuPod         = `` /* 126-byte string literal not displayed */
	PromQMemPod         = `sum(container_memory_working_set_bytes{image!=""})by(pod)`
	PromQMemPercentPod  = `sum(container_memory_working_set_bytes{image!=""})by(pod) / ignoring (pod) group_left sum( machine_memory_bytes{}) * 100`
	PromQDiskPod        = `sum(container_fs_usage_bytes{image!=""})by(pod)`
	PromQDiskPercentPod = `` /* 150-byte string literal not displayed */
	PromQNetRecvRate    = `sum(irate(container_network_receive_bytes_total{image!=""}[1m]))by(pod)`
	PromQNetSentRate    = `sum(irate(container_network_transmit_bytes_total{image!=""}[1m]))by(pod)`

	PromQAutoScaleCpuTotalU = "stabilized_max_total_worker_node_cpu_utilisation"
	PromQAutoScaleMemTotalU = "stabilized_max_total_worker_node_mem_utilisation"

	PromQConnections = "envoy_cluster_upstream_cx_active"
)

Variables

View Source
var (
	PromQCpuClustUrlEncoded           = url.QueryEscape(PromQCpuClust)
	PromQMemClustUrlEncoded           = url.QueryEscape(PromQMemClust)
	PromQDiskClustUrlEncoded          = url.QueryEscape(PromQDiskClust)
	PromQSentBytesRateClustUrlEncoded = url.QueryEscape(PromQSentBytesRateClust)
	PromQRecvBytesRateClustUrlEncoded = url.QueryEscape(PromQRecvBytesRateClust)
	PromQTcpConnClustUrlEncoded       = url.QueryEscape(PromQTcpConnClust)
	PromQTcpRetransClustUrlEncoded    = url.QueryEscape(PromQTcpRetransClust)
	PromQUdpSentPktsClustUrlEncoded   = url.QueryEscape(PromQUdpSentPktsClust)
	PromQUdpRecvPktsClustUrlEncoded   = url.QueryEscape(PromQUdpRecvPktsClust)
	PromQUdpRecvErrUrlEncoded         = url.QueryEscape(PromQUdpRecvErr)

	// For bare metal k8s CloudletMetrics
	PromQCloudletCpuTotalEncoded  = url.QueryEscape(PromQCloudletCpuTotal)
	PromQCloudletMemUseEncoded    = url.QueryEscape(PromQCloudletMemUse)
	PromQCloudletMemTotalEncoded  = url.QueryEscape(PromQCloudletMemTotal)
	PromQCloudletDiskUseEncoded   = url.QueryEscape(PromQCloudletDiskUse)
	PromQCloudletDiskTotalEncoded = url.QueryEscape(PromQCloudletDiskTotal)

	// For Pod metrics we need to join them with k8s pod labels
	PromQCpuPodUrlEncoded         = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQCpuPod))
	PromQMemPodUrlEncoded         = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQMemPod))
	PromQMemPercentPodUrlEncoded  = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQMemPercentPod))
	PromQDiskPodUrlEncoded        = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQDiskPod))
	PromQDiskPercentPodUrlEncoded = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQDiskPercentPod))
	PromQNetRecvRateUrlEncoded    = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQNetRecvRate))
	PromQNetSentRateUrlEncoded    = url.QueryEscape(GetPromQueryWithK8sLabels(PromLabelsAllMobiledgeXApps, PromQNetSentRate))

	PromQAutoScaleCpuTotalUUrlEncoded = url.QueryEscape(PromQAutoScaleCpuTotalU)
	PromQAutoScaleMemTotalUUrlEncoded = url.QueryEscape(PromQAutoScaleMemTotalU)
)

Url-encoded strings, so we don't have to encode them every time

View Source
var ClusterPrometheusAppInstLabel = "label_" + cloudcommon.MexAppInstNameLabel
View Source
var ClusterPrometheusAppInstOrgLabel = "label_" + cloudcommon.MexAppInstOrgLabel
View Source
var ClusterPrometheusAppLabel = "label_" + cloudcommon.MexAppNameLabel
View Source
var ClusterPrometheusAppVersionLabel = "label_" + cloudcommon.MexAppVersionLabel
View Source
var PromLabelsAllMobiledgeXApps = `{` + ClusterPrometheusAppLabel + `!=""}`

Going forward, this should use ClusterPrometheusAppInstLabel, but for backwards compatibility we leave it as AppLabel.

Functions

func GetPromQueryWithK8sLabels

func GetPromQueryWithK8sLabels(labelFilter, podQuery string) string

Returns a prometheus pod-based query joined with k8s labels series Function also takes an optional label filter string of form "{label1="val1",label2="val2",..}"

func ParseTime

func ParseTime(timeFloat float64) *types.Timestamp

Takes a float64 representation of a time(in sec) given to use by prometheus and turns it into a type.Timestamp format for writing into influxDB

Types

type PromAlert

type PromAlert struct {
	Labels      map[string]string
	Annotations map[string]string
	State       string
	ActiveAt    *time.Time `json:"activeAt,omitempty"`
	Value       PromAlertValue
}

type PromAlertValue

type PromAlertValue float64

Prometheus Alert Value may be a string or a numeric, depending on the version of the prometheus operator used. Handle either.

func (PromAlertValue) MarshalJSON

func (s PromAlertValue) MarshalJSON() ([]byte, error)

func (*PromAlertValue) UnmarshalJSON

func (s *PromAlertValue) UnmarshalJSON(b []byte) error

type PromData

type PromData struct {
	ResType string       `json:"resultType,omitempty"`
	Result  []PromMetric `json:"result,omitempty"`
}

type PromLabels

type PromLabels struct {
	PodName     string `json:"pod,omitempty"`
	AppName     string `json:"label_mexAppName,omitempty"`
	AppVersion  string `json:"label_mexAppVersion,omitempty"`
	AppInstName string `json:"label_mexAppInstName,omitempty"`
	AppInstOrg  string `json:"label_mexAppInstOrg,omitempty"`
}

type PromMetric

type PromMetric struct {
	Labels PromLabels    `json:"metric,omitempty"`
	Values []interface{} `json:"value,omitempty"`
}

type PromResp

type PromResp struct {
	Status string   `json:"status,omitempty"`
	Data   PromData `json:"data,omitempty"`
}

func GetPromMetrics

func GetPromMetrics(ctx context.Context, addr string, query string, client ssh.Client) (*PromResp, error)

Jump to

Keyboard shortcuts

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