<commit_before>// returns data points from Win32_OperatingSystem

package collectors

import (
	"log"

	"github.com/StackExchange/wmi"
	"github.com/prometheus/client_golang/prometheus"
)

// A OSCollector is a Prometheus collector for WMI OperatingSystem metrics
type OSCollector struct {
	FreePhysicalMemory     *prometheus.Desc
	FreeSpaceInPagingFiles *prometheus.Desc
	FreeVirtualMemory      *prometheus.Desc
	NumberOfProcesses      *prometheus.Desc
	NumberOfUsers          *prometheus.Desc
}

// NewOSCollector ...
func NewOSCollector() *OSCollector {

	return &OSCollector{
		FreePhysicalMemory: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory"),
			"Free physical memory.",
			nil,
			nil,
		),

		FreeSpaceInPagingFiles: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files"),
			"Free space in paging files.",
			nil,
			nil,
		),

		FreeVirtualMemory: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory"),
			"Free virtual memory.",
			nil,
			nil,
		),

		NumberOfProcesses: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "number_of_processes"),
			"No. of processes running on the system.",
			nil,
			nil,
		),

		NumberOfUsers: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "number_of_users"),
			"No. of users logged in.",
			nil,
			nil,
		),
	}
}

// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *OSCollector) Collect(ch chan<- prometheus.Metric) {
	if desc, err := c.collect(ch); err != nil {
		log.Println("[ERROR] failed collecting process metrics:", desc, err)
		return
	}
}

// Describe sends the descriptors of each metric over to the provided channel.
// The corresponding metric values are sent separately.
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {

	ch <- c.FreePhysicalMemory
	ch <- c.FreeSpaceInPagingFiles
	ch <- c.FreeVirtualMemory
	ch <- c.NumberOfProcesses
	ch <- c.NumberOfUsers
}

type Win32_OperatingSystem struct {
	FreePhysicalMemory     uint64
	FreeSpaceInPagingFiles uint64
	FreeVirtualMemory      uint64
	NumberOfProcesses      uint32
	NumberOfUsers          uint32
}

func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	if err := wmi.Query(q, &dst); err != nil {
		return nil, err
	}

	ch <- prometheus.MustNewConstMetric(
		c.FreePhysicalMemory,
		prometheus.GaugeValue,
		float64(dst[0].FreePhysicalMemory),
	)

	ch <- prometheus.MustNewConstMetric(
		c.FreeSpaceInPagingFiles,
		prometheus.GaugeValue,
		float64(dst[0].FreeSpaceInPagingFiles),
	)

	ch <- prometheus.MustNewConstMetric(
		c.FreeVirtualMemory,
		prometheus.GaugeValue,
		float64(dst[0].FreeVirtualMemory),
	)

	ch <- prometheus.MustNewConstMetric(
		c.NumberOfProcesses,
		prometheus.GaugeValue,
		float64(dst[0].NumberOfProcesses),
	)

	ch <- prometheus.MustNewConstMetric(
		c.NumberOfUsers,
		prometheus.GaugeValue,
		float64(dst[0].NumberOfUsers),
	)

	return nil, nil
}<commit_msg>os: expose SizeStoredInPagingFiles, TotalVirtualMemorySize, TotalVisibleMemorySize<commit_after>// returns data points from Win32_OperatingSystem
// https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx

package collectors

import (
	"log"

	"github.com/StackExchange/wmi"
	"github.com/prometheus/client_golang/prometheus"
)

// A OSCollector is a Prometheus collector for WMI OperatingSystem metrics
type OSCollector struct {
	FreePhysicalMemory      *prometheus.Desc
	FreeSpaceInPagingFiles  *prometheus.Desc
	FreeVirtualMemory       *prometheus.Desc
	NumberOfProcesses       *prometheus.Desc
	NumberOfUsers           *prometheus.Desc
	SizeStoredInPagingFiles *prometheus.Desc
	TotalVirtualMemorySize  *prometheus.Desc
	TotalVisibleMemorySize  *prometheus.Desc
}

// NewOSCollector ...
func NewOSCollector() *OSCollector {

	return &OSCollector{
		FreePhysicalMemory: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_physical_memory"),
			"Number, in kilobytes, of physical memory currently unused and available.",
			nil,
			nil,
		),

		FreeSpaceInPagingFiles: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_space_in_paging_files"),
			"Number, in kilobytes, that can be mapped into the operating system paging files without causing any other pages to be swapped out.",
			nil,
			nil,
		),

		FreeVirtualMemory: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "free_virtual_memory"),
			"Number, in kilobytes, of virtual memory currently unused and available.",
			nil,
			nil,
		),

		NumberOfProcesses: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "number_of_processes"),
			"Number of process contexts currently loaded or running on the operating system.",
			nil,
			nil,
		),

		NumberOfUsers: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "number_of_users"),
			"Number of user sessions for which the operating system is storing state information currently.",
			nil,
			nil,
		),

		SizeStoredInPagingFiles: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "size_stored_in_paging_files"),
			"Total number of kilobytes that can be stored in the operating system paging files.",
			nil,
			nil,
		),

		TotalVirtualMemorySize: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "total_virtual_memory_size"),
			"Number, in kilobytes, of virtual memory.",
			nil,
			nil,
		),

		TotalVisibleMemorySize: prometheus.NewDesc(
			prometheus.BuildFQName(wmiNamespace, "os", "total_visible_memory_size"),
			"Total amount, in kilobytes, of physical memory available to the operating system.",
			nil,
			nil,
		),
	}
}

// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func (c *OSCollector) Collect(ch chan<- prometheus.Metric) {
	if desc, err := c.collect(ch); err != nil {
		log.Println("[ERROR] failed collecting process metrics:", desc, err)
		return
	}
}

// Describe sends the descriptors of each metric over to the provided channel.
// The corresponding metric values are sent separately.
func (c *OSCollector) Describe(ch chan<- *prometheus.Desc) {

	ch <- c.FreePhysicalMemory
	ch <- c.FreeSpaceInPagingFiles
	ch <- c.FreeVirtualMemory
	ch <- c.NumberOfProcesses
	ch <- c.NumberOfUsers
	ch <- c.SizeStoredInPagingFiles
	ch <- c.TotalVirtualMemorySize
	ch <- c.TotalVisibleMemorySize
}

type Win32_OperatingSystem struct {
	FreePhysicalMemory      uint64
	FreeSpaceInPagingFiles  uint64
	FreeVirtualMemory       uint64
	NumberOfProcesses       uint32
	NumberOfUsers           uint32
	SizeStoredInPagingFiles uint64
	TotalVirtualMemorySize  uint64
	TotalVisibleMemorySize  uint64
}

func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	if err := wmi.Query(q, &dst); err != nil {
		return nil, err
	}

	ch <- prometheus.MustNewConstMetric(
		c.FreePhysicalMemory,
		prometheus.GaugeValue,
		float64(dst[0].FreePhysicalMemory),
	)

	ch <- prometheus.MustNewConstMetric(
		c.FreeSpaceInPagingFiles,
		prometheus.GaugeValue,
		float64(dst[0].FreeSpaceInPagingFiles),
	)

	ch <- prometheus.MustNewConstMetric(
		c.FreeVirtualMemory,
		prometheus.GaugeValue,
		float64(dst[0].FreeVirtualMemory),
	)

	ch <- prometheus.MustNewConstMetric(
		c.NumberOfProcesses,
		prometheus.GaugeValue,
		float64(dst[0].NumberOfProcesses),
	)

	ch <- prometheus.MustNewConstMetric(
		c.NumberOfUsers,
		prometheus.GaugeValue,
		float64(dst[0].NumberOfUsers),
	)

	ch <- prometheus.MustNewConstMetric(
		c.SizeStoredInPagingFiles,
		prometheus.GaugeValue,
		float64(dst[0].SizeStoredInPagingFiles),
	)

	ch <- prometheus.MustNewConstMetric(
		c.TotalVirtualMemorySize,
		prometheus.GaugeValue,
		float64(dst[0].TotalVirtualMemorySize),
	)

	ch <- prometheus.MustNewConstMetric(
		c.TotalVisibleMemorySize,
		prometheus.GaugeValue,
		float64(dst[0].TotalVisibleMemorySize),
	)

	return nil, nil
}
{'fraction_non_alphanumeric': 0.10213395830763537, 'fraction_numerical': 0.01048476625138769, 'mean_word_length': 4.448924731182796, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '7009905', 'n_tokens_mistral': 3028, 'n_tokens_neox': 2637, 'n_words': 598}