unused

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

CLI tool, Prometheus exporter, and Go module to list your unused disks in all cloud providers

This repository contains a Go library to list your unused persistent disks in different cloud providers, and binaries for displaying them at the CLI or exporting Prometheus metrics.

At Grafana Labs we host our workloads in multiple cloud providers. Our workloads orchestration is managed by Kubernetes, and we've found that due to some misconfiguration in the backend storage, we used to have lots of unused resources, specially persistent disks. These leaked resources cost money, and because these are resources that are not in use anymore, it translates into wasted money. This library and its companion tools should help you out to identify these resources and clean them up.

Go module github.com/grafana/unused

This module exports some interfaces and implementations to easily list all your unsed persistent disks in GCP, AWS, and Azure. You can find the API in the Go package documentation.

Binaries

This repository also provides two binaries ready to use to interactively view unused disks (cmd/unused) or expose unused disk metrics (cmd/unused-exporter) to Prometheus. Both programs can authenticate against the following providers using the listed CLI flags:

Provider Flag Description
GCP -gcp.project ID of the GCP project
AWS -aws.profile AWS configuration profile name
Azure -azure.sub Azure subscription ID

These flags can be specified more than once, allowing to have different configurations for each provider.

Notes on authentication

Both binaries are opinionated on how to authenticate against each Cloud Service Provider (CSP).

Provider Notes
GCP Depends on default credentials
AWS Uses profile names from your credentials file
Azure Requires Azure CLI installed on the host and signed in
unused binary

TUI tool to query all given providers and list them as a neat table. It also supports an interactive mode which allows to select and delete disks in an easy way.

go install github.com/grafana/unused/cmd/unused@latest
unused-exporter Prometheus exporter

Web server exposing Prometheus metrics about each providers count of unused disks. It exposes the following metrics:

Metric Description
unused_disks_count How many unused disks are in this provider
unused_provider_duration_ms How long in milliseconds took to fetch this provider information
unused_provider_info CSP information
unused_provider_success Static metric indicating if collecting the metrics succeeded or not

All metrics have the provider and provider_id labels to identify to which provider instance they belong. The unused_disks_count metric has an additional k8s_namespace metric mapped to the kubernetes.io/created-for/pvc/namespace annotation assigned to persistent disks created by Kubernetes.

Information about each unused disk is currently logged to stdout given that it contains more changing information that could lead to cardinality explosion.

go install github.com/grafana/unused/cmd/unused-exporter@latest

Documentation

Overview

Package unsued provides the basic interfaces to obtain information and in some cases, manipulate, unused resources in different Cloud Service Providers (CSPs).

Currently only unused disks are supported.

The following providers are already implemented:

  • Google Cloud Platform (GCP)
  • Amazon Web Services (AWS)
  • Azure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByCreatedAt

func ByCreatedAt(p, q Disk) bool

ByCreatedAt sorts a Disks collection by disk creation time.

func ByName

func ByName(p, q Disk) bool

ByName sorts a Disks collection by disk name.

func ByProvider

func ByProvider(p, q Disk) bool

ByProvider sorts a Disks collection by provider name.

Types

type ByFunc

type ByFunc func(p, q Disk) bool

ByFunc is the type of sorting functions for Disks.

type Disk

type Disk interface {
	// ID should return a unique ID for a disk within each cloud
	// provider.
	ID() string

	// Provider returns a string indicating the provider this disk
	// belongs to.
	Provider() Provider

	// Name returns the disk name.
	Name() string

	// SizeGB returns the disk size in GB.
	SizeGB() int

	// CreatedAt returns the time when the disk was created.
	CreatedAt() time.Time

	// LastUsedAt returns the date when the disk was last used.
	LastUsedAt() time.Time

	// Meta returns the disk metadata.
	Meta() Meta

	// DiskType returns the normalized type of disk.
	DiskType() DiskType
}

Disk represents an unused disk on a given cloud provider.

type DiskType added in v0.0.2

type DiskType string
const (
	SSD     DiskType = "ssd"
	HDD     DiskType = "hdd"
	Unknown DiskType = "unknown"
)

type Disks

type Disks []Disk

Disks is a collection of Disk.

func (Disks) Sort

func (d Disks) Sort(by ByFunc)

Sort sorts the collection by the given function.

type Meta

type Meta map[string]string

Meta is a map of key/value pairs.

func (Meta) CreatedBy added in v0.0.3

func (m Meta) CreatedBy() string

func (Meta) CreatedForNamespace added in v0.0.3

func (m Meta) CreatedForNamespace() string

func (Meta) CreatedForPV added in v0.0.3

func (m Meta) CreatedForPV() string

func (Meta) CreatedForPVC added in v0.0.3

func (m Meta) CreatedForPVC() string

func (Meta) Equals added in v0.0.3

func (m Meta) Equals(b Meta) bool

func (Meta) Keys

func (m Meta) Keys() []string

Keys returns all the keys in the map sorted alphabetically.

func (Meta) Matches

func (m Meta) Matches(key, val string) bool

Matches returns true when the given key exists in the map with the given value.

func (Meta) String

func (m Meta) String() string

String returns a string representation of metadata.

func (Meta) Zone added in v0.0.3

func (m Meta) Zone() string

type Provider

type Provider interface {
	// Name returns the provider name.
	Name() string

	// ListUnusedDisks returns a list of unused disks for the given
	// provider.
	ListUnusedDisks(ctx context.Context) (Disks, error)

	// Meta returns the provider metadata.
	Meta() Meta

	// Delete deletes a disk from the provider.
	Delete(ctx context.Context, disk Disk) error
}

Provider represents a cloud provider.

Directories

Path Synopsis
cmd
unused
unused is a CLI tool to query the given providers for unused disks.
unused is a CLI tool to query the given providers for unused disks.
unused-exporter
unused-exporter is a Prometheus exporter with a web interface to expose unused disks as metrics.
unused-exporter is a Prometheus exporter with a web interface to expose unused disks as metrics.

Jump to

Keyboard shortcuts

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