Move to vendor
Signed-off-by: Olivier Gambier <olivier@docker.com>
This commit is contained in:
parent
c8d8e7e357
commit
77e69b9cf3
1268 changed files with 34 additions and 24 deletions
71
vendor/github.com/yvasiyarov/newrelic_platform_go/component.go
generated
vendored
Normal file
71
vendor/github.com/yvasiyarov/newrelic_platform_go/component.go
generated
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
package newrelic_platform_go
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
)
|
||||
|
||||
type ComponentData interface{}
|
||||
type IComponent interface {
|
||||
Harvest(plugin INewrelicPlugin) ComponentData
|
||||
SetDuration(duration int)
|
||||
AddMetrica(model IMetrica)
|
||||
ClearSentData()
|
||||
}
|
||||
|
||||
type PluginComponent struct {
|
||||
Name string `json:"name"`
|
||||
GUID string `json:"guid"`
|
||||
Duration int `json:"duration"`
|
||||
Metrics map[string]MetricaValue `json:"metrics"`
|
||||
MetricaModels []IMetrica `json:"-"`
|
||||
}
|
||||
|
||||
func NewPluginComponent(name string, guid string) *PluginComponent {
|
||||
c := &PluginComponent{
|
||||
Name: name,
|
||||
GUID: guid,
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (component *PluginComponent) AddMetrica(model IMetrica) {
|
||||
component.MetricaModels = append(component.MetricaModels, model)
|
||||
}
|
||||
|
||||
func (component *PluginComponent) ClearSentData() {
|
||||
component.Metrics = nil
|
||||
}
|
||||
|
||||
func (component *PluginComponent) SetDuration(duration int) {
|
||||
component.Duration = duration
|
||||
}
|
||||
|
||||
func (component *PluginComponent) Harvest(plugin INewrelicPlugin) ComponentData {
|
||||
component.Metrics = make(map[string]MetricaValue, len(component.MetricaModels))
|
||||
for i := 0; i < len(component.MetricaModels); i++ {
|
||||
model := component.MetricaModels[i]
|
||||
metricaKey := plugin.GetMetricaKey(model)
|
||||
|
||||
if newValue, err := model.GetValue(); err == nil {
|
||||
if math.IsInf(newValue, 0) || math.IsNaN(newValue) {
|
||||
newValue = 0
|
||||
}
|
||||
|
||||
if existMetric, ok := component.Metrics[metricaKey]; ok {
|
||||
if floatExistVal, ok := existMetric.(float64); ok {
|
||||
component.Metrics[metricaKey] = NewAggregatedMetricaValue(floatExistVal, newValue)
|
||||
} else if aggregatedValue, ok := existMetric.(*AggregatedMetricaValue); ok {
|
||||
aggregatedValue.Aggregate(newValue)
|
||||
} else {
|
||||
panic("Invalid type in metrica value")
|
||||
}
|
||||
} else {
|
||||
component.Metrics[metricaKey] = newValue
|
||||
}
|
||||
} else {
|
||||
log.Printf("Can not get metrica: %v, got error:%#v", model.GetName(), err)
|
||||
}
|
||||
}
|
||||
return component
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue