本文整理汇总了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
}
示例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
}
示例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
}
示例4: UpdateCpuStat
func UpdateCpuStat() error {
cpuStatLock.Lock()
defer cpuStatLock.Unlock()
err := wmi.Query(cpuStatQuery, &cpuStatHistory)
if err != nil {
return err
} else {
return nil
}
}
示例5: UpdateProcStat
func UpdateProcStat() error {
procStatLock.Lock()
defer procStatLock.Unlock()
err := wmi.Query(procStatQuery, &procStatHistory)
if err != nil {
return err
} else {
return nil
}
}
示例6: UpdateMemStat
func UpdateMemStat() error {
memStatLock.Lock()
defer memStatLock.Unlock()
err := wmi.Query(memStatQuery, &memStatHistory)
if err != nil {
return err
} else {
return nil
}
}
示例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
}
示例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
}
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}