<commit_before>package collectors

import (
	"github.com/StackExchange/scollector/metadata"
	"github.com/StackExchange/scollector/opentsdb"
	"github.com/StackExchange/wmi"
)

func init() {
	collectors = append(collectors, &IntervalCollector{F: c_cpu_windows})
	collectors = append(collectors, &IntervalCollector{F: c_cpu_info_windows})
}

func c_cpu_windows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_PerfOS_Processor
	var q = wmi.CreateQuery(&dst, `WHERE Name <> '_Total'`)
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	var used, num uint64
	for _, v := range dst {
		used += v.Timestamp_Sys100NS - v.PercentIdleTime
		num++
		Add(&md, "win.cpu", v.PercentPrivilegedTime, opentsdb.TagSet{"cpu": v.Name, "type": "privileged"}, metadata.Counter, metadata.Pct, "Percentage of non-idle processor time spent in privileged mode.")
		Add(&md, "win.cpu", v.PercentInterruptTime, opentsdb.TagSet{"cpu": v.Name, "type": "interrupt"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spent receiving and servicing hardware interrupts during the sample interval.")
		Add(&md, "win.cpu", v.PercentUserTime, opentsdb.TagSet{"cpu": v.Name, "type": "user"}, metadata.Counter, metadata.Pct, "Percentage of non-idle processor time spent in user mode.")
		Add(&md, "win.cpu", v.PercentIdleTime, opentsdb.TagSet{"cpu": v.Name, "type": "idle"}, metadata.Counter, metadata.Pct, "Percentage of time during the sample interval that the processor was idle.")
		Add(&md, "win.cpu.interrupts", v.InterruptsPersec, opentsdb.TagSet{"cpu": v.Name}, metadata.Counter, metadata.Event, "Average number of hardware interrupts that the processor is receiving and servicing in each second.")
		Add(&md, "win.cpu.dpcs", v.DPCRate, opentsdb.TagSet{"cpu": v.Name}, metadata.Counter, metadata.Event, "Rate at which deferred procedure calls (DPCs) are added to the processor DPC queue between the timer tics of the processor clock.")
		Add(&md, "win.cpu.time_cstate", v.PercentC1Time, opentsdb.TagSet{"cpu": v.Name, "type": "c1"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C1 low-power idle state, which is a subset of the total processor idle time.")
		Add(&md, "win.cpu.time_cstate", v.PercentC2Time, opentsdb.TagSet{"cpu": v.Name, "type": "c2"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C-2 low-power idle state, which is a subset of the total processor idle time.")
		Add(&md, "win.cpu.time_cstate", v.PercentC3Time, opentsdb.TagSet{"cpu": v.Name, "type": "c3"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C3 low-power idle state, which is a subset of the total processor idle time.")
	}
	if num > 0 {
		cpu := used / 1e5 / num
		Add(&md, osCPU, cpu, nil, metadata.Counter, metadata.Pct, "")
	}
	return md, nil
}

type Win32_PerfRawData_PerfOS_Processor struct {
	DPCRate               uint32
	InterruptsPersec      uint32
	Name                  string
	PercentC1Time         uint64
	Timestamp_Sys100NS    uint64
	PercentC2Time         uint64
	PercentC3Time         uint64
	PercentIdleTime       uint64
	PercentInterruptTime  uint64
	PercentPrivilegedTime uint64
	PercentProcessorTime  uint64
	PercentUserTime       uint64
}

func c_cpu_info_windows() (opentsdb.MultiDataPoint, error) {<commit_msg>cmd/scollector: Just pass when there is an erroneous CPU spike measurement of os.cpu in win<commit_after>package collectors

import (
	"github.com/StackExchange/scollector/metadata"
	"github.com/StackExchange/scollector/opentsdb"
	"github.com/StackExchange/wmi"
)

func init() {
	collectors = append(collectors, &IntervalCollector{F: c_cpu_windows})
	collectors = append(collectors, &IntervalCollector{F: c_cpu_info_windows})
}

func c_cpu_windows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_PerfOS_Processor
	var q = wmi.CreateQuery(&dst, `WHERE Name <> '_Total'`)
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	var used, num uint64
	for _, v := range dst {
		used += v.Timestamp_Sys100NS - v.PercentIdleTime
		num++
		Add(&md, "win.cpu", v.PercentPrivilegedTime, opentsdb.TagSet{"cpu": v.Name, "type": "privileged"}, metadata.Counter, metadata.Pct, "Percentage of non-idle processor time spent in privileged mode.")
		Add(&md, "win.cpu", v.PercentInterruptTime, opentsdb.TagSet{"cpu": v.Name, "type": "interrupt"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spent receiving and servicing hardware interrupts during the sample interval.")
		Add(&md, "win.cpu", v.PercentUserTime, opentsdb.TagSet{"cpu": v.Name, "type": "user"}, metadata.Counter, metadata.Pct, "Percentage of non-idle processor time spent in user mode.")
		Add(&md, "win.cpu", v.PercentIdleTime, opentsdb.TagSet{"cpu": v.Name, "type": "idle"}, metadata.Counter, metadata.Pct, "Percentage of time during the sample interval that the processor was idle.")
		Add(&md, "win.cpu.interrupts", v.InterruptsPersec, opentsdb.TagSet{"cpu": v.Name}, metadata.Counter, metadata.Event, "Average number of hardware interrupts that the processor is receiving and servicing in each second.")
		Add(&md, "win.cpu.dpcs", v.DPCRate, opentsdb.TagSet{"cpu": v.Name}, metadata.Counter, metadata.Event, "Rate at which deferred procedure calls (DPCs) are added to the processor DPC queue between the timer tics of the processor clock.")
		Add(&md, "win.cpu.time_cstate", v.PercentC1Time, opentsdb.TagSet{"cpu": v.Name, "type": "c1"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C1 low-power idle state, which is a subset of the total processor idle time.")
		Add(&md, "win.cpu.time_cstate", v.PercentC2Time, opentsdb.TagSet{"cpu": v.Name, "type": "c2"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C-2 low-power idle state, which is a subset of the total processor idle time.")
		Add(&md, "win.cpu.time_cstate", v.PercentC3Time, opentsdb.TagSet{"cpu": v.Name, "type": "c3"}, metadata.Counter, metadata.Pct, "Percentage of time that the processor spends in the C3 low-power idle state, which is a subset of the total processor idle time.")
	}
	//This sometimes spike to > 100 , so as a workaround we just pass when that happens
	if num > 0 && num <= 100 {
		cpu := used / 1e5 / num
		Add(&md, osCPU, cpu, nil, metadata.Counter, metadata.Pct, "")
	}
	return md, nil
}

type Win32_PerfRawData_PerfOS_Processor struct {
	DPCRate               uint32
	InterruptsPersec      uint32
	Name                  string
	PercentC1Time         uint64
	Timestamp_Sys100NS    uint64
	PercentC2Time         uint64
	PercentC3Time         uint64
	PercentIdleTime       uint64
	PercentInterruptTime  uint64
	PercentPrivilegedTime uint64
	PercentProcessorTime  uint64
	PercentUserTime       uint64
}

func c_cpu_info_windows() (opentsdb.MultiDataPoint, error) {
{'fraction_non_alphanumeric': 0.11724931664508703, 'fraction_numerical': 0.014961875989066321, 'mean_word_length': 4.665851670741646, 'pattern_counts': {'":': 32, '<': 6, '<?xml version=': 0, '>': 8, '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': '5094714', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2234, 'n_words': 689}