custom-metrics-generator

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: MIT Imports: 11 Imported by: 0

README

custom-metrics-generator

custom-metrics-generator is generate prometheus metrics using custom resource definition.
You can output any metrics to http endpoints like a prometheus exporter.

Image

Official

public.ecr.aws/q1m5p9s1/custom-metrics-generator (amd64 linux only)

Build

$ IMG=<<your repository>>:<<tag>> make docker-build

Deploy CRD and controller

See manifest/deploy.

$ kustomize build manifests/deploy | kubectl apply -f -

Flags
-generate-metrics-bind-address string
    Generated metrics endpoint addr. (default ":8082")
-generate-metrics-path string
    Generated metrics path. (default "/metrics")
-interval-seconds int
    interval seconds to fetch metrics (default 60)
-metrics-prefix string
    set prefix for metrics name (default none)
-offset-seconds int
    offset seconds to generate metrics (default 0)
-timezone string
    set timezone (default "UTC")

Deploy resources

Sample is in manifest/resource.

Fields
Name Type Required Description
spec.metricsName string Yes Name of generated metrics.
spec.offsetSeconds int No Offset seconds to generate metrics (override flag setting)
spec.timezone string No Set timezone (override flag setting)
spec.labels map[string]string No Labels to be added to generated metrics.
spec.metrics.start string Yes Cron formatted schedule to start output metrics.
spec.metrics.duration duration Yes Duration to keep output metrics.
spec.metrics.value int Yes Value of output metrics.
Rules of define metrics
Naming

spec.metricsName must match the regex [a-zA-Z_:][a-zA-Z0-9_:]*.
Keys in spec.labels must match the regex [a-zA-Z_][a-zA-Z0-9_]* and cannot start with two or more _.
See also prometheus docs.

If invalid character is used, it is replaced by _.

Multiple metrics

spec.metrics field is specified as array, so you can define more than one.
If multiple metrics have overlapping schedules, new schedule metrics will be used.

metrics sample

Argo CD Custom Health Check

If you are using Argo CD, you can set argo-cd custom health check by adding below to configMap argocd-cm.
For more information, https://argo-cd.readthedocs.io/en/stable/operator-manual/health/

  resource.customizations.health.k8s.oder.com_MetricsSource: |
    hs = {}
    if obj.status ~= nil then
      if obj.status.conditions ~= nil then
        for i, condition in ipairs(obj.status.conditions) do
          if condition.type == "Ready" and condition.status == "False" then
            hs.status = "Degraded"
            hs.message = condition.message
            return hs
          end
          if condition.type == "Ready" and condition.status == "True" then
            hs.status = "Healthy"
            hs.message = condition.message
            return hs
          end
        end
      end
    end

    hs.status = "Progressing"
    hs.message = "Waiting for Reconcile"
    return hs

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1
Package v1 contains API Schema definitions for the k8s v1 API group +kubebuilder:object:generate=true +groupName=k8s.oder.com
Package v1 contains API Schema definitions for the k8s v1 API group +kubebuilder:object:generate=true +groupName=k8s.oder.com

Jump to

Keyboard shortcuts

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