surfacers

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Overview

Package surfacers is the base package for creating Surfacer objects that are used for writing metics data to different monitoring services.

Any Surfacer that is created for writing metrics data to a monitor system should implement the below Surfacer interface and should accept metrics.EventMetrics object through a Write() call. Each new surfacer should also plug itself in through the New() method defined here.

Index

Constants

This section is empty.

Variables

View Source
var StatusTmpl = template.Must(template.New("statusTmpl").Parse(`
<table class="status-list">
  <tr>
    <th>Type</th>
    <th>Name</th>
    <th>Conf</th>
  </tr>
  {{ range . }}
  <tr>
    <td>{{.Type}}</td>
    <td>{{.Name}}</td>
    <td>
    {{if .Conf}}
      <pre>{{.Conf}}</pre>
    {{else}}
      default
    {{end}}
    </td>
  </tr>
  {{ end }}
</table>
`))

StatusTmpl variable stores the HTML template suitable to generate the surfacers' status for cloudprober's /status page. It expects an array of SurfacerInfo objects as input.

Functions

func Register

func Register(name string, s Surfacer)

Register allows you to register a user defined surfacer with cloudprober. Example usage:

import (
	"github.com/cloudprober/cloudprober"
	"github.com/cloudprober/cloudprober/surfacers"
)

s := &FancySurfacer{}
surfacers.Register("fancy_surfacer", s)
pr, err := cloudprober.InitFromConfig(*configFile)
if err != nil {
	log.Exitf("Error initializing cloudprober. Err: %v", err)
}

func RegisterSurfacerType added in v0.14.1

func RegisterSurfacerType(extensionFieldNo int, newSurfacerFunc surfacerFunc)

RegisterSurfacerType registers a new surfacer-type. New surfacer types are integrated with the config subsystem using the protobuf extensions.

Example usage:

import (
	"github.com/cloudprober/cloudprober"
	"github.com/cloudprober/cloudprober/surfacers"
)

surfacers.RegisterSurfacerType(200, func(conf any) (Surfacer, error) {
	fancyConf, ok := conf.(*testdatapb.FancySurfacer)
	if !ok {
		return nil, fmt.Errorf("expected *testdatapb.FancySurfacer, got %T", conf)
	}
	s, err := NewFancySurfacer(fancyConf)
	if err != nil {
		return nil, err
	}
	return s, nil
})

pr, err := cloudprober.Init()
if err != nil {
	log.Exitf("Error initializing cloudprober. Err: %v", err)
}

Types

type Surfacer

type Surfacer interface {
	// Function for writing a piece of metric data to a specified metric
	// store (or other location).
	Write(ctx context.Context, em *metrics.EventMetrics)
}

Surfacer is an interface for all metrics surfacing systems

type SurfacerInfo

type SurfacerInfo struct {
	Surfacer
	Type        string
	Name        string
	SurfacerDef *surfacerpb.SurfacerDef
	Conf        string
}

SurfacerInfo encapsulates a Surfacer and related info.

func Init

func Init(ctx context.Context, sDefs []*surfacerpb.SurfacerDef) ([]*SurfacerInfo, error)

Init initializes the surfacers from the config protobufs and returns them as a list.

Directories

Path Synopsis
Package options defines data structure for common surfacer options.
Package options defines data structure for common surfacer options.

Jump to

Keyboard shortcuts

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