Documentation
¶
Overview ¶
Copyright 2020 FairwindsOps Inc
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 FairwindsOps Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 FairwindsOps Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2020 FairwindsOps Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
const ( MetricCPU = "CPU" MetricMemory = "Memory" MetricGPU = "GPU" MetricNetworkReceive = "NetworkReceive" MetricNetworkTransmit = "NetworkTransmit" MetricStorageCapacity = "StorageCapacity" )
const TenantHeader = "X-Scope-OrgID"
TenantHeader is the HTTP header used by Grafana Mimir and other multi-tenant Prometheus-compatible backends to identify the tenant.
Variables ¶
This section is empty.
Functions ¶
func GetClient ¶
func GetClient(address, bearerToken string) (prometheusV1.API, error)
GetClient returns a Prometheus API client for a given address. This function is maintained for backward compatibility. For new features like multi-tenant support (Grafana Mimir), use GetClientWithOptions instead.
func GetClientWithOptions ¶
func GetClientWithOptions(address string, opts ...ClientOption) (prometheusV1.API, error)
GetClientWithOptions returns a Prometheus API client for a given address with configurable options. This function supports multi-tenant Prometheus backends like Grafana Mimir through the WithTenantID option.
For Mimir deployments, the address should include the full path to the Prometheus API endpoint (e.g., "https://mimir.example.com/prometheus"). The Prometheus client will automatically append /api/v1 for API calls.
Example usage:
// Standard Prometheus
client, err := GetClientWithOptions("http://prometheus:9090")
// Prometheus with bearer token
client, err := GetClientWithOptions("http://prometheus:9090",
WithBearerToken("my-token"))
// Grafana Mimir with tenant ID
client, err := GetClientWithOptions("https://mimir.example.com/prometheus",
WithTenantID("my-tenant"))
// Grafana Mimir with tenant ID and bearer token
client, err := GetClientWithOptions("https://mimir.example.com/prometheus",
WithBearerToken("my-token"),
WithTenantID("my-tenant"))
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption is a functional option for configuring the Prometheus client.
func WithBearerToken ¶
func WithBearerToken(token string) ClientOption
WithBearerToken sets the bearer token for authentication. This is equivalent to the bearerToken parameter in the original GetClient function.
func WithTenantID ¶
func WithTenantID(tenantID string) ClientOption
WithTenantID sets the tenant ID for multi-tenant Prometheus backends like Grafana Mimir. When set, the X-Scope-OrgID header will be included in all requests.
type CombinedRequest ¶
type CombinedRequest struct {
Owner
// contains filtered or unexported fields
}
CombinedRequest is the cpu/memory and requests for a given pod/container
func GetMetrics ¶
func GetMetrics(ctx context.Context, dynamicClient dynamic.Interface, restMapper meta.RESTMapper, api prometheusV1.API, clusterName string, prometheusAddress string, skipCAdvisorNonZeroMetricsValidation, skipKSMNonZeroMetricsValidation bool) ([]CombinedRequest, error)
GetMetrics returns the memory/cpu and requests for each container running in the cluster. When prometheusAddress is GMP and clusterName is set, request/limit metrics that return 0 from kube-state-metrics are retried using GKE system metrics (kubernetes.io/container/*).
type NodesMetrics ¶
type NodesMetrics struct {
IdleCPU model.SampleValue `json:"IdleCPU,omitempty" yaml:"IdleCPU,omitempty"`
IdleMemory model.SampleValue `json:"IdleMemory,omitempty" yaml:"IdleMemory,omitempty"`
OverheadCPU model.SampleValue `json:"OverheadCPU,omitempty" yaml:"OverheadCPU,omitempty"`
OverheadMemory model.SampleValue `json:"OverheadMemory,omitempty" yaml:"OverheadMemory,omitempty"`
}
func GetNodesMetrics ¶
func GetNodesMetrics(ctx context.Context, dynamicClient dynamic.Interface, restMapper meta.RESTMapper, api prometheusV1.API, clusterName string) (*NodesMetrics, error)
type Owner ¶
type Owner struct {
Container string
PodName string
ControllerNamespace string
ControllerName string
ControllerKind string
}
Owner is the information about a pod that a set of metrics belongs to.
type Statistics ¶
type Statistics struct {
Owner
StartTime time.Time
Metric string
Value int64
Request int64
LimitValue int64
}
Statistics is an aggregation of the metrics by pod/container
func CalculateStatistics ¶
func CalculateStatistics(values []CombinedRequest) []Statistics
CalculateStatistics finds the max/min/avg for a set of data points by hour