예제 #1
1
func allPartitions() ([]Partition, error) {
	var ret []Partition
	var dst []win32.Win32_DiskPartition

	q := wmi.CreateQuery(&dst, "")

	if err := wmi.Query(q, &dst); err != nil {
		return ret, err
	}

	for _, p := range dst {

		part := Partition{
			Device: Device{
				DeviceId:    p.DeviceID,
				Name:        p.Name,
				Caption:     p.Caption,
				Description: p.Description,
			},
			BlockSize:        p.BlockSize,
			BootPartition:    p.BootPartition,
			NumberOfBlocks:   p.NumberOfBlocks,
			PrimaryPartition: p.PrimaryPartition,
			Size:             sysmon.Size(p.Size),
			Index:            p.DiskIndex,
			Type:             p.Type,
		}

		ret = append(ret, part)
	}

	return ret, nil
}
예제 #2
0
func init() {
	collectors = append(collectors, &IntervalCollector{F: c_network_windows, init: winNetworkInit})

	c_winnetteam := &IntervalCollector{
		F: c_network_team_windows,
	}
	// Make sure MSFT_NetImPlatAdapter and MSFT_NetAdapterStatisticsSettingData
	// are valid WMI classes when initializing c_network_team_windows
	c_winnetteam.init = func() {
		var dstTeamNic []MSFT_NetLbfoTeamNic
		var dstStats []MSFT_NetAdapterStatisticsSettingData
		queryTeamAdapter = wmi.CreateQuery(&dstTeamNic, "")
		queryTeamStats = wmi.CreateQuery(&dstStats, "")
		c_winnetteam.Enable = func() bool {
			errTeamNic := queryWmiNamespace(queryTeamAdapter, &dstTeamNic, namespaceStandardCimv2)
			errStats := queryWmiNamespace(queryTeamStats, &dstStats, namespaceStandardCimv2)
			result := errTeamNic == nil && errStats == nil
			return result
		}
	}
	collectors = append(collectors, c_winnetteam)
	c := &IntervalCollector{
		F: c_network_windows_tcp,
	}
	c.init = wmiInit(c, func() interface{} { return &[]Win32_PerfRawData_Tcpip_TCPv4{} }, "", &winNetTCPQuery)
	collectors = append(collectors, c)
}
예제 #3
0
func c_mssql_general(svc_dst []Win32_Service) (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint
	for _, w := range svc_dst {
		var dst []Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics
		q := wmi.CreateQuery(&dst, `WHERE Name <> '_Total'`)
		label := "mssqlserver"
		if w.Name != `MSSQLSERVER` {
			q = instanceWMIQuery(w.Name, q)
			label = strings.ToLower(w.Name[6:len(w.Name)])
		}
		if err := queryWmi(q, &dst); err != nil {
			return nil, err
		}
		for _, v := range dst {
			tags := opentsdb.TagSet{"instance": label}
			Add(&md, "mssql.user_connections", v.UserConnections, tags, metadata.Gauge, metadata.Count, descMSSQLUserConnections)
			Add(&md, "mssql.connection_resets", v.ConnectionResetPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLConnectionResetPersec)
			Add(&md, "mssql.logins", v.LoginsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLoginsPersec)
			Add(&md, "mssql.logouts", v.LogoutsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogoutsPersec)
			Add(&md, "mssql.mars_deadlocks", v.MarsDeadlocks, tags, metadata.Counter, metadata.Count, descMSSQLMarsDeadlocks)
			Add(&md, "mssql.proc_blocked", v.Processesblocked, tags, metadata.Gauge, metadata.Count, descMSSQLProcessesblocked)
			Add(&md, "mssql.temptables_created", v.TempTablesCreationRate, tags, metadata.Counter, metadata.PerSecond, descMSSQLTempTablesCreationRate)
			Add(&md, "mssql.temptables_to_destroy", v.TempTablesForDestruction, tags, metadata.Gauge, metadata.Count, descMSSQLTempTablesForDestruction)
			Add(&md, "mssql.transactions_total", v.Transactions, tags, metadata.Gauge, metadata.Count, descMSSQLTransactions)

		}
	}
	return md, nil
}
예제 #4
0
func getInfo() ([]Info, error) {
	var ret []Info
	var dst []win32.Win32_Processor

	q := wmi.CreateQuery(&dst, "")

	if err := wmi.Query(q, &dst); err != nil {
		return ret, err
	}

	fmt.Println("dst size: ", len(dst))

	var procID string
	for i, p := range dst {
		procID = ""
		if p.ProcessorId != nil {
			procID = *p.ProcessorId
		}

		cpu := Info{
			CPU:        int32(i),
			Family:     p.Family.String(),
			VendorId:   p.Manufacturer,
			ModelName:  p.Name,
			Cores:      int32(p.NumberOfLogicalProcessors),
			PhysicalId: procID,
			Mhz:        float64(p.MaxClockSpeed),
			Flags:      []string{},
		}
		ret = append(ret, cpu)
	}

	return ret, nil
}
예제 #5
0
func c_mssql_locks(svc_dst []Win32_Service) (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint
	for _, w := range svc_dst {
		var dst []Win32_PerfRawData_MSSQLSERVER_SQLServerLocks
		q := wmi.CreateQuery(&dst, `WHERE Name = 'Page' OR Name = 'Extent' OR Name = 'Object' or Name = 'Database'`)
		label := "mssqlserver"
		if w.Name != `MSSQLSERVER` {
			q = instanceWMIQuery(w.Name, q)
			label = strings.ToLower(w.Name[6:len(w.Name)])
		}
		err := queryWmi(q, &dst)
		if err != nil {
			return nil, err
		}
		for _, v := range dst {
			tags := opentsdb.TagSet{"instance": label, "type": v.Name}
			Add(&md, "mssql.lock_wait_time", v.AverageWaitTimems, tags, metadata.Counter, metadata.MilliSecond, descMSSQLAverageWaitTimems)
			Add(&md, "mssql.lock_requests", v.LockRequestsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLockRequestsPersec)
			Add(&md, "mssql.lock_timeouts", v.LockTimeoutsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLockTimeoutsPersec)
			Add(&md, "mssql.lock_timeouts0", v.LockTimeoutstimeout0Persec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLockTimeoutstimeout0Persec)
			Add(&md, "mssql.lock_waits", v.LockWaitsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLockWaitsPersec)
			Add(&md, "mssql.deadlocks", v.NumberofDeadlocksPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLNumberofDeadlocksPersec)
		}
	}
	return md, nil
}
예제 #6
0
func c_mssql_statistics(svc_dst []Win32_Service) (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint
	for _, w := range svc_dst {
		var dst []Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics
		q := wmi.CreateQuery(&dst, `WHERE Name <> '_Total'`)
		label := "mssqlserver"
		if w.Name != `MSSQLSERVER` {
			q = instanceWMIQuery(w.Name, q)
			label = strings.ToLower(w.Name[6:len(w.Name)])
		}
		err := queryWmi(q, &dst)
		if err != nil {
			return nil, err
		}
		for _, v := range dst {
			tags := opentsdb.TagSet{"instance": label}
			Add(&md, "mssql.autoparam_attempts", v.AutoParamAttemptsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLAutoParamAttemptsPersec)
			Add(&md, "mssql.autoparam_failed", v.FailedAutoParamsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLFailedAutoParamsPersec)
			Add(&md, "mssql.autoparam_forced", v.ForcedParameterizationsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLForcedParameterizationsPersec)
			Add(&md, "mssql.autoparam_safe", v.SafeAutoParamsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLSafeAutoParamsPersec)
			Add(&md, "mssql.autoparam_unsafe", v.UnsafeAutoParamsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLUnsafeAutoParamsPersec)
			Add(&md, "mssql.batches", v.BatchRequestsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLBatchRequestsPersec)
			Add(&md, "mssql.guided_plans", v.GuidedplanexecutionsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLGuidedplanexecutionsPersec)
			Add(&md, "mssql.misguided_plans", v.MisguidedplanexecutionsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLMisguidedplanexecutionsPersec)
			Add(&md, "mssql.compilations", v.SQLCompilationsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLSQLCompilationsPersec)
			Add(&md, "mssql.recompilations", v.SQLReCompilationsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLSQLReCompilationsPersec)
		}
	}
	return md, nil
}
예제 #7
0
func c_diskspace_windows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_LogicalDisk
	var q = wmi.CreateQuery(&dst, "WHERE DriveType = 3 AND FreeSpace <> null")
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		tags := opentsdb.TagSet{"disk": v.Name}
		space_used := v.Size - v.FreeSpace
		Add(&md, "win.disk.fs.space_free", v.FreeSpace, tags, metadata.Gauge, metadata.Bytes, osDiskFreeDesc)
		Add(&md, "win.disk.fs.space_total", v.Size, tags, metadata.Gauge, metadata.Bytes, osDiskTotalDesc)
		Add(&md, "win.disk.fs.space_used", space_used, tags, metadata.Gauge, metadata.Bytes, osDiskUsedDesc)
		Add(&md, osDiskFree, v.FreeSpace, tags, metadata.Gauge, metadata.Bytes, osDiskFreeDesc)
		Add(&md, osDiskTotal, v.Size, tags, metadata.Gauge, metadata.Bytes, osDiskTotalDesc)
		Add(&md, osDiskUsed, space_used, tags, metadata.Gauge, metadata.Bytes, osDiskUsedDesc)
		if v.Size != 0 {
			percent_free := float64(v.FreeSpace) / float64(v.Size) * 100
			Add(&md, "win.disk.fs.percent_free", percent_free, tags, metadata.Gauge, metadata.Pct, osDiskPctFreeDesc)
			Add(&md, osDiskPctFree, percent_free, tags, metadata.Gauge, metadata.Pct, osDiskPctFreeDesc)
		}
		if v.VolumeName != "" {
			metadata.AddMeta("", tags, "label", v.VolumeName, true)
		}
	}
	return md, nil
}
예제 #8
0
func Info() ([]InfoStat, error) {
	var ret []InfoStat
	var dst []Win32_Processor
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return ret, err
	}

	var procID string
	for i, l := range dst {
		procID = ""
		if l.ProcessorID != nil {
			procID = *l.ProcessorID
		}

		cpu := InfoStat{
			CPU:        int32(i),
			Family:     fmt.Sprintf("%d", l.Family),
			VendorID:   l.Manufacturer,
			ModelName:  l.Name,
			Cores:      int32(l.NumberOfLogicalProcessors),
			PhysicalID: procID,
			Mhz:        float64(l.MaxClockSpeed),
			Flags:      []string{},
		}
		ret = append(ret, cpu)
	}

	return ret, nil
}
예제 #9
0
func c_system_windows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_PerfOS_System
	var q = wmi.CreateQuery(&dst, "")
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		if v.Frequency_Object != 0 {
			//see http://microsoft.public.win32.programmer.wmi.narkive.com/09kqthVC/lastbootuptime
			var uptime = (v.Timestamp_Object - v.SystemUpTime) / v.Frequency_Object
			Add(&md, "win.system.uptime", uptime, nil, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
			Add(&md, osSystemUptime, uptime, nil, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
		}
		Add(&md, "win.system.context_switches", v.ContextSwitchesPersec, nil, metadata.Counter, metadata.ContextSwitch, descWinSystemContextSwitchesPersec)
		Add(&md, "win.system.exceptions", v.ExceptionDispatchesPersec, nil, metadata.Counter, metadata.PerSecond, descWinSystemExceptionDispatchesPersec)
		Add(&md, "win.system.cpu_queue", v.ProcessorQueueLength, nil, metadata.Gauge, metadata.Count, descWinSystemProcessorQueueLength)
		Add(&md, "win.system.syscall", v.SystemCallsPersec, nil, metadata.Counter, metadata.Syscall, descWinSystemSystemCallsPersec)
		Add(&md, "win.system.threads", v.Threads, nil, metadata.Gauge, metadata.Count, descWinSystemThreads)
		Add(&md, "win.system.processes", v.Processes, nil, metadata.Gauge, metadata.Count, descWinSystemProcesses)

	}
	return md, nil
}
예제 #10
0
func c_windows_memory() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_PerfOS_Memory
	var q = wmi.CreateQuery(&dst, "")
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		Add(&md, "win.mem.cache", v.CacheBytes, nil, metadata.Gauge, metadata.Bytes, descWinMemCacheBytes)
		Add(&md, "win.mem.cache_peak", v.CacheBytesPeak, nil, metadata.Gauge, metadata.Bytes, descWinMemCacheBytesPeak)
		Add(&md, "win.mem.committed", v.CommittedBytes, nil, metadata.Gauge, metadata.Bytes, descWinMemCommittedBytes)
		Add(&md, "win.mem.committed_limit", v.CommitLimit, nil, metadata.Gauge, metadata.Bytes, descWinMemCommitLimit)
		Add(&md, "win.mem.committed_percent", float64(v.PercentCommittedBytesInUse)/float64(v.PercentCommittedBytesInUse_Base)*100, nil, metadata.Gauge, metadata.Pct, descWinMemPercentCommittedBytesInUse)
		Add(&md, "win.mem.modified", v.ModifiedPageListBytes, nil, metadata.Gauge, metadata.Bytes, descWinMemModifiedPageListBytes)
		Add(&md, "win.mem.page_faults", v.PageFaultsPersec, nil, metadata.Counter, metadata.PerSecond, descWinMemPageFaultsPersec)
		Add(&md, "win.mem.faults", v.CacheFaultsPersec, opentsdb.TagSet{"type": "cache"}, metadata.Counter, metadata.PerSecond, descWinMemCacheFaultsPersec)
		Add(&md, "win.mem.faults", v.DemandZeroFaultsPersec, opentsdb.TagSet{"type": "demand_zero"}, metadata.Counter, metadata.PerSecond, descWinMemDemandZeroFaultsPersec)
		Add(&md, "win.mem.faults", v.TransitionFaultsPersec, opentsdb.TagSet{"type": "transition"}, metadata.Counter, metadata.PerSecond, descWinMemTransitionFaultsPersec)
		Add(&md, "win.mem.faults", v.WriteCopiesPersec, opentsdb.TagSet{"type": "write_copies"}, metadata.Counter, metadata.PerSecond, descWinMemWriteCopiesPersec)
		Add(&md, "win.mem.page_operations", v.PageReadsPersec, opentsdb.TagSet{"type": "read"}, metadata.Counter, metadata.PerSecond, descWinMemPageReadsPersec)
		Add(&md, "win.mem.page_operations", v.PageWritesPersec, opentsdb.TagSet{"type": "write"}, metadata.Counter, metadata.PerSecond, descWinMemPageWritesPersec)
		Add(&md, "win.mem.page_operations", v.PagesInputPersec, opentsdb.TagSet{"type": "input"}, metadata.Counter, metadata.PerSecond, descWinMemPagesInputPersec)
		Add(&md, "win.mem.page_operations", v.PagesOutputPersec, opentsdb.TagSet{"type": "output"}, metadata.Counter, metadata.PerSecond, descWinMemPagesOutputPersec)
		Add(&md, "win.mem.pool.bytes", v.PoolNonpagedBytes, opentsdb.TagSet{"type": "nonpaged"}, metadata.Gauge, metadata.Bytes, descWinMemPoolNonpagedBytes)
		Add(&md, "win.mem.pool.bytes", v.PoolPagedBytes, opentsdb.TagSet{"type": "paged"}, metadata.Gauge, metadata.Bytes, descWinMemPoolPagedBytes)
		Add(&md, "win.mem.pool.bytes", v.PoolPagedResidentBytes, opentsdb.TagSet{"type": "paged_resident"}, metadata.Gauge, metadata.Bytes, descWinMemPoolPagedResidentBytes)
		Add(&md, "win.mem.pool.allocations", v.PoolPagedAllocs, opentsdb.TagSet{"type": "paged"}, metadata.Gauge, metadata.Operation, descWinMemPoolPagedAllocs)
		Add(&md, "win.mem.pool.allocations", v.PoolNonpagedAllocs, opentsdb.TagSet{"type": "nonpaged"}, metadata.Gauge, metadata.Operation, descWinMemPoolNonpagedAllocs)
	}
	return md, nil
}
예제 #11
0
func wmiInitNamespace(c *IntervalCollector, dst func() interface{}, where string, query *string, namespace string) func() {
	return func() {
		*query = wmi.CreateQuery(dst(), where)
		c.Enable = func() bool {
			return queryWmiNamespace(*query, dst(), namespace) == nil
		}
	}
}
예제 #12
0
// winNetworkInit maintains a mapping of InstanceName to InterfaceIndex
func winNetworkInit() {
	update := func() {
		var dstNetworkAdapter []Win32_NetworkAdapter
		q := wmi.CreateQuery(&dstNetworkAdapter, "WHERE PhysicalAdapter=True and MACAddress <> null")
		err := queryWmi(q, &dstNetworkAdapter)
		if err != nil {
			slog.Error(err)
			return
		}
		for _, nic := range dstNetworkAdapter {
			var iface = fmt.Sprint("Interface", nic.InterfaceIndex)
			// Get PnPName using Win32_PnPEntity class
			var pnpname = ""
			var escapeddeviceid = strings.Replace(nic.PNPDeviceID, "\\", "\\\\", -1)
			var filter = fmt.Sprintf("WHERE DeviceID='%s'", escapeddeviceid)
			var dstPnPName []Win32_PnPEntity
			q = wmi.CreateQuery(&dstPnPName, filter)
			err = queryWmi(q, &dstPnPName)
			if err != nil {
				slog.Error(err)
				return
			}
			for _, pnp := range dstPnPName { // Really should be a single item
				pnpname = pnp.Name
			}
			if pnpname == "" {
				slog.Errorf("%s cannot find Win32_PnPEntity %s", iface, filter)
				continue
			}

			// Convert to instance name (see http://goo.gl/jfq6pq )
			instanceName := winNetworkToInstanceName(pnpname)
			mNicInstanceNameToInterfaceIndex[instanceName] = iface
		}
	}
	update()
	go func() {
		for range time.Tick(time.Minute * 5) {
			update()
		}
	}()
}
예제 #13
0
func c_meta_windows_version() (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint
	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		slog.Error(err)
		return md, err
	}

	var dstComputer []Win32_ComputerSystem
	q = wmi.CreateQuery(&dstComputer, "")
	err = wmi.Query(q, &dstComputer)
	if err != nil {
		slog.Error(err)
		return md, err
	}

	var dstBIOS []Win32_BIOS
	q = wmi.CreateQuery(&dstBIOS, "")
	err = wmi.Query(q, &dstBIOS)
	if err != nil {
		slog.Error(err)
		return md, err
	}

	for _, v := range dst {
		metadata.AddMeta("", nil, "version", v.Version, true)
		metadata.AddMeta("", nil, "versionCaption", v.Caption, true)
	}

	for _, v := range dstComputer {
		metadata.AddMeta("", nil, "manufacturer", v.Manufacturer, true)
		metadata.AddMeta("", nil, "model", v.Model, true)
		metadata.AddMeta("", nil, "memoryTotal", v.TotalPhysicalMemory, true)
	}

	for _, v := range dstBIOS {
		metadata.AddMeta("", nil, "serialNumber", v.SerialNumber, true)
	}
	return md, nil
}
예제 #14
0
func getComputerSystemStats() (stats []Stat) {
	var dst []Win32_ComputerSystem

	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		log.Fatalf("getComputerSystemStats: %s", err)
	}
	stats = append(stats, Stat{"mem.physical.total", strconv.FormatUint(dst[0].TotalPhysicalMemory, 10), time.Now().UTC()})
	return
}
예제 #15
0
파일: main.go 프로젝트: CodyGuo/Go-Cody
func main() {
	var dst []Win32_NetworkAdapter
	q := wmi.CreateQuery(&dst, "WHERE NetConnectionID != null")
	err := wmi.Query(q, &dst)
	if err != nil {
		log.Fatal(err)
	}
	for i, v := range dst {
		fmt.Printf("[%d] : Name:%s NetConnectionID:%s\n", i, v.Name, v.NetConnectionID)
	}
}
예제 #16
0
func BootTime() (uint64, error) {
	now := time.Now()

	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return 0, err
	}
	t := dst[0].LastBootUpTime.Local()
	return uint64(now.Sub(t).Seconds()), nil
}
예제 #17
0
func getWin32OperatingSystem() (Win32_OperatingSystem, error) {
	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return Win32_OperatingSystem{}, errors.Wrap(err, "wmi query for Win32_OperatingSystem failed")
	}
	if len(dst) != 1 {
		return Win32_OperatingSystem{}, errors.New("wmi query for Win32_OperatingSystem failed")
	}
	return dst[0], nil
}
예제 #18
0
func GetOSInfo() (Win32_OperatingSystem, error) {
	var dst []Win32_OperatingSystem
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return Win32_OperatingSystem{}, err
	}

	osInfo = &dst[0]

	return dst[0], nil
}
예제 #19
0
func GetWin32Proc(pid int32) ([]Win32_Process, error) {
	var dst []Win32_Process
	query := fmt.Sprintf("WHERE ProcessId = %d", pid)
	q := wmi.CreateQuery(&dst, query)
	err := wmi.Query(q, &dst)
	if err != nil {
		return []Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err)
	}
	if len(dst) != 1 {
		return []Win32_Process{}, fmt.Errorf("could not get win32Proc: empty")
	}
	return dst, nil
}
예제 #20
0
func (p *Process) Cmdline() (string, error) {
	var dst []Win32_Process
	query := fmt.Sprintf("WHERE ProcessId = %d", p.Pid)
	q := wmi.CreateQuery(&dst, query)
	err := wmi.Query(q, &dst)
	if err != nil {
		return "", err
	}
	if len(dst) != 1 {
		return "", fmt.Errorf("could not get CommandLine")
	}
	return *dst[0].CommandLine, nil
}
예제 #21
0
func (p *Process) NumThreads() (int32, error) {
	var dst []Win32_Process
	query := fmt.Sprintf("WHERE ProcessId = %d", p.Pid)
	q := wmi.CreateQuery(&dst, query)
	err := wmi.Query(q, &dst)
	if err != nil {
		return 0, err
	}
	if len(dst) != 1 {
		return 0, fmt.Errorf("could not get ThreadCount")
	}
	return int32(dst[0].ThreadCount), nil
}
예제 #22
0
func c_windows_process_total() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_PerfProc_Process
	var q = wmi.CreateQuery(&dst, `WHERE Name = '_Total'`)
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		Add(&md, "win.system.handle_count", v.HandleCount, nil, metadata.Gauge, metadata.Count, descWinSystemHandle_count)
	}
	return md, nil
}
예제 #23
0
func (p *Process) Exe() (string, error) {
	var dst []Win32_Process
	query := fmt.Sprintf("WHERE ProcessId = %d", p.Pid)
	q := wmi.CreateQuery(&dst, query)
	err := wmi.Query(q, &dst)
	if err != nil {
		return "", err
	}
	if len(dst) != 1 {
		return "", fmt.Errorf("could not get ExecutablePath")
	}
	return *dst[0].ExecutablePath, nil
}
예제 #24
0
func cHPEvaHostConnectionWindows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_EVAPMEXT_HPEVAHostConnection
	var q = wmi.CreateQuery(&dst, ``)
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, slog.Wrap(err)
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		Add(&md, "hp.eva.hostconnection.queuedepth", v.QueueDepth, opentsdb.TagSet{"evahost": v.Name}, metadata.Gauge, metadata.Count, descHostConnectionQueueDepth)
	}
	return md, nil
}
예제 #25
0
// getWin32Process gets information about the process with the given process ID.
// It uses a WMI query to get the information from the local system.
func getWin32Process(pid int32) (Win32_Process, error) {
	var dst []Win32_Process
	query := fmt.Sprintf("WHERE ProcessId = %d", pid)
	q := wmi.CreateQuery(&dst, query)
	err := wmi.Query(q, &dst)
	if err != nil {
		return Win32_Process{}, fmt.Errorf("could not get Win32_Process %s: %v", query, err)
	}
	if len(dst) < 1 {
		return Win32_Process{}, fmt.Errorf("could not get Win32_Process %s: Process not found", query)
	}
	return dst[0], nil
}
예제 #26
0
func c_mssql_replica_resources() (opentsdb.MultiDataPoint, error) {
	var dst []MSCluster_Resource
	//Only report metrics for resources owned by this node
	q := wmi.CreateQuery(&dst, fmt.Sprintf("WHERE OwnerNode = '%s'", util.Hostname))
	if err := queryWmiNamespace(q, &dst, rootMSCluster); err != nil {
		return nil, err
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		Add(&md, "mssql.replica.resource_state", v.State, opentsdb.TagSet{"group": v.OwnerGroup, "type": v.Type, "name": v.Name}, metadata.Gauge, metadata.StatusCode, descMSSQLReplicaResourceState)
	}
	return md, nil
}
예제 #27
0
func c_mssql_databases(svc_dst []Win32_Service) (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint
	for _, w := range svc_dst {
		var dst []Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases
		q := wmi.CreateQuery(&dst, `WHERE Name <> '_Total'`)
		label := "mssqlserver"
		if w.Name != `MSSQLSERVER` {
			q = instanceWMIQuery(w.Name, q)
			label = strings.ToLower(w.Name[6:len(w.Name)])
		}
		err := queryWmi(q, &dst)
		if err != nil {
			return nil, err
		}
		for _, v := range dst {
			tags := opentsdb.TagSet{"instance": label, "db": v.Name}
			Add(&md, "mssql.active_transactions", v.ActiveTransactions, tags, metadata.Gauge, metadata.Count, descMSSQLActiveTransactions)
			Add(&md, "mssql.backup_restore_throughput", v.BackupPerRestoreThroughputPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLBackupPerRestoreThroughputPersec)
			Add(&md, "mssql.bulkcopy_rows", v.BulkCopyRowsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLBulkCopyRowsPersec)
			Add(&md, "mssql.bulkcopy_throughput", v.BulkCopyThroughputPersec, tags, metadata.Counter, metadata.KBytes, descMSSQLBulkCopyThroughputPersec)
			Add(&md, "mssql.commit_table_entries", v.Committableentries, tags, metadata.Gauge, metadata.Count, descMSSQLCommittableentries)
			Add(&md, "mssql.data_files_size", v.DataFilesSizeKB*1024, tags, metadata.Gauge, metadata.Bytes, descMSSQLDataFilesSizeKB)
			Add(&md, "mssql.dbcc_logical_scan_bytes", v.DBCCLogicalScanBytesPersec, tags, metadata.Counter, metadata.BytesPerSecond, descMSSQLDBCCLogicalScanBytesPersec)
			//Add(&md, "mssql.group_commit_time", v.GroupCommitTimePersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLGroupCommitTimePersec)
			Add(&md, "mssql.log_bytes_flushed", v.LogBytesFlushedPersec, tags, metadata.Counter, metadata.BytesPerSecond, descMSSQLLogBytesFlushedPersec)
			Add(&md, "mssql.log_cache_hit_ratio", v.LogCacheHitRatio, tags, metadata.Counter, metadata.Pct, descMSSQLLogCacheHitRatio)
			Add(&md, "mssql.log_cache_hit_ratio_base", v.LogCacheHitRatio_Base, tags, metadata.Counter, metadata.None, descMSSQLLogCacheHitRatio_Base)
			Add(&md, "mssql.log_cache_reads", v.LogCacheReadsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogCacheReadsPersec)
			Add(&md, "mssql.log_files_size", v.LogFilesSizeKB*1024, tags, metadata.Gauge, metadata.Bytes, descMSSQLLogFilesSizeKB)
			Add(&md, "mssql.log_files_used_size", v.LogFilesUsedSizeKB*1024, tags, metadata.Gauge, metadata.Bytes, descMSSQLLogFilesUsedSizeKB)
			Add(&md, "mssql.log_flushes", v.LogFlushesPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogFlushesPersec)
			Add(&md, "mssql.log_flush_waits", v.LogFlushWaitsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogFlushWaitsPersec)
			Add(&md, "mssql.log_flush_wait_time", v.LogFlushWaitTime, tags, metadata.Counter, metadata.MilliSecond, descMSSQLLogFlushWaitTime)
			//Add(&md, "mssql.log_flush_write_time_ms", v.LogFlushWriteTimems, tags, metadata.Counter, metadata.MilliSecond, descMSSQLLogFlushWriteTimems)
			Add(&md, "mssql.log_growths", v.LogGrowths, tags, metadata.Gauge, metadata.Count, descMSSQLLogGrowths)
			//Add(&md, "mssql.log_pool_cache_misses", v.LogPoolCacheMissesPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogPoolCacheMissesPersec)
			//Add(&md, "mssql.log_pool_disk_reads", v.LogPoolDiskReadsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogPoolDiskReadsPersec)
			//Add(&md, "mssql.log_pool_requests", v.LogPoolRequestsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLLogPoolRequestsPersec)
			Add(&md, "mssql.log_shrinks", v.LogShrinks, tags, metadata.Gauge, metadata.Count, descMSSQLLogShrinks)
			Add(&md, "mssql.log_truncations", v.LogTruncations, tags, metadata.Gauge, metadata.Count, descMSSQLLogTruncations)
			Add(&md, "mssql.percent_log_used", v.PercentLogUsed, tags, metadata.Gauge, metadata.Pct, descMSSQLPercentLogUsed)
			Add(&md, "mssql.repl_pending_xacts", v.ReplPendingXacts, tags, metadata.Gauge, metadata.Count, descMSSQLReplPendingXacts)
			Add(&md, "mssql.repl_trans_rate", v.ReplTransRate, tags, metadata.Counter, metadata.PerSecond, descMSSQLReplTransRate)
			Add(&md, "mssql.shrink_data_movement_bytes", v.ShrinkDataMovementBytesPersec, tags, metadata.Counter, metadata.BytesPerSecond, descMSSQLShrinkDataMovementBytesPersec)
			Add(&md, "mssql.tracked_transactions", v.TrackedtransactionsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLTrackedtransactionsPersec)
			Add(&md, "mssql.transactions", v.TransactionsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLTransactionsPersec)
			Add(&md, "mssql.write_transactions", v.WriteTransactionsPersec, tags, metadata.Counter, metadata.PerSecond, descMSSQLWriteTransactionsPersec)
		}
	}
	return md, nil
}
예제 #28
0
파일: main.go 프로젝트: postfix/winnetspeed
func main() {
	err := termbox.Init()
	if err != nil {
		panic(err)
	}
	defer termbox.Close()

	event_queue := make(chan termbox.Event)
	go func() {
		for {
			event_queue <- termbox.PollEvent()
		}
	}()

	var dst []Win32_PerfFormattedData_Tcpip_NetworkInterface
	q := wmi.CreateQuery(&dst, `` /*`WHERE Name = "Realtek PCIe GBE Family Controller"`*/)

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()

	loop:
		for {
			select {
			case ev := <-event_queue:
				if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
					break loop
				}
			default:
				var d []Win32_PerfFormattedData_Tcpip_NetworkInterface
				err := wmi.Query(q, &d)
				if err != nil {
					panic(err)
				}

				termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
				y := 0
				for _, entry := range d {
					print(0, y, fmt.Sprintf("%s: recv: %s sent: %s", entry.Name, humanize.Bytes(uint64(entry.BytesReceivedPerSec)), humanize.Bytes(uint64(entry.BytesSentPerSec))))
					y++
				}
				termbox.Flush()

				<-time.After(time.Millisecond * 500)
			}
		}
	}()

	wg.Wait()
}
예제 #29
0
func cHPEvaStorageControllerWindows() (opentsdb.MultiDataPoint, error) {
	var dst []Win32_PerfRawData_EVAPMEXT_HPEVAStorageController
	var q = wmi.CreateQuery(&dst, ``)
	err := queryWmi(q, &dst)
	if err != nil {
		return nil, slog.Wrap(err)
	}
	var md opentsdb.MultiDataPoint
	for _, v := range dst {
		Add(&md, "hp.eva.storagecontroller.transfer", v.PercentDataTransferTime, opentsdb.TagSet{"controller": v.Name}, metadata.Gauge, metadata.Pct, descStoragePercentDataTransferTime)
		Add(&md, "hp.eva.storagecontroller.cpu", v.PercentProcessorTime, opentsdb.TagSet{"controller": v.Name}, metadata.Gauge, metadata.Pct, descStoragePercentProcessorTime)
	}
	return md, nil
}
예제 #30
0
func init() {
	var dst []Win32_PerfRawData_EVAPMEXT_HPEVAStorageArray
	var q = wmi.CreateQuery(&dst, ``)
	err := queryWmi(q, &dst)
	if err != nil {
		return // No HP EVA datasources found
	}
	collectors = append(collectors, &IntervalCollector{F: cHPEvaVirtualDiskWindows})
	collectors = append(collectors, &IntervalCollector{F: cHPEvaHostConnectionWindows})
	collectors = append(collectors, &IntervalCollector{F: cHPEvaStorageControllerWindows})
	collectors = append(collectors, &IntervalCollector{F: cHPEvaStorageArrayWindows})
	collectors = append(collectors, &IntervalCollector{F: cHPEvaHostPortWindows})
	collectors = append(collectors, &IntervalCollector{F: cHPEvaPhysicalDiskGroupWindows})
}