mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-12-27 07:39:05 +01:00
d98076c792
* 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>
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package sinks
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
// "time"
|
|
lp "github.com/ClusterCockpit/cc-metric-collector/internal/ccMetric"
|
|
)
|
|
|
|
type StdoutSink struct {
|
|
sink // meta_as_tags, name
|
|
output *os.File
|
|
config struct {
|
|
defaultSinkConfig
|
|
Output string `json:"output_file,omitempty"`
|
|
}
|
|
}
|
|
|
|
func (s *StdoutSink) Write(m lp.CCMetric) error {
|
|
fmt.Fprint(
|
|
s.output,
|
|
m.ToLineProtocol(s.meta_as_tags),
|
|
)
|
|
return nil
|
|
}
|
|
|
|
func (s *StdoutSink) Flush() error {
|
|
s.output.Sync()
|
|
return nil
|
|
}
|
|
|
|
func (s *StdoutSink) Close() {
|
|
if s.output != os.Stdout && s.output != os.Stderr {
|
|
s.output.Close()
|
|
}
|
|
}
|
|
|
|
func NewStdoutSink(name string, config json.RawMessage) (Sink, error) {
|
|
s := new(StdoutSink)
|
|
s.name = fmt.Sprintf("StdoutSink(%s)", name)
|
|
if len(config) > 0 {
|
|
err := json.Unmarshal(config, &s.config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
s.output = os.Stdout
|
|
if len(s.config.Output) > 0 {
|
|
switch strings.ToLower(s.config.Output) {
|
|
case "stdout":
|
|
s.output = os.Stdout
|
|
case "stderr":
|
|
s.output = os.Stderr
|
|
default:
|
|
f, err := os.OpenFile(s.config.Output, os.O_CREATE|os.O_WRONLY, os.FileMode(0600))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s.output = f
|
|
}
|
|
}
|
|
s.meta_as_tags = s.config.MetaAsTags
|
|
|
|
return s, nil
|
|
}
|