Skip to content

memes/gce-metric

Repository files navigation

GCP custom metric generator

GitHub release Maintenance Contributor Covenant Go Reference Go Report Card

A synthetic metric generator for Google Cloud that will create a time-series of artificial metrics that can be consumed by an autoscaler, or other metric-bound resource. The application will automatically generate a time-series with labels appropriate for gce_instance or gke_container metrics, if detected, with fallback to generic_node metrics.

Usage

The application has three-forms of operation; generator, list, and delete.

Generator

gce-metric waveform [flags] NAME
  • waveform is one of sawtooth, sine, square, or triangle, and sets the pattern for the metrics (see images below)
  • NAME is the custom metric type to add to GCP; this name must not conflict with existing metrics provided by GCP, and convention suggests that it be of the form custom.googleapis.com/name - see GCP creating metrics docs for details.

All options have a default values which can be overridden through command line flags, environment variables, or a configuration file.

  • --floor N sets the minimum value for the cycles, can be an integer or floating point value
  • --ceiling N sets the maximum value for the cycles, can be an integer of floating point value
  • --period T sets the duration for one complete cycle from floor to ceiling, must be valid Go duration string (see time.ParseDuration)
  • --sample T sets the interval between sending metrics to Google Monitoring, must be valid Go duration string (see time.ParseDuration)
  • --verbose set the logging levels to include more details
  • --integer forces the generated metrics to be integers, making them less smooth and more step-like

NOTE: Custom metric names can be reused as long as the type of the metric doesn't change; i.e. if you created a metric with floating point values, and then try to use --integer with the same metric name it will fail.

When executed on a GCE VM, or in a container with access to GCE metadata, the project identifier (and other details) will be pulled from the metadata server. If you run the application on a non-GCP system you will need to ensure you are authenticated to GCP and authorised to create metric time-series.

  • --project ID will set (or override discovered) project ID for the metrics

Example: Sawtooth

Sawtooth metric in Metrics Explorer

gce-metric sawtooth --floor 0 --ceiling 100 --period 20m --sample 30s custom.googleapis.com/gce_metric/sawtooth

Example: Sine

Sine metric in Metrics Explorer

gce-metric sine --floor 0 --ceiling 100 --period 20m --sample 30s custom.googleapis.com/gce_metric/sine

Example: Square

Square metric in Metrics Explorer

gce-metric square --floor 0 --ceiling 100 --period 20m --sample 30s custom.googleapis.com/gce_metric/square

Example: Triangle

Triangle metric in Metrics Explorer

gce-metric triangle --floor 0 --ceiling 100 --period 20m --sample 30s custom.googleapis.com/gce_metric/triangle

List

To list custom metrics

gce-metric list [--verbose] [--project ID --filter FILTER]
  • --filter applies a metric filter to the list. If omitted, the default filter will limit the results to metrics matching custom.googleapis.com/* in the project.

Delete

To delete one or more custom metrics use

gce-metric delete [--verbose] [--project ID] NAME...

or combine with list to delete all custom metrics matching a criteria

gce-metric list [--project ID] --filter FILTER | \
   xargs gce-metric delete [--project ID]

Binaries

Binaries are published on the Releases page for Linux, macOS, and Windows. If you have Go installed locally, go install github.com/memes/gce-metric/cmd/gce-metric will download and install to $GOBIN.

A container image is also published to Docker Hub and GitHub Container Registries that can be used in place of the binary; just append the arguments to the docker run or podman run command.

E.g.

podman run -d --rm --name gce-metric \
   ghcr.io/memes/gce-metric:v1.2.3 \
   sawtooth -period 1h -sample 2m

Verifying releases

For each tagged release, an tarball of the source and a syft SBOM is created, along with SHA256 checksums for all files. cosign is used to automatically generate a signing certificate for download and verification of container images.

Verify release files

  1. Download the checksum, signature, and signing certificate file from GitHub

    curl -sLO https://github.com/memes/gce-metric/releases/download/v1.2.3/gce-metric_1.2.3_SHA256SUMS
    curl -sLO https://github.com/memes/gce-metric/releases/download/v1.2.3/gce-metric_1.2.3_SHA256SUMS.sig
    curl -sLO https://github.com/memes/gce-metric/releases/download/v1.2.3/gce-metric_1.2.3_SHA256SUMS.pem
  2. Verify the SHA256SUMS have been signed with cosign

    cosign verify-blob \
       --cert gce-metric_1.2.3_SHA256SUMS.pem \
       --signature gce-metric_1.2.3_SHA256SUMS.sig \
       gce-metric_1.2.3_SHA256SUMS
    verified OK
    
  3. Download and verify files

    Now that the checksum file has been verified, any other file can be verified using sha256sum.

    For example

    curl -sLO https://github.com/memes/gce-metric/releases/download/v1.2.3/gce-metric-1.2.3.tar.gz.sbom
    curl -sLO https://github.com/memes/gce-metric/releases/download/v1.2.3/gce-metric_1.2.3_linux_amd64
    sha256sum --ignore-missing -c gce-metric_1.2.3_SHA256SUMS
    gce-metric-1.2.3.tar.gz.sbom: OK
    gce-metric_1.2.3_linux_amd64: OK
    

Verify container image

Use cosigns experimental OCI signature support to validate the container.

COSIGN_EXPERIMENTAL=1 cosign verify ghcr.io/memes/gce-metric:v1.2.3