cc-metric-collector/sinks
Thomas Gruber d98076c792
Merge current development version into main (#48)
* DiskstatCollector: cast part_max_used metric to int

* Add uint types to GangliaSink and LibgangliaSink

* Use new sink instances to allow multiple of same sink type

* Update sink README and SampleSink

* Use new receiver instances to allow multiple of same receiver type

* Fix metric scope in likwid configuration script

* Mention likwid config script in LikwidCollector README

* Refactor: Embed Init() into New() function

* Refactor: Embed Init() into New() function

* Fix: MetricReceiver uses uninitialized values, when initialization fails

* Use Ganglia configuration (#44)

* Copy all metric configurations from original Ganglia code

* Use metric configurations from Ganglia for some metrics

* Format value string also for known metrics

* Numa-aware memstat collector (#45)

* Add samples for collectors, sinks and receivers

* Ping InfluxDB server after connecting to recognize faulty connections

* Add sink for Prometheus monitoring system (#46)

* Add sink for Prometheus monitoring system

* Add prometheus sink to README

* Add scraper for Prometheus clients (#47)

Co-authored-by: Holger Obermaier <holgerob@gmx.de>
Co-authored-by: Holger Obermaier <40787752+ho-ob@users.noreply.github.com>
2022-02-25 14:49:49 +01:00
..
gangliaCommon.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
gangliaSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
gangliaSink.md Sink specific configuration maps (#25) 2022-02-04 18:12:24 +01:00
httpSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
httpSink.md Automatically flush batched writes in the HTTP sink (#31) 2022-02-10 13:12:32 +01:00
influxAsyncSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
influxAsyncSink.md Add non-blocking InfluxDB sink (#29) 2022-02-07 16:51:46 +01:00
influxSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
influxSink.md Add non-blocking InfluxDB sink (#29) 2022-02-07 16:51:46 +01:00
libgangliaSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
libgangliaSink.md Ganglia sink using libganglia.so directly (#35) 2022-02-16 18:33:46 +01:00
metricSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
natsSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
natsSink.md Sink specific configuration maps (#25) 2022-02-04 18:12:24 +01:00
prometheusSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
prometheusSink.md Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
README.md Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
sampleSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
sinkManager.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
stdoutSink.go Merge current development version into main (#48) 2022-02-25 14:49:49 +01:00
stdoutSink.md Sink specific configuration maps (#25) 2022-02-04 18:12:24 +01:00

CCMetric sinks

This folder contains the SinkManager and sink implementations for the cc-metric-collector.

Available sinks:

Configuration

The configuration file for the sinks is a list of configurations. The type field in each specifies which sink to initialize.

[
  "mystdout" : {
    "type" : "stdout",
    "meta_as_tags" : false
  },
  "metricstore" : {
    "type" : "http",
    "host" : "localhost",
    "port" : "4123",
    "database" : "ccmetric",
    "password" : "<jwt token>"
  }
]

Contributing own sinks

A sink contains five functions and is derived from the type sink:

  • Init(name string, config json.RawMessage) error
  • Write(point CCMetric) error
  • Flush() error
  • Close()
  • New<Typename>(name string, config json.RawMessage) (Sink, error) (calls the Init() function)

The data structures should be set up in Init() like opening a file or server connection. The Write() function writes/sends the data. For non-blocking sinks, the Flush() method tells the sink to drain its internal buffers. The Close() function should tear down anything created in Init().

Finally, the sink needs to be registered in the sinkManager.go. There is a list of sinks called AvailableSinks which is a map (sink_type_string -> pointer to sink interface). Add a new entry with a descriptive name and the new sink.

Sample sink

package sinks

import (
	"encoding/json"
	"log"
	lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
)

type SampleSinkConfig struct {
	defaultSinkConfig  // defines JSON tags for 'name' and 'meta_as_tags'
}

type SampleSink struct {
	sink              // declarate 'name' and 'meta_as_tags'
	config StdoutSinkConfig // entry point to the SampleSinkConfig
}

// Initialize the sink by giving it a name and reading in the config JSON
func (s *SampleSink) Init(name string, config json.RawMessage) error {
	s.name = fmt.Sprintf("SampleSink(%s)", name)   // Always specify a name here
  // Read in the config JSON
	if len(config) > 0 {
		err := json.Unmarshal(config, &s.config)
		if err != nil {
			return err
		}
	}
	return nil
}

// Code to submit a single CCMetric to the sink
func (s *SampleSink) Write(point lp.CCMetric) error {
	log.Print(point)
	return nil
}

// If the sink uses batched sends internally, you can tell to flush its buffers
func (s *SampleSink) Flush() error {
	return nil
}


// Close sink: close network connection, close files, close libraries, ...
func (s *SampleSink) Close() {}


// New function to create a new instance of the sink
func NewSampleSink(name string, config json.RawMessage) (Sink, error) {
	s := new(SampleSink)
	err := s.Init(name, config)
	return s, err
}