• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang wmi.CreateQuery函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/StackExchange/wmi.CreateQuery函数的典型用法代码示例。如果您正苦于以下问题:Golang CreateQuery函数的具体用法?Golang CreateQuery怎么用?Golang CreateQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CreateQuery函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: init

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)
}
开发者ID:noblehng,项目名称:bosun,代码行数:27,代码来源:network_windows.go


示例2: allPartitions

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
}
开发者ID:entuerto,项目名称:sysmon,代码行数:33,代码来源:disk_windows.go


示例3: c_mssql_general

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:29,代码来源:sql_windows.go


示例4: getInfo

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
}
开发者ID:entuerto,项目名称:sysmon,代码行数:34,代码来源:cpu_windows.go


示例5: c_mssql_locks

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:26,代码来源:sql_windows.go


示例6: c_mssql_statistics

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:30,代码来源:sql_windows.go


示例7: c_diskspace_windows

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:28,代码来源:disk_windows.go


示例8: Info

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
}
开发者ID:ChongFeng,项目名称:beats,代码行数:31,代码来源:cpu_windows.go


示例9: c_system_windows

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
}
开发者ID:nicollet,项目名称:bosun,代码行数:25,代码来源:system_windows.go


示例10: c_windows_memory

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:32,代码来源:mem_windows.go


示例11: wmiInitNamespace

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
		}
	}
}
开发者ID:noblehng,项目名称:bosun,代码行数:8,代码来源:wmi_windows.go


示例12: winNetworkInit

// 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()
		}
	}()
}
开发者ID:noblehng,项目名称:bosun,代码行数:43,代码来源:network_windows.go


示例13: c_meta_windows_version

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
}
开发者ID:noblehng,项目名称:bosun,代码行数:42,代码来源:metadata_windows.go


示例14: getComputerSystemStats

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
}
开发者ID:halkeye,项目名称:go_windows_stats,代码行数:11,代码来源:main.go


示例15: main

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)
	}
}
开发者ID:CodyGuo,项目名称:Go-Cody,代码行数:11,代码来源:main.go


示例16: BootTime

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
}
开发者ID:avalente,项目名称:gopsutil,代码行数:12,代码来源:host_windows.go


示例17: getWin32OperatingSystem

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
}
开发者ID:andrewkroh,项目名称:beats,代码行数:12,代码来源:sigar_windows.go


示例18: GetOSInfo

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
}
开发者ID:archsaber,项目名称:gopsutil,代码行数:12,代码来源:host_windows.go


示例19: GetWin32Proc

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
}
开发者ID:dflupu,项目名称:gopsutil,代码行数:13,代码来源:process_windows.go


示例20: Cmdline

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
}
开发者ID:neutony,项目名称:gopsutil,代码行数:13,代码来源:process_windows.go



注:本文中的github.com/StackExchange/wmi.CreateQuery函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang wmi.Query函数代码示例发布时间:2022-05-28
下一篇:
Golang lib.Broker类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap