func (m *metricset) Fetch(reporter mb.ReporterV2) error {
	families, _, err := m.mod.GetContainerdMetricsFamilies(m.prometheusClient)
	if err != nil {
		return errors.Wrap(err, "error getting families")
	}
	events, err := m.prometheusClient.ProcessMetrics(families, mapping)
	if err != nil {
		return errors.Wrap(err, "error getting events")
	}

	for _, event := range events {

		// setting ECS container.id and module field containerd.namespace
		containerFields := common.MapStr{}
		moduleFields := common.MapStr{}
		rootFields := common.MapStr{}

		cID := containerd.GetAndDeleteCid(event)
		namespace := containerd.GetAndDeleteNamespace(event)

		containerFields.Put("id", cID)
		rootFields.Put("container", containerFields)
		moduleFields.Put("namespace", namespace)

		// Calculate memory total usage percentage
		if m.calcPct {
			inactiveFiles, err := event.GetValue("inactiveFiles")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. inactiveFiles not present in the event: %w", err)
				continue
			}
			usageTotal, err := event.GetValue("usage.total")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. usage.total not present in the event: %w", err)
				continue
			}
			memoryLimit, err := event.GetValue("usage.limit")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. usage.limit not present in the event: %w", err)
				continue
			}
			mLfloat, ok := memoryLimit.(float64)
			if ok && mLfloat != 0.0 {
				// calculate working set memory usage
				workingSetUsage := usageTotal.(float64) - inactiveFiles.(float64)
				workingSetUsagePct := workingSetUsage / mLfloat
				event.Put("workingset.pct", workingSetUsagePct)

				memoryUsagePct := usageTotal.(float64) / mLfloat
				event.Put("usage.pct", memoryUsagePct)
				m.Logger().Debugf("memoryUsagePct for %+v is %+v", cID, memoryUsagePct)
			}
		}

		reporter.Event(mb.Event{
			RootFields:      rootFields,
			ModuleFields:    moduleFields,
			MetricSetFields: event,
			Namespace:       "containerd.memory",
		})
	}
	return nil
}
// Fetch gathers information from the containerd and reports events with this information.
Fetch gathers information from the containerd and reports events with this information.
// Fetch gathers information from the containerd and reports events with this information .
func (m *metricset) Fetch(reporter mb.ReporterV2) error {
	families, _, err := m.mod.GetContainerdMetricsFamilies(m.prometheusClient)
	if err != nil {
		return errors.Wrap(err, "error getting families")
	}
	events, err := m.prometheusClient.ProcessMetrics(families, mapping)
	if err != nil {
		return errors.Wrap(err, "error getting events")
	}
	for _, event := range events {
		containerFields := common.MapStr{}
		moduleFields := common.MapStr{}
		rootFields := common.MapStr{}
		cID := containerd.GetAndDeleteCid(event)
		namespace := containerd.GetAndDeleteNamespace(event)
		containerFields.Put("id", cID)
		rootFields.Put("container", containerFields)
		moduleFields.Put("namespace", namespace)
		if m.calcPct {
			inactiveFiles, err := event.GetValue("inactiveFiles")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. inactiveFiles not present in the event: %w", err)
				continue
			}
			usageTotal, err := event.GetValue("usage.total")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. usage.total not present in the event: %w", err)
				continue
			}
			memoryLimit, err := event.GetValue("usage.limit")
			if err != nil {
				m.Logger().Debugf("memoryUsagePct calculation skipped. usage.limit not present in the event: %w", err)
				continue
			}
			mLfloat, ok := memoryLimit.(float64)
			if ok && mLfloat != 0.0 {
				workingSetUsage := usageTotal.(float64) - inactiveFiles.(float64)
				workingSetUsagePct := workingSetUsage / mLfloat
				event.Put("workingset.pct", workingSetUsagePct)
				memoryUsagePct := usageTotal.(float64) / mLfloat
				event.Put("usage.pct", memoryUsagePct)
				m.Logger().Debugf("memoryUsagePct for %+v is %+v", cID, memoryUsagePct)
			}
		}
		reporter.Event(mb.Event{
			RootFields:      rootFields,
			ModuleFields:    moduleFields,
			MetricSetFields: event,
			Namespace:       "containerd.memory",
		})
	}
	return nil
}
func ( m * metricset ) Fetch ( reporter mb . ReporterV2 ) error { families , _ , err := m . mod . GetContainerdMetricsFamilies ( m . prometheusClient ) if err != nil { return errors . Wrap ( err , " " ) } events , err := m . prometheusClient . ProcessMetrics ( families , mapping ) if err != nil { return errors . Wrap ( err , " " ) } for _ , event := range events { containerFields := common . MapStr { } moduleFields := common . MapStr { } rootFields := common . MapStr { } cID := containerd . GetAndDeleteCid ( event ) namespace := containerd . GetAndDeleteNamespace ( event ) containerFields . Put ( " " , cID ) rootFields . Put ( " " , containerFields ) moduleFields . Put ( " " , namespace ) if m . calcPct { inactiveFiles , err := event . GetValue ( " " ) if err != nil { m . Logger ( ) . Debugf ( " " , err ) continue } usageTotal , err := event . GetValue ( " " ) if err != nil { m . Logger ( ) . Debugf ( " " , err ) continue } memoryLimit , err := event . GetValue ( " " ) if err != nil { m . Logger ( ) . Debugf ( " " , err ) continue } mLfloat , ok := memoryLimit . ( float64 ) if ok && mLfloat != 0.0 { workingSetUsage := usageTotal . ( float64 ) - inactiveFiles . ( float64 ) workingSetUsagePct := workingSetUsage / mLfloat event . Put ( " " , workingSetUsagePct ) memoryUsagePct := usageTotal . ( float64 ) / mLfloat event . Put ( " " , memoryUsagePct ) m . Logger ( ) . Debugf ( " " , cID , memoryUsagePct ) } } reporter . Event ( mb . Event { RootFields : rootFields , ModuleFields : moduleFields , MetricSetFields : event , Namespace : " " , } ) } return nil }
Fetch gathers information from the containerd and reports events with this information.
Fetch gathers information from the containerd and reports events with this information .
// setting ECS container.id and module field containerd.namespace // Calculate memory total usage percentage // calculate working set memory usage