本文整理匯總了Golang中collectd/org/api.ValueList類的典型用法代碼示例。如果您正苦於以下問題:Golang ValueList類的具體用法?Golang ValueList怎麽用?Golang ValueList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ValueList類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newName
// newName converts one data source of a value list to a string representation.
func newName(vl api.ValueList, index int) string {
var name string
if vl.Plugin == vl.Type {
name = "collectd_" + vl.Type
} else {
name = "collectd_" + vl.Plugin + "_" + vl.Type
}
if dsname := vl.DSName(index); dsname != "value" {
name += "_" + dsname
}
switch vl.Values[index].(type) {
case api.Counter:
name += "_total"
}
return name
}
示例2: UnmarshalValueList
// Unmarshal translates a ValueList into InfluxDB data points.
func (s *Service) UnmarshalValueList(vl *api.ValueList) []models.Point {
timestamp := vl.Time.UTC()
var points []models.Point
for i := range vl.Values {
var name string
name = fmt.Sprintf("%s_%s", vl.Identifier.Plugin, vl.DSName(i))
tags := make(map[string]string)
fields := make(map[string]interface{})
// Convert interface back to actual type, then to float64
switch value := vl.Values[i].(type) {
case api.Gauge:
fields["value"] = float64(value)
case api.Derive:
fields["value"] = float64(value)
case api.Counter:
fields["value"] = float64(value)
}
if vl.Identifier.Host != "" {
tags["host"] = vl.Identifier.Host
}
if vl.Identifier.PluginInstance != "" {
tags["instance"] = vl.Identifier.PluginInstance
}
if vl.Identifier.Type != "" {
tags["type"] = vl.Identifier.Type
}
if vl.Identifier.TypeInstance != "" {
tags["type_instance"] = vl.Identifier.TypeInstance
}
// Drop invalid points
p, err := models.NewPoint(name, models.NewTags(tags), fields, timestamp)
if err != nil {
s.Logger.Info(fmt.Sprintf("Dropping point %v: %v", name, err))
atomic.AddInt64(&s.stats.InvalidDroppedPoints, 1)
continue
}
points = append(points, p)
}
return points
}
示例3: parseTime
func parseTime(partType uint16, payload []byte, state *api.ValueList) error {
v, err := parseInt(payload)
if err != nil {
return err
}
switch partType {
case typeInterval:
state.Interval = time.Duration(v) * time.Second
case typeIntervalHR:
state.Interval = cdtime.Time(v).Duration()
case typeTime:
state.Time = time.Unix(int64(v), 0)
case typeTimeHR:
state.Time = cdtime.Time(v).Time()
}
return nil
}
示例4: Write
// Write formats the ValueList in the PUTVAL format and writes it to the
// assiciated io.Writer.
func (g *Graphite) Write(vl api.ValueList) error {
for i, v := range vl.Values {
dsName := ""
if g.AlwaysAppendDS || len(vl.Values) != 1 {
dsName = vl.DSName(i)
}
name := g.formatName(vl.Identifier, dsName)
val, err := g.formatValue(v)
if err != nil {
return err
}
t := vl.Time
if t.IsZero() {
t = time.Now()
}
fmt.Fprintf(g.W, "%s %s %d\r\n", name, val, t.Unix())
}
return nil
}
示例5: newDesc
// newDesc converts one data source of a value list to a Prometheus description.
func newDesc(vl api.ValueList, index int) *prometheus.Desc {
help := fmt.Sprintf("Collectd exporter: '%s' Type: '%s' Dstype: '%T' Dsname: '%s'",
vl.Plugin, vl.Type, vl.Values[index], vl.DSName(index))
return prometheus.NewDesc(newName(vl, index), help, []string{}, newLabels(vl))
}