Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
coreospackage
Commits
40724686
Commit
40724686
authored
7 years ago
by
Sandeep S. Shewalkar
Browse files
Options
Downloads
Patches
Plain Diff
Diskdetails changes
wmic full path added in command
parent
563d2de7
Branches
DiskDetails_WMIC_RelativePath
1 merge request
!44
Diskdetails changes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diskdetailshelper/diskdetails.go
+11
-6
diskdetailshelper/diskdetails.go
diskdetailshelper/gopsutil/disk_windows.go
+8
-2
diskdetailshelper/gopsutil/disk_windows.go
with
19 additions
and
8 deletions
diskdetailshelper/diskdetails.go
+
11
−
6
View file @
40724686
...
@@ -3,6 +3,7 @@ package diskdetailshelper
...
@@ -3,6 +3,7 @@ package diskdetailshelper
import
(
import
(
"bytes"
"bytes"
"errors"
"errors"
"os"
"os/exec"
"os/exec"
"regexp"
"regexp"
"runtime"
"runtime"
...
@@ -19,6 +20,8 @@ import (
...
@@ -19,6 +20,8 @@ import (
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/mem"
)
)
const
WMIC_RELATIVE_PATH
=
"
\\
System32
\\
wbem
\\
wmic"
// UsageStat struct contains serial number and disk stats
// UsageStat struct contains serial number and disk stats
type
UsageStat
struct
{
type
UsageStat
struct
{
SerialNumber
string
`json:"serialNumber"`
SerialNumber
string
`json:"serialNumber"`
...
@@ -127,7 +130,8 @@ func AnalyseDisk() (UsageStat, error) {
...
@@ -127,7 +130,8 @@ func AnalyseDisk() (UsageStat, error) {
// GetDiskDetails returns disk details for windows OS
// GetDiskDetails returns disk details for windows OS
func
GetDiskDetails
()
([]
DiskStats
,
error
)
{
func
GetDiskDetails
()
([]
DiskStats
,
error
)
{
diskStats
:=
[]
DiskStats
{}
diskStats
:=
[]
DiskStats
{}
cmd
:=
exec
.
Command
(
"wmic"
)
windowsDirPath
:=
os
.
Getenv
(
"SYSTEMROOT"
)
cmd
:=
exec
.
Command
(
windowsDirPath
+
WMIC_RELATIVE_PATH
)
cmd
.
Stdin
=
strings
.
NewReader
(
"logicaldisk get caption,drivetype,freespace,size"
)
cmd
.
Stdin
=
strings
.
NewReader
(
"logicaldisk get caption,drivetype,freespace,size"
)
var
out
bytes
.
Buffer
var
out
bytes
.
Buffer
...
@@ -205,18 +209,19 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e
...
@@ -205,18 +209,19 @@ func GetCPUUtilizationPercent(interval time.Duration, percpu bool) ([]float64, e
// GetCPUPhysicalID returns CPU Physical ID or empty string
// GetCPUPhysicalID returns CPU Physical ID or empty string
func
GetCPUPhysicalID
()
(
string
,
error
)
{
func
GetCPUPhysicalID
()
(
string
,
error
)
{
cpuPhysicalID
:=
""
cpuPhysicalID
:=
""
o
s
:=
""
s
erverOS
:=
""
osInfo
,
err
:=
host
.
Info
()
osInfo
,
err
:=
host
.
Info
()
if
err
!=
nil
{
if
err
!=
nil
{
logginghelper
.
LogError
(
"error occured while getting OS details"
,
err
)
logginghelper
.
LogError
(
"error occured while getting OS details"
,
err
)
// return cpuPhysicalID, err
// return cpuPhysicalID, err
o
s
=
runtime
.
GOOS
s
erverOS
=
runtime
.
GOOS
}
else
{
}
else
{
o
s
=
osInfo
.
OS
s
erverOS
=
osInfo
.
OS
}
}
switch
o
s
{
switch
s
erverOS
{
case
"windows"
:
case
"windows"
:
cmd
:=
exec
.
Command
(
"wmic"
,
"CPU"
,
"get"
,
"ProcessorId"
)
windowsDirPath
:=
os
.
Getenv
(
"SYSTEMROOT"
)
cmd
:=
exec
.
Command
(
windowsDirPath
+
WMIC_RELATIVE_PATH
,
"CPU"
,
"get"
,
"ProcessorId"
)
// cmd.Stdin = strings.NewReader("CPU get ProcessorId")
// cmd.Stdin = strings.NewReader("CPU get ProcessorId")
var
out
bytes
.
Buffer
var
out
bytes
.
Buffer
...
...
This diff is collapsed.
Click to expand it.
diskdetailshelper/gopsutil/disk_windows.go
+
8
−
2
View file @
40724686
...
@@ -4,6 +4,7 @@ package gopsutil
...
@@ -4,6 +4,7 @@ package gopsutil
import
(
import
(
"bytes"
"bytes"
"os"
"regexp"
"regexp"
"unsafe"
"unsafe"
...
@@ -23,6 +24,8 @@ var (
...
@@ -23,6 +24,8 @@ var (
provGetVolumeInformation
=
Modkernel32
.
NewProc
(
"GetVolumeInformationW"
)
provGetVolumeInformation
=
Modkernel32
.
NewProc
(
"GetVolumeInformationW"
)
)
)
const
WMIC_RELATIVE_PATH
=
"
\\
System32
\\
wbem
\\
wmic"
var
(
var
(
FileFileCompression
=
int64
(
16
)
// 0x00000010
FileFileCompression
=
int64
(
16
)
// 0x00000010
FileReadOnlyVolume
=
int64
(
524288
)
// 0x00080000
FileReadOnlyVolume
=
int64
(
524288
)
// 0x00080000
...
@@ -197,8 +200,10 @@ func GetDiskSerialNumber(name string) string {
...
@@ -197,8 +200,10 @@ func GetDiskSerialNumber(name string) string {
serialNumberArray
:=
[]
string
{}
serialNumberArray
:=
[]
string
{}
serialNumberMap
:=
make
(
map
[
string
]
bool
)
serialNumberMap
:=
make
(
map
[
string
]
bool
)
windowsDirPath
:=
os
.
Getenv
(
"SYSTEMROOT"
)
cmd1
:=
&
exec
.
Cmd
{}
cmd1
:=
&
exec
.
Cmd
{}
cmd1
=
exec
.
Command
(
"wmic"
,
"path"
,
"win32_physicalmedia"
,
"get"
,
"SerialNumber"
)
cmd1
=
exec
.
Command
(
windowsDirPath
+
WMIC_RELATIVE_PATH
,
"path"
,
"win32_physicalmedia"
,
"get"
,
"SerialNumber"
)
var
out1
bytes
.
Buffer
var
out1
bytes
.
Buffer
cmd1
.
Stdout
=
&
out1
cmd1
.
Stdout
=
&
out1
commandError
:=
cmd1
.
Run
()
commandError
:=
cmd1
.
Run
()
...
@@ -217,7 +222,8 @@ func GetDiskSerialNumber(name string) string {
...
@@ -217,7 +222,8 @@ func GetDiskSerialNumber(name string) string {
}
}
cmd2
:=
&
exec
.
Cmd
{}
cmd2
:=
&
exec
.
Cmd
{}
cmd2
=
exec
.
Command
(
"wmic"
,
"diskdrive"
,
"get"
,
"serialnumber"
)
cmd2
=
exec
.
Command
(
windowsDirPath
+
WMIC_RELATIVE_PATH
,
"diskdrive"
,
"get"
,
"serialnumber"
)
var
out2
bytes
.
Buffer
var
out2
bytes
.
Buffer
cmd2
.
Stdout
=
&
out2
cmd2
.
Stdout
=
&
out2
commandError
=
cmd2
.
Run
()
commandError
=
cmd2
.
Run
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets