digitaloceanexporter

package module
v0.0.0-...-3c1487e Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 10 Imported by: 0

README ¶

digitalocean_exporter

🚀 a Prometheus exporter for DigitalOcean resources 🚀

https://github.com/coding-to-music/digitalocean_exporter

From / By Andrew Starr-Bochicchio https://github.com/andrewsomething

https://github.com/andrewsomething/digitalocean_exporter

Environment variables:


GitHub

git init
git add .
git remote remove origin
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:coding-to-music/digitalocean_exporter.git
git push -u origin main

digitalocean_exporter

Build Status Go Report Card Docker Build Status

digitalocean_exporter is a Prometheus exporter for DigitalOcean resources.

Initially written as a way to explore Prometheus exporters, I am sharing it in the hope that it will be useful to others. Matt Layher's rtorrent_exporter was a great help.

You may want to consider using github.com/metalmatze/digitalocean_exporter. It is a more active project than this one.

Usage

digitalocean_exporter has a number of runtime options that can be set using flags including the listen addresss and the path for the metrics end point. A DigitalOcean API token is also required. It is recommended to use a read-only token as digitalocean_exporter has no need for write access to your account.

As calls to the DigitalOcean API can be expensive, digitalocean_exporter maintains a local cache that is periodically refreshed based on the refresh-interval value provided. The default is every 60 seconds.

$ ./digitalocean_exporter -help
Usage of ./digitalocean_exporter:
  -debug
        Print debug logs
  -listen string
        Listen address for DigitalOcean exporter (default "localhost:9292")
  -metrics-path string
        URL path for surfacing metrics (default "/metrics")
  -refresh-interval int
        Interval (in seconds) between subsequent requests against DigitalOcean API (default 60)
  -token string
        DigitalOcean API token (read-only)
  -v    Prints current digitalocean_exporter version
Docker

This exporter is also available as a Docker image: andrewsomething/digitalocean_exporter

Example usage:

$ docker run -p 127.0.0.1:9292:9292 andrewsomething/digitalocean_exporter \
    -listen 0.0.0.0:9292 -token $DIGITALOCEAN_API_TOKEN

Metrics

Here is an example of the metrics exposed by digitalocean_exporter:

$ curl --silent localhost:9292/metrics | grep digitalocean
# HELP digitalocean_droplets_count Number of Droplets by region, size, and status.
# TYPE digitalocean_droplets_count gauge
digitalocean_droplets_count{region="lon1",size="1gb",status="active"} 1
digitalocean_droplets_count{region="nyc2",size="1gb",status="active"} 1
digitalocean_droplets_count{region="nyc2",size="2gb",status="active"} 3
digitalocean_droplets_count{region="nyc3",size="16gb",status="active"} 1
digitalocean_droplets_count{region="nyc3",size="1gb",status="active"} 1
digitalocean_droplets_count{region="nyc3",size="1gb",status="off"} 1
digitalocean_droplets_count{region="nyc3",size="4gb",status="active"} 1
digitalocean_droplets_count{region="nyc3",size="512mb",status="active"} 6
digitalocean_droplets_count{region="nyc3",size="512mb",status="off"} 1
# HELP digitalocean_floating_ips_count Number of Floating IPs by region and status.
# TYPE digitalocean_floating_ips_count gauge
digitalocean_floating_ips_count{region="nyc3",status="assigned"} 1
digitalocean_floating_ips_count{region="nyc3",status="unassigned"} 1
# HELP digitalocean_load_balancers_count Number of Load Balancers by region and status.
# TYPE digitalocean_load_balancers_count gauge
digitalocean_load_balancers_count{region="nyc3",status="active"} 1
# HELP digitalocean_query_duration_seconds Time elapsed while querying the DigitalOcean API in seconds.
# TYPE digitalocean_query_duration_seconds gauge
digitalocean_query_duration_seconds 4.806081399
# HELP digitalocean_tags_count Count of tagged resources by name and resource type.
# TYPE digitalocean_tags_count gauge
digitalocean_tags_count{name="frontend",resource_type="droplets"} 0
digitalocean_tags_count{name="production",resource_type="droplets"} 7
digitalocean_tags_count{name="prometheus",resource_type="droplets"} 1
digitalocean_tags_count{name="swarm",resource_type="droplets"} 2
# HELP digitalocean_volumes_count Number of Volumes by region, size in GiB, and status.
# TYPE digitalocean_volumes_count gauge
digitalocean_volumes_count{region="fra1",size="100",status="unattached"} 1
digitalocean_volumes_count{region="nyc1",size="100",status="attached"} 1

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	DefaultRefreshInterval int = 60
)

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type DigitalOceanBuffer ¶

type DigitalOceanBuffer struct {
	Droplets      map[DropletCounter]int
	FloatingIPs   map[FlipCounter]int
	LoadBalancers map[LoadBalancerCounter]int
	Tags          map[TagCounter]int
	Volumes       map[VolumeCounter]int

	QueryDuration time.Duration
	// contains filtered or unexported fields
}

func NewDigitalOceanBuffer ¶

func NewDigitalOceanBuffer(client *godo.Client, refreshInterval int) *DigitalOceanBuffer

