<commit_before>package procstat

import (
	"fmt"

	"github.com/shirou/gopsutil/process"

	"github.com/influxdb/telegraf/plugins"
)

type SpecProcessor struct {
	Prefix string
	tags   map[string]string
	acc    plugins.Accumulator
	proc   *process.Process
}

func (p *SpecProcessor) add(metric string, value interface{}) {
	p.acc.Add(p.Prefix+"_"+metric, value, p.tags)
}

func NewSpecProcessor(prefix string, acc plugins.Accumulator, p *process.Process) *SpecProcessor {
	return &SpecProcessor{
		Prefix: prefix,
		tags:   map[string]string{},
		acc:    acc,
		proc:   p,
	}
}

func (p *SpecProcessor) pushMetrics() error {
	if err := p.pushFDStats(); err != nil {
		return err
	}
	if err := p.pushCtxStats(); err != nil {
		return err
	}
	if err := p.pushIOStats(); err != nil {
		return err
	}
	if err := p.pushCPUStats(); err != nil {
		return err
	}
	if err := p.pushMemoryStats(); err != nil {
		return err
	}
	return nil
}

func (p *SpecProcessor) pushFDStats() error {
	fds, err := p.proc.NumFDs()
	if err != nil {
		return fmt.Errorf("NumFD error: %s\n", err)
	}
	p.add("num_fds", fds)
	return nil
}

func (p *SpecProcessor) pushCtxStats() error {
	ctx, err := p.proc.NumCtxSwitches()
	if err != nil {
		return fmt.Errorf("ContextSwitch error: %s\n", err)<commit_msg>Add pid tag to procstat plugin, dont exit on error, only log<commit_after>package procstat

import (
	"fmt"
	"log"

	"github.com/shirou/gopsutil/process"

	"github.com/influxdb/telegraf/plugins"
)

type SpecProcessor struct {
	Prefix string
	tags   map[string]string
	acc    plugins.Accumulator
	proc   *process.Process
}

func (p *SpecProcessor) add(metric string, value interface{}) {
	p.acc.Add(p.Prefix+"_"+metric, value, p.tags)
}

func NewSpecProcessor(
	prefix string,
	acc plugins.Accumulator,
	p *process.Process,
) *SpecProcessor {
	tags := make(map[string]string)
	tags["pid"] = fmt.Sprintf("%v", p.Pid)
	return &SpecProcessor{
		Prefix: prefix,
		tags:   tags,
		acc:    acc,
		proc:   p,
	}
}

func (p *SpecProcessor) pushMetrics() error {
	if err := p.pushFDStats(); err != nil {
		log.Printf(err.Error())
	}
	if err := p.pushCtxStats(); err != nil {
		log.Printf(err.Error())
	}
	if err := p.pushIOStats(); err != nil {
		log.Printf(err.Error())
	}
	if err := p.pushCPUStats(); err != nil {
		log.Printf(err.Error())
	}
	if err := p.pushMemoryStats(); err != nil {
		log.Printf(err.Error())
	}
	return nil
}

func (p *SpecProcessor) pushFDStats() error {
	fds, err := p.proc.NumFDs()
	if err != nil {
		return fmt.Errorf("NumFD error: %s\n", err)
	}
	p.add("num_fds", fds)
	return nil
}

func (p *SpecProcessor) pushCtxStats() error {
	ctx, err := p.proc.NumCtxSwitches()
	if err != nil {
		return fmt.Errorf("ContextSwitch error: %s\n", err)
{'fraction_non_alphanumeric': 0.15598681801537898, 'fraction_numerical': 0.0, 'mean_word_length': 3.818342151675485, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5430747', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1033, 'n_words': 258}