mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-08-14 14:52:58 +02:00
.github
collectors
internal
receivers
scripts
sinks
README.md
gangliaCommon.go
gangliaSink.go
gangliaSink.md
httpSink.go
httpSink.md
influxAsyncSink.go
influxAsyncSink.md
influxSink.go
influxSink.md
libgangliaSink.go
libgangliaSink.md
metricSink.go
natsSink.go
natsSink.md
prometheusSink.go
prometheusSink.md
sampleSink.go
sinkManager.go
stdoutSink.go
stdoutSink.md
.gitignore
.gitmodules
LICENSE
Makefile
README.md
collectors.json
config.json
go.mod
go.sum
metric-collector.go
receivers.json
router.json
sinks.json
* 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>
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package sinks
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
|
|
cclog "github.com/ClusterCockpit/cc-metric-collector/internal/ccLogger"
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
)
|
|
|
|
type SampleSinkConfig struct {
|
|
defaultSinkConfig // defines JSON tags for 'type' and 'meta_as_tags'
|
|
// Add additional options
|
|
}
|
|
|
|
type SampleSink struct {
|
|
sink // declarate 'name' and 'meta_as_tags'
|
|
config SampleSinkConfig // entry point to the SampleSinkConfig
|
|
}
|
|
|
|
// 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() {
|
|
cclog.ComponentDebug(s.name, "CLOSE")
|
|
}
|
|
|
|
// New function to create a new instance of the sink
|
|
// Initialize the sink by giving it a name and reading in the config JSON
|
|
func NewSampleSink(name string, config json.RawMessage) (Sink, error) {
|
|
s := new(SampleSink)
|
|
s.name = fmt.Sprintf("SampleSink(%s)", name) // Always specify a name here
|
|
|
|
// Set defaults in s.config
|
|
|
|
// Read in the config JSON
|
|
if len(config) > 0 {
|
|
err := json.Unmarshal(config, &s.config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// Check if all required fields in the config are set
|
|
// Use 'len(s.config.Option) > 0' for string settings
|
|
|
|
// Establish connection to the server, library, ...
|
|
// Check required files exist and lookup path(s) of executable(s)
|
|
|
|
// Return (nil, meaningful error message) in case of errors
|
|
return s, nil
|
|
}
|