当前位置: 首页>>代码示例>>Golang>>正文


Golang wmi.Query函数代码示例

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


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


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