pcfmetrics

package module
v0.0.0-...-f9a4f30 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

This is the go-metrics exporter for Pivotal Cloud Foundry (PCF) Metrics.

It is designed to work with the go-metrics library, which is a Go port of Dropwizard metrics.

1. Download and install the Go packages

go get github.com/rcrowley/go-metrics
go get github.com/pivotal-cf/go-metrics-pcf

2. Import the metrics libraries into your application

Add these import lines to your main.go:

import (
    "time"
    
    // add both of these lines to your application
    "github.com/pivotal-cf/go-metrics-pcf"
    "github.com/rcrowley/go-metrics"
)

You'll also want to include the go-metrics import in any other places where you collect metrics.

3. Start the exporter inside your application

This only needs to be called once, so find a convenient place to run this when your application starts.

func main() {
    // ... other code here
    
    // start exporting to PCF every minute
    go pcfmetrics.StartExporter(metrics.DefaultRegistry)

    // ...
}

4. Add desired instrumentation elsewhere in your code

Remember to import the github.com/rcrowley/go-metrics package everywhere you want to add this instrumentation.

    timer := metrics.GetOrRegisterTimer("sample-timer", metrics.DefaultRegistry)
    
    timer.Time(func() {
        time.Sleep(time.Second)
    })

5. Create and bind the CF Metrics service to your application

This will bind your application to the metrics service and make sure credentials are available for the metrics API.

$ cf create-service cf-metrics standard my-metrics-service

$ cf bind-service my-app my-metrics-service

$ cf restage my-app

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartExporter

func StartExporter(registry metrics.Registry, opts ...ExporterOption) func()

StartExporter starts a new exporter on the current go-routine and will never exit.

func StartExporterWithOptions

func StartExporterWithOptions(registry metrics.Registry, options *Options) func()

StartExporterWithOptions starts a new exporter with provided options on the current go-routine and will never exit.

Types

type ExporterOption

type ExporterOption func(*Options)

ExporterOption is used to configure an exporter.

func WithAppGuid

func WithAppGuid(guid string) ExporterOption

WithAppGuid sets the AppGuid.

func WithFrequency

func WithFrequency(f time.Duration) ExporterOption

WithFrequency sets the frequency. The default is a minute.

func WithInstanceId

func WithInstanceId(guid string) ExporterOption

WithInstanceId sets the instance ID. The default is read from the environment variable INSTANCE_GUID

func WithInstanceIndex

func WithInstanceIndex(index string) ExporterOption

WithInstanceIndex sets the instance index. The default is read from the environment variable INSTANCE_INDEX.

func WithServiceName

func WithServiceName(n string) ExporterOption

WithServiceName sets the ServiceName.

func WithSkipSSL

func WithSkipSSL(skip bool) ExporterOption

WithSkipSSL sets the InsecureSkipVerify flag on the HTTP transport.

func WithTimeUnit

func WithTimeUnit(u time.Duration) ExporterOption

WithTimeUnit sets the TimeUnit.

func WithToken

func WithToken(token string) ExporterOption

WithToken sets the token.

func WithURL

func WithURL(URL string) ExporterOption

WithURL sets the URL.

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Options

type Options struct {
	Frequency           time.Duration
	InstanceId          string
	InstanceIndex       string
	Token               string
	Url                 string
	AppGuid             string
	TimeUnit            time.Duration
	ServiceName         string
	SkipSSLVerification bool
}

Options is used when starting an exporter.

Directories

Path Synopsis
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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