<commit_before>package qtypes


import (
	"fmt"
	"strings"
	"github.com/docker/docker/api/types"
)


// Inspired by https://github.com/elastic/beats/blob/master/metricbeat/module/docker/net/helper.go
type NetStats struct {
	Base
	Container     *types.Container
	NameInterface string
	RxBytes       float64
	RxDropped     float64
	RxErrors      float64
	RxPackets     float64
	TxBytes       float64
	TxDropped     float64
	TxErrors      float64
	TxPackets     float64
}


func (ns *NetStats) ToMetrics(src string) []Metric {
	dim := map[string]string{
		"container_id": ns.Container.ID,
		"container_name": strings.Trim(ns.Container.Names[0], "/"),
		"image_name": ns.Container.Image,
		"command": strings.Replace(ns.Container.Command, " ", "#", -1),
		"created": fmt.Sprintf("%d", ns.Container.Created),
	}
	for k, v := range ns.Container.Labels {
		dim[k] = strings.Replace(v, " ", "#", -1)
	}
	return []Metric{
		ns.NewExtMetric(src, "network.total.rx.bytes", Gauge, ns.RxBytes, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.rx.dropped", Gauge, ns.RxDropped, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.rx.errors", Gauge, ns.RxErrors, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.rx.packets", Gauge, ns.RxPackets, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.tx.bytes", Gauge, ns.TxBytes, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.tx.dropped", Gauge, ns.TxDropped, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.tx.errors", Gauge, ns.TxErrors, dim, ns.Time, true),
		ns.NewExtMetric(src, "network.total.tx.packets", Gauge, ns.TxPackets, dim, ns.Time, true),
	}
}<commit_msg>if NetworkInterface is not set use total<commit_after>package qtypes


import (
	"fmt"
	"strings"
	"github.com/docker/docker/api/types"
)


// Inspired by https://github.com/elastic/beats/blob/master/metricbeat/module/docker/net/helper.go
type NetStats struct {
	Base
	Container     *types.Container
	NameInterface string
	RxBytes       float64
	RxDropped     float64
	RxErrors      float64
	RxPackets     float64
	TxBytes       float64
	TxDropped     float64
	TxErrors      float64
	TxPackets     float64
}


func (ns *NetStats) ToMetrics(src string) []Metric {
	dim := map[string]string{
		"container_id": ns.Container.ID,
		"container_name": strings.Trim(ns.Container.Names[0], "/"),
		"image_name": ns.Container.Image,
		"command": strings.Replace(ns.Container.Command, " ", "#", -1),
		"created": fmt.Sprintf("%d", ns.Container.Created),
	}
	for k, v := range ns.Container.Labels {
		dim[k] = strings.Replace(v, " ", "#", -1)
	}
	iface := "total"
	if ns.NameInterface == "" {
		iface = ns.NameInterface
		dim["network_iface"] = iface
	}
	return []Metric{
		ns.NewExtMetric(src, "network."+iface+".rx.bytes", Gauge, ns.RxBytes, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".rx.dropped", Gauge, ns.RxDropped, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".rx.errors", Gauge, ns.RxErrors, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".rx.packets", Gauge, ns.RxPackets, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".tx.bytes", Gauge, ns.TxBytes, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".tx.dropped", Gauge, ns.TxDropped, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".tx.errors", Gauge, ns.TxErrors, dim, ns.Time, true),
		ns.NewExtMetric(src, "network."+iface+".tx.packets", Gauge, ns.TxPackets, dim, ns.Time, true),
	}
}
{'fraction_non_alphanumeric': 0.16967612496417311, 'fraction_numerical': 0.010891372886213814, 'mean_word_length': 4.155096011816839, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5409195', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1304, 'n_words': 252}