type DigitalOceanCollector ¶

type DigitalOceanCollector struct {
	Droplets      *prometheus.Desc
	FloatingIPs   *prometheus.Desc
	LoadBalancers *prometheus.Desc
	Tags          *prometheus.Desc
	Volumes       *prometheus.Desc

	QueryDuration *prometheus.Desc
	// contains filtered or unexported fields
}

A DigitalOceanCollector is a Prometheus collector for metrics regarding DigitalOcean.

func NewDigitalOceanCollector ¶

func NewDigitalOceanCollector(dos DigitalOceanSource) *DigitalOceanCollector

NewDigitalOceanCollector creates a new DigitalOceanCollector which collects metrics about resources in a DigitalOcean account.

func (*DigitalOceanCollector) Collect ¶

func (c *DigitalOceanCollector) Collect(ch chan<- prometheus.Metric)

Collect sends the metric values for each metric pertaining to the DigitalOcean resources to the provided prometheus Metric channel.

func (*DigitalOceanCollector) Describe ¶

func (c *DigitalOceanCollector) Describe(ch chan<- *prometheus.Desc)

Describe sends the descriptors of each metric over to the provided channel. The corresponding metric values are sent separately.

type DigitalOceanService ¶

type DigitalOceanService struct {
	Buffer *DigitalOceanBuffer
}

DigitalOceanService is a wrapper around godo.Client.

func NewDigitalOceanService ¶

func NewDigitalOceanService(buffer *DigitalOceanBuffer) *DigitalOceanService

func (*DigitalOceanService) Droplets ¶

func (s *DigitalOceanService) Droplets() map[DropletCounter]int

Droplets retrieves a count of Droplets grouped by status, size, and region.

func (*DigitalOceanService) FloatingIPs ¶

func (s *DigitalOceanService) FloatingIPs() map[FlipCounter]int

FloatingIPs retrieves a count of Floating IPs grouped by status and region.

func (*DigitalOceanService) LoadBalancers ¶

func (s *DigitalOceanService) LoadBalancers() map[LoadBalancerCounter]int

LoadBalancers retrieves a count of Load Balancers grouped by status and region.

func (*DigitalOceanService) QueryDuration ¶

func (s *DigitalOceanService) QueryDuration() time.Duration

QueryDuration reports the time elapsed while querying the DigitalOcean API.

func (*DigitalOceanService) Tags ¶

func (s *DigitalOceanService) Tags() map[TagCounter]int

Tags retrieves a count of Tags grouped by name and resource type.

func (*DigitalOceanService) Volumes ¶

func (s *DigitalOceanService) Volumes() map[VolumeCounter]int

Volumes retrieves a count of Volumes grouped by status, size, and region.

type DigitalOceanSource ¶

type DigitalOceanSource interface {
	Droplets() map[DropletCounter]int
	FloatingIPs() map[FlipCounter]int
	LoadBalancers() map[LoadBalancerCounter]int
	Tags() map[TagCounter]int
	Volumes() map[VolumeCounter]int

	QueryDuration() time.Duration
}

A DigitalOceanSource is an interface which can retrieve information about a resources in a DigitalOcean account. It is implemented by *digitaloceanexporter.DigitalOceanService.

type DropletCounter ¶

type DropletCounter struct {
	// contains filtered or unexported fields
}

DropletCounter is a struct holding information about a Droplet.

type Exporter ¶

type Exporter struct {
	// contains filtered or unexported fields
}

An Exporter is a Prometheus exporter for DigitalOcean metrics. It wraps all DigitalOcean metrics collectors and provides a single global exporter which can serve metrics. It also ensures that the collection is done in a thread-safe manner, the necessary requirement stated by Prometheus. It implements the prometheus.Collector interface in order to register with Prometheus.

func New ¶

New creates a new Exporter which collects metrics from one or mote sites.

func (*Exporter) Collect ¶

func (c *Exporter) Collect(ch chan<- prometheus.Metric)

Collect sends the collected metrics from each of the collectors to prometheus. Collect could be called several times concurrently and thus its run is protected by a single mutex.

func (*Exporter) Describe ¶

func (c *Exporter) Describe(ch chan<- *prometheus.Desc)

Describe sends all the descriptors of the collectors included to the provided channel.

type FlipCounter ¶

type FlipCounter struct {
	// contains filtered or unexported fields
}

FlipCounter is a struct holding information about a Floating IP.

type LoadBalancerCounter ¶

type LoadBalancerCounter struct {
	// contains filtered or unexported fields
}

LoadBalancerCounter is a struct holding information about a Load Balancer.

type TagCounter ¶

type TagCounter struct {
	// contains filtered or unexported fields
}

TagCounter is a struct holding information about a Tag.

type VolumeCounter ¶

type VolumeCounter struct {
	// contains filtered or unexported fields
}

VolumeCounter is a struct holding information about a Block Storage Volume.

Directories ¶

Path Synopsis
cmd
digitalocean_exporter
Command digitalocean_exporter provides a Prometheus exporter for DigitalOcean.
Command digitalocean_exporter provides a Prometheus exporter for DigitalOcean.

Jump to

Keyboard shortcuts

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