github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/metrics/sinks/honeycomb/driver.go (about)

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package honeycomb
    16  
    17  import (
    18  	"net/url"
    19  	"sync"
    20  
    21  	"github.com/golang/glog"
    22  	honeycomb_common "k8s.io/heapster/common/honeycomb"
    23  	"k8s.io/heapster/metrics/core"
    24  )
    25  
    26  // These metrics report cumulative values over the lifetime of the process.
    27  // Heapster also reports gauges (e.g., "cpu/usage_rate"). Cumulative metrics
    28  // are more confusing than helpful, so let's not send them in the first place.
    29  var blacklist = map[string]struct{}{
    30  	"cpu/usage":                {},
    31  	"memory/major_page_faults": {},
    32  	"memory/page_faults":       {},
    33  	"network/rx_errors":        {},
    34  	"network/rx":               {},
    35  	"network/tx_errors":        {},
    36  	"network/tx":               {},
    37  }
    38  
    39  type honeycombSink struct {
    40  	client honeycomb_common.Client
    41  	sync.Mutex
    42  }
    43  
    44  type Point struct {
    45  	MetricsName string
    46  	MetricsTags string
    47  }
    48  
    49  func (sink *honeycombSink) ExportData(dataBatch *core.DataBatch) {
    50  
    51  	sink.Lock()
    52  	defer sink.Unlock()
    53  
    54  	batch := make(honeycomb_common.Batch, len(dataBatch.MetricSets))
    55  
    56  	i := 0
    57  	for _, metricSet := range dataBatch.MetricSets {
    58  		data := make(map[string]interface{})
    59  		for metricName, metricValue := range metricSet.MetricValues {
    60  			if _, ok := blacklist[metricName]; ok {
    61  				continue
    62  			}
    63  			data[metricName] = metricValue.GetValue()
    64  		}
    65  		for k, v := range metricSet.Labels {
    66  			data[k] = v
    67  		}
    68  		batch[i] = &honeycomb_common.BatchPoint{
    69  			Data:      data,
    70  			Timestamp: dataBatch.Timestamp,
    71  		}
    72  		i++
    73  	}
    74  	err := sink.client.SendBatch(batch)
    75  	if err != nil {
    76  		glog.Warningf("Failed to send metrics batch: %v", err)
    77  	}
    78  }
    79  
    80  func (sink *honeycombSink) Stop() {}
    81  func (sink *honeycombSink) Name() string {
    82  	return "Honeycomb Sink"
    83  }
    84  
    85  func NewHoneycombSink(uri *url.URL) (core.DataSink, error) {
    86  	client, err := honeycomb_common.NewClient(uri)
    87  	if err != nil {
    88  		return nil, err
    89  	}
    90  	sink := &honeycombSink{
    91  		client: client,
    92  	}
    93  
    94  	return sink, nil
    95  }