func serialize(metric telegraf.Metric) ([]string, error) { out := []string{} m := make(map[string]interface{}) m["version"] = "1.1" m["timestamp"] = metric.UnixNano() / 1000000000 m["short_message"] = " " m["name"] = metric.Name() if host, ok := metric.Tags()["host"]; ok { m["host"] = host } else { host, err := os.Hostname() if err != nil { return []string{}, err } m["host"] = host } for key, value := range metric.Fields() { nkey := fmt.Sprintf("_%s", key) m[nkey] = value } serialized, err := ejson.Marshal(m) if err != nil { return []string{}, err } out = append(out, string(serialized)) return out, nil }
func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} // Get name name := metric.Name() // Convert UnixNano to Unix timestamps timestamp := metric.UnixNano() / 1000000000 tag_str := buildTags(metric) for field_name, value := range metric.Fields() { // Convert value value_str := fmt.Sprintf("%#v", value) // Write graphite metric var graphitePoint string if name == field_name { graphitePoint = fmt.Sprintf("%s.%s %s %d", tag_str, strings.Replace(name, ".", "_", -1), value_str, timestamp) } else { graphitePoint = fmt.Sprintf("%s.%s.%s %s %d", tag_str, strings.Replace(name, ".", "_", -1), strings.Replace(field_name, ".", "_", -1), value_str, timestamp) } if s.Prefix != "" { graphitePoint = fmt.Sprintf("%s.%s", s.Prefix, graphitePoint) } out = append(out, graphitePoint) } return out, nil }
func (s *JsonSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} m := make(map[string]interface{}) m["tags"] = metric.Tags() m["fields"] = metric.Fields() m["name"] = metric.Name() m["timestamp"] = metric.UnixNano() / 1000000000 serialized, err := ejson.Marshal(m) if err != nil { return []string{}, err } out = append(out, string(serialized)) return out, nil }
func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} // Convert UnixNano to Unix timestamps timestamp := metric.UnixNano() / 1000000000 for field_name, value := range metric.Fields() { // Convert value value_str := fmt.Sprintf("%#v", value) // Write graphite metric var graphitePoint string graphitePoint = fmt.Sprintf("%s %s %d", s.SerializeBucketName(metric, field_name), value_str, timestamp) out = append(out, graphitePoint) } return out, nil }
func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} // Convert UnixNano to Unix timestamps timestamp := metric.UnixNano() / 1000000000 bucket := s.SerializeBucketName(metric.Name(), metric.Tags()) for fieldName, value := range metric.Fields() { // Convert value to string valueS := fmt.Sprintf("%#v", value) point := fmt.Sprintf("%s %s %d", // insert "field" section of template InsertField(bucket, fieldName), valueS, timestamp) out = append(out, point) } return out, nil }
func (s *GraphiteSerializer) Serialize(metric telegraf.Metric) ([]string, error) { out := []string{} // Convert UnixNano to Unix timestamps timestamp := metric.UnixNano() / 1000000000 bucket := SerializeBucketName(metric.Name(), metric.Tags(), s.Template, s.Prefix) if bucket == "" { return out, nil } for fieldName, value := range metric.Fields() { // Convert value to string valueS := fmt.Sprintf("%#v", value) point := fmt.Sprintf("%s %s %d", // insert "field" section of template sanitizedChars.Replace(InsertField(bucket, fieldName)), sanitizedChars.Replace(valueS), timestamp) out = append(out, point) } return out, nil }