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

Golang wmi.Query函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: UpdateCpuStat

func UpdateCpuStat() error {
	cpuStatLock.Lock()
	defer cpuStatLock.Unlock()
	err := wmi.Query(cpuStatQuery, &cpuStatHistory)
	if err != nil {
		return err
	} else {
		return nil
	}
}
开发者ID:ZeaLoVe,项目名称:falcon-winAgent,代码行数:10,代码来源:cpustat.go


示例5: UpdateProcStat

func UpdateProcStat() error {
	procStatLock.Lock()
	defer procStatLock.Unlock()
	err := wmi.Query(procStatQuery, &procStatHistory)
	if err != nil {
		return err
	} else {
		return nil
	}
}
开发者ID:ZeaLoVe,项目名称:falcon-winAgent,代码行数:10,代码来源:proc.go


示例6: UpdateMemStat

func UpdateMemStat() error {
	memStatLock.Lock()
	defer memStatLock.Unlock()
	err := wmi.Query(memStatQuery, &memStatHistory)
	if err != nil {
		return err
	} else {
		return nil
	}
}
开发者ID:ZeaLoVe,项目名称:falcon-winAgent,代码行数:10,代码来源:memstat.go


示例7: 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


示例8: UpdateIfStat

func UpdateIfStat() error {
	ifStatLock.Lock()
	defer ifStatLock.Unlock()
	ifStatHistory = ifStatCurrent
	err := wmi.Query(ifStatQuery, &ifStatCurrent)
	if err != nil {
		return err
	} else {
		return nil
	}
}
开发者ID:ZeaLoVe,项目名称:falcon-winAgent,代码行数:11,代码来源:ifstat.go


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例13: 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


示例14: Exe

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


示例15: 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


示例16: NumThreads

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


示例17: getWin32Process

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


示例18: 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


示例19: main

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()
}
开发者ID:postfix,项目名称:winnetspeed,代码行数:51,代码来源:main.go


示例20: CPUPercent

func CPUPercent(interval time.Duration, percpu bool) ([]float64, error) {
	var ret []float64
	var dst []Win32_Processor
	q := wmi.CreateQuery(&dst, "")
	err := wmi.Query(q, &dst)
	if err != nil {
		return ret, err
	}
	for _, l := range dst {
		// use range but windows can only get one percent.
		ret = append(ret, float64(l.LoadPercentage)/100.0)
	}
	return ret, nil
}
开发者ID:neutony,项目名称:gopsutil,代码行数:14,代码来源:cpu_windows.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang dropbox.Dropbox类代码示例发布时间:2022-05-28
下一篇:
Golang wmi.CreateQuery函数代码示例发布时间: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