mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
JSON representation is renamed to fit Google JSON style, camelCase.
This commit is contained in:
parent
46ddd57c72
commit
4bb84648bf
@ -19,6 +19,12 @@ psutil functions on some architectures...
|
|||||||
We introduced versioning by using gopkgin. And breaking changes will be introduced at v2. See `issue 174 <https://github.com/shirou/gopsutil/issues/174>`_ .
|
We introduced versioning by using gopkgin. And breaking changes will be introduced at v2. See `issue 174 <https://github.com/shirou/gopsutil/issues/174>`_ .
|
||||||
|
|
||||||
|
|
||||||
|
Migrating to v2
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
On gopsutil itself, `v2migration.sh <https://github.com/shirou/gopsutil/blob/v2/v2migration.sh>`_ is used for migration. It can not be commly used, but it may help to your migration.
|
||||||
|
|
||||||
|
|
||||||
Available Architectures
|
Available Architectures
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
|
||||||
|
14
cpu/cpu.go
14
cpu/cpu.go
@ -18,22 +18,22 @@ type TimesStat struct {
|
|||||||
Softirq float64 `json:"softirq"`
|
Softirq float64 `json:"softirq"`
|
||||||
Steal float64 `json:"steal"`
|
Steal float64 `json:"steal"`
|
||||||
Guest float64 `json:"guest"`
|
Guest float64 `json:"guest"`
|
||||||
GuestNice float64 `json:"guest_nice"`
|
GuestNice float64 `json:"guestNice"`
|
||||||
Stolen float64 `json:"stolen"`
|
Stolen float64 `json:"stolen"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfoStat struct {
|
type InfoStat struct {
|
||||||
CPU int32 `json:"cpu"`
|
CPU int32 `json:"cpu"`
|
||||||
VendorID string `json:"vendor_id"`
|
VendorID string `json:"vendorId"`
|
||||||
Family string `json:"family"`
|
Family string `json:"family"`
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Stepping int32 `json:"stepping"`
|
Stepping int32 `json:"stepping"`
|
||||||
PhysicalID string `json:"physical_id"`
|
PhysicalID string `json:"physicalId"`
|
||||||
CoreID string `json:"core_id"`
|
CoreID string `json:"coreId"`
|
||||||
Cores int32 `json:"cores"`
|
Cores int32 `json:"cores"`
|
||||||
ModelName string `json:"model_name"`
|
ModelName string `json:"modelName"`
|
||||||
Mhz float64 `json:"mhz"`
|
Mhz float64 `json:"mhz"`
|
||||||
CacheSize int32 `json:"cache_size"`
|
CacheSize int32 `json:"cacheSize"`
|
||||||
Flags []string `json:"flags"`
|
Flags []string `json:"flags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ func (c TimesStat) String() string {
|
|||||||
`"softirq":` + strconv.FormatFloat(c.Softirq, 'f', 1, 64),
|
`"softirq":` + strconv.FormatFloat(c.Softirq, 'f', 1, 64),
|
||||||
`"steal":` + strconv.FormatFloat(c.Steal, 'f', 1, 64),
|
`"steal":` + strconv.FormatFloat(c.Steal, 'f', 1, 64),
|
||||||
`"guest":` + strconv.FormatFloat(c.Guest, 'f', 1, 64),
|
`"guest":` + strconv.FormatFloat(c.Guest, 'f', 1, 64),
|
||||||
`"guest_nice":` + strconv.FormatFloat(c.GuestNice, 'f', 1, 64),
|
`"guestNice":` + strconv.FormatFloat(c.GuestNice, 'f', 1, 64),
|
||||||
`"stolen":` + strconv.FormatFloat(c.Stolen, 'f', 1, 64),
|
`"stolen":` + strconv.FormatFloat(c.Stolen, 'f', 1, 64),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func finishCPUInfo(c *InfoStat) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(c.CoreID) == 0 {
|
if len(c.CoreID) == 0 {
|
||||||
lines, err := common.ReadLines(sysCpuPath(c.CPU, "topology/core_id"))
|
lines, err := common.ReadLines(sysCpuPath(c.CPU, "topology/coreId"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.CoreID = lines[0]
|
c.CoreID = lines[0]
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ func Info() ([]InfoStat, error) {
|
|||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
c.CPU = int32(t)
|
c.CPU = int32(t)
|
||||||
case "vendor_id":
|
case "vendorId":
|
||||||
c.VendorID = value
|
c.VendorID = value
|
||||||
case "cpu family":
|
case "cpu family":
|
||||||
c.Family = value
|
c.Family = value
|
||||||
|
@ -41,7 +41,7 @@ func TestCPUTimeStat_String(t *testing.T) {
|
|||||||
System: 200.1,
|
System: 200.1,
|
||||||
Idle: 300.1,
|
Idle: 300.1,
|
||||||
}
|
}
|
||||||
e := `{"cpu":"cpu0","user":100.1,"system":200.1,"idle":300.1,"nice":0.0,"iowait":0.0,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guest_nice":0.0,"stolen":0.0}`
|
e := `{"cpu":"cpu0","user":100.1,"system":200.1,"idle":300.1,"nice":0.0,"iowait":0.0,"irq":0.0,"softirq":0.0,"steal":0.0,"guest":0.0,"guestNice":0.0,"stolen":0.0}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("CPUTimesStat string is invalid: %v", v)
|
t.Errorf("CPUTimesStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
|
26
disk/disk.go
26
disk/disk.go
@ -10,11 +10,11 @@ type UsageStat struct {
|
|||||||
Total uint64 `json:"total"`
|
Total uint64 `json:"total"`
|
||||||
Free uint64 `json:"free"`
|
Free uint64 `json:"free"`
|
||||||
Used uint64 `json:"used"`
|
Used uint64 `json:"used"`
|
||||||
UsedPercent float64 `json:"used_percent"`
|
UsedPercent float64 `json:"usedPercent"`
|
||||||
InodesTotal uint64 `json:"inodes_total"`
|
InodesTotal uint64 `json:"inodesTotal"`
|
||||||
InodesUsed uint64 `json:"inodes_used"`
|
InodesUsed uint64 `json:"inodesUsed"`
|
||||||
InodesFree uint64 `json:"inodes_free"`
|
InodesFree uint64 `json:"inodesFree"`
|
||||||
InodesUsedPercent float64 `json:"inodes_used_percent"`
|
InodesUsedPercent float64 `json:"inodesUsedPercent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PartitionStat struct {
|
type PartitionStat struct {
|
||||||
@ -25,15 +25,15 @@ type PartitionStat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IOCountersStat struct {
|
type IOCountersStat struct {
|
||||||
ReadCount uint64 `json:"read_count"`
|
ReadCount uint64 `json:"readCount"`
|
||||||
WriteCount uint64 `json:"write_count"`
|
WriteCount uint64 `json:"writeCount"`
|
||||||
ReadBytes uint64 `json:"read_bytes"`
|
ReadBytes uint64 `json:"readBytes"`
|
||||||
WriteBytes uint64 `json:"write_bytes"`
|
WriteBytes uint64 `json:"writeBytes"`
|
||||||
ReadTime uint64 `json:"read_time"`
|
ReadTime uint64 `json:"readTime"`
|
||||||
WriteTime uint64 `json:"write_time"`
|
WriteTime uint64 `json:"writeTime"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
IoTime uint64 `json:"io_time"`
|
IoTime uint64 `json:"ioTime"`
|
||||||
SerialNumber string `json:"serial_number"`
|
SerialNumber string `json:"serialNumber"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d UsageStat) String() string {
|
func (d UsageStat) String() string {
|
||||||
|
@ -62,7 +62,7 @@ func TestDiskUsageStat_String(t *testing.T) {
|
|||||||
InodesUsedPercent: 49.1,
|
InodesUsedPercent: 49.1,
|
||||||
Fstype: "ext4",
|
Fstype: "ext4",
|
||||||
}
|
}
|
||||||
e := `{"path":"/","fstype":"ext4","total":1000,"free":2000,"used":3000,"used_percent":50.1,"inodes_total":4000,"inodes_used":5000,"inodes_free":6000,"inodes_used_percent":49.1}`
|
e := `{"path":"/","fstype":"ext4","total":1000,"free":2000,"used":3000,"usedPercent":50.1,"inodesTotal":4000,"inodesUsed":5000,"inodesFree":6000,"inodesUsedPercent":49.1}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("DiskUsageStat string is invalid: %v", v)
|
t.Errorf("DiskUsageStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func TestDiskIOCountersStat_String(t *testing.T) {
|
|||||||
WriteBytes: 400,
|
WriteBytes: 400,
|
||||||
SerialNumber: "SERIAL",
|
SerialNumber: "SERIAL",
|
||||||
}
|
}
|
||||||
e := `{"read_count":100,"write_count":200,"read_bytes":300,"write_bytes":400,"read_time":0,"write_time":0,"name":"sd01","io_time":0,"serial_number":"SERIAL"}`
|
e := `{"readCount":100,"writeCount":200,"readBytes":300,"writeBytes":400,"readTime":0,"writeTime":0,"name":"sd01","ioTime":0,"serialNumber":"SERIAL"}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("DiskUsageStat string is invalid: %v", v)
|
t.Errorf("DiskUsageStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
|
@ -6,36 +6,36 @@ var ErrDockerNotAvailable = errors.New("docker not available")
|
|||||||
var ErrCgroupNotAvailable = errors.New("cgroup not available")
|
var ErrCgroupNotAvailable = errors.New("cgroup not available")
|
||||||
|
|
||||||
type CgroupMemStat struct {
|
type CgroupMemStat struct {
|
||||||
ContainerID string `json:"container_id"`
|
ContainerID string `json:"containerID"`
|
||||||
Cache uint64 `json:"cache"`
|
Cache uint64 `json:"cache"`
|
||||||
RSS uint64 `json:"rss"`
|
RSS uint64 `json:"rss"`
|
||||||
RSSHuge uint64 `json:"rss_huge"`
|
RSSHuge uint64 `json:"rssHuge"`
|
||||||
MappedFile uint64 `json:"mapped_file"`
|
MappedFile uint64 `json:"mappedFile"`
|
||||||
Pgpgin uint64 `json:"pgpgin"`
|
Pgpgin uint64 `json:"pgpgin"`
|
||||||
Pgpgout uint64 `json:"pgpgout"`
|
Pgpgout uint64 `json:"pgpgout"`
|
||||||
Pgfault uint64 `json:"pgfault"`
|
Pgfault uint64 `json:"pgfault"`
|
||||||
Pgmajfault uint64 `json:"pgmajfault"`
|
Pgmajfault uint64 `json:"pgmajfault"`
|
||||||
InactiveAnon uint64 `json:"inactive_anon"`
|
InactiveAnon uint64 `json:"inactiveAnon"`
|
||||||
ActiveAnon uint64 `json:"active_anon"`
|
ActiveAnon uint64 `json:"activeAnon"`
|
||||||
InactiveFile uint64 `json:"inactive_file"`
|
InactiveFile uint64 `json:"inactiveFile"`
|
||||||
ActiveFile uint64 `json:"active_file"`
|
ActiveFile uint64 `json:"activeFile"`
|
||||||
Unevictable uint64 `json:"unevictable"`
|
Unevictable uint64 `json:"unevictable"`
|
||||||
HierarchicalMemoryLimit uint64 `json:"hierarchical_memory_limit"`
|
HierarchicalMemoryLimit uint64 `json:"hierarchicalMemoryLimit"`
|
||||||
TotalCache uint64 `json:"total_cache"`
|
TotalCache uint64 `json:"totalCache"`
|
||||||
TotalRSS uint64 `json:"total_rss"`
|
TotalRSS uint64 `json:"totalRss"`
|
||||||
TotalRSSHuge uint64 `json:"total_rss_huge"`
|
TotalRSSHuge uint64 `json:"totalRssHuge"`
|
||||||
TotalMappedFile uint64 `json:"total_mapped_file"`
|
TotalMappedFile uint64 `json:"totalMappedFile"`
|
||||||
TotalPgpgIn uint64 `json:"total_pgpgin"`
|
TotalPgpgIn uint64 `json:"totalPgpgin"`
|
||||||
TotalPgpgOut uint64 `json:"total_pgpgout"`
|
TotalPgpgOut uint64 `json:"totalPgpgout"`
|
||||||
TotalPgFault uint64 `json:"total_pgfault"`
|
TotalPgFault uint64 `json:"totalPgfault"`
|
||||||
TotalPgMajFault uint64 `json:"total_pgmajfault"`
|
TotalPgMajFault uint64 `json:"totalPgmajfault"`
|
||||||
TotalInactiveAnon uint64 `json:"total_inactive_anon"`
|
TotalInactiveAnon uint64 `json:"totalInactiveAnon"`
|
||||||
TotalActiveAnon uint64 `json:"total_active_anon"`
|
TotalActiveAnon uint64 `json:"totalActiveAnon"`
|
||||||
TotalInactiveFile uint64 `json:"total_inactive_file"`
|
TotalInactiveFile uint64 `json:"totalInactiveFile"`
|
||||||
TotalActiveFile uint64 `json:"total_active_file"`
|
TotalActiveFile uint64 `json:"totalActiveFile"`
|
||||||
TotalUnevictable uint64 `json:"total_unevictable"`
|
TotalUnevictable uint64 `json:"totalUnevictable"`
|
||||||
MemUsageInBytes uint64 `json:"mem_usage_in_bytes"`
|
MemUsageInBytes uint64 `json:"memUsageInBytes"`
|
||||||
MemMaxUsageInBytes uint64 `json:"mem_max_usage_in_bytes"`
|
MemMaxUsageInBytes uint64 `json:"memMaxUsageInBytes"`
|
||||||
MemLimitInBytes uint64 `json:"memory.limit_in_bytes"`
|
MemLimitInBytes uint64 `json:"memoryLimitInBbytes"`
|
||||||
MemFailCnt uint64 `json:"memory.failcnt"`
|
MemFailCnt uint64 `json:"memoryFailcnt"`
|
||||||
}
|
}
|
||||||
|
@ -101,9 +101,9 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
|
|||||||
ret.Cache = v
|
ret.Cache = v
|
||||||
case "rss":
|
case "rss":
|
||||||
ret.RSS = v
|
ret.RSS = v
|
||||||
case "rss_huge":
|
case "rssHuge":
|
||||||
ret.RSSHuge = v
|
ret.RSSHuge = v
|
||||||
case "mapped_file":
|
case "mappedFile":
|
||||||
ret.MappedFile = v
|
ret.MappedFile = v
|
||||||
case "pgpgin":
|
case "pgpgin":
|
||||||
ret.Pgpgin = v
|
ret.Pgpgin = v
|
||||||
@ -113,43 +113,43 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
|
|||||||
ret.Pgfault = v
|
ret.Pgfault = v
|
||||||
case "pgmajfault":
|
case "pgmajfault":
|
||||||
ret.Pgmajfault = v
|
ret.Pgmajfault = v
|
||||||
case "inactive_anon":
|
case "inactiveAnon":
|
||||||
ret.InactiveAnon = v
|
ret.InactiveAnon = v
|
||||||
case "active_anon":
|
case "activeAnon":
|
||||||
ret.ActiveAnon = v
|
ret.ActiveAnon = v
|
||||||
case "inactive_file":
|
case "inactiveFile":
|
||||||
ret.InactiveFile = v
|
ret.InactiveFile = v
|
||||||
case "active_file":
|
case "activeFile":
|
||||||
ret.ActiveFile = v
|
ret.ActiveFile = v
|
||||||
case "unevictable":
|
case "unevictable":
|
||||||
ret.Unevictable = v
|
ret.Unevictable = v
|
||||||
case "hierarchical_memory_limit":
|
case "hierarchicalMemoryLimit":
|
||||||
ret.HierarchicalMemoryLimit = v
|
ret.HierarchicalMemoryLimit = v
|
||||||
case "total_cache":
|
case "totalCache":
|
||||||
ret.TotalCache = v
|
ret.TotalCache = v
|
||||||
case "total_rss":
|
case "totalRss":
|
||||||
ret.TotalRSS = v
|
ret.TotalRSS = v
|
||||||
case "total_rss_huge":
|
case "totalRssHuge":
|
||||||
ret.TotalRSSHuge = v
|
ret.TotalRSSHuge = v
|
||||||
case "total_mapped_file":
|
case "totalMappedFile":
|
||||||
ret.TotalMappedFile = v
|
ret.TotalMappedFile = v
|
||||||
case "total_pgpgin":
|
case "totalPgpgin":
|
||||||
ret.TotalPgpgIn = v
|
ret.TotalPgpgIn = v
|
||||||
case "total_pgpgout":
|
case "totalPgpgout":
|
||||||
ret.TotalPgpgOut = v
|
ret.TotalPgpgOut = v
|
||||||
case "total_pgfault":
|
case "totalPgfault":
|
||||||
ret.TotalPgFault = v
|
ret.TotalPgFault = v
|
||||||
case "total_pgmajfault":
|
case "totalPgmajfault":
|
||||||
ret.TotalPgMajFault = v
|
ret.TotalPgMajFault = v
|
||||||
case "total_inactive_anon":
|
case "totalInactiveAnon":
|
||||||
ret.TotalInactiveAnon = v
|
ret.TotalInactiveAnon = v
|
||||||
case "total_active_anon":
|
case "totalActiveAnon":
|
||||||
ret.TotalActiveAnon = v
|
ret.TotalActiveAnon = v
|
||||||
case "total_inactive_file":
|
case "totalInactiveFile":
|
||||||
ret.TotalInactiveFile = v
|
ret.TotalInactiveFile = v
|
||||||
case "total_active_file":
|
case "totalActiveFile":
|
||||||
ret.TotalActiveFile = v
|
ret.TotalActiveFile = v
|
||||||
case "total_unevictable":
|
case "totalUnevictable":
|
||||||
ret.TotalUnevictable = v
|
ret.TotalUnevictable = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -162,11 +162,11 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
ret.MemMaxUsageInBytes = r
|
ret.MemMaxUsageInBytes = r
|
||||||
}
|
}
|
||||||
r, err = getCgroupMemFile(containerId, base, "memory.limit_in_bytes")
|
r, err = getCgroupMemFile(containerId, base, "memoryLimitInBbytes")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.MemLimitInBytes = r
|
ret.MemLimitInBytes = r
|
||||||
}
|
}
|
||||||
r, err = getCgroupMemFile(containerId, base, "memory.failcnt")
|
r, err = getCgroupMemFile(containerId, base, "memoryFailcnt")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.MemFailCnt = r
|
ret.MemFailCnt = r
|
||||||
}
|
}
|
||||||
|
10
host/host.go
10
host/host.go
@ -9,14 +9,14 @@ import (
|
|||||||
type InfoStat struct {
|
type InfoStat struct {
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Uptime uint64 `json:"uptime"`
|
Uptime uint64 `json:"uptime"`
|
||||||
BootTime uint64 `json:"boot_time"`
|
BootTime uint64 `json:"bootTime"`
|
||||||
Procs uint64 `json:"procs"` // number of processes
|
Procs uint64 `json:"procs"` // number of processes
|
||||||
OS string `json:"os"` // ex: freebsd, linux
|
OS string `json:"os"` // ex: freebsd, linux
|
||||||
Platform string `json:"platform"` // ex: ubuntu, linuxmint
|
Platform string `json:"platform"` // ex: ubuntu, linuxmint
|
||||||
PlatformFamily string `json:"platform_family"` // ex: debian, rhel
|
PlatformFamily string `json:"platformFamily"` // ex: debian, rhel
|
||||||
PlatformVersion string `json:"platform_version"`
|
PlatformVersion string `json:"platformVersion"`
|
||||||
VirtualizationSystem string `json:"virtualization_system"`
|
VirtualizationSystem string `json:"virtualizationSystem"`
|
||||||
VirtualizationRole string `json:"virtualization_role"` // guest or host
|
VirtualizationRole string `json:"virtualizationRole"` // guest or host
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func TestHostInfoStat_String(t *testing.T) {
|
|||||||
Platform: "ubuntu",
|
Platform: "ubuntu",
|
||||||
BootTime: 1447040000,
|
BootTime: 1447040000,
|
||||||
}
|
}
|
||||||
e := `{"hostname":"test","uptime":3000,"boot_time":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platform_family":"","platform_version":"","virtualization_system":"","virtualization_role":""}`
|
e := `{"hostname":"test","uptime":3000,"bootTime":1447040000,"procs":100,"os":"linux","platform":"ubuntu","platformFamily":"","platformVersion":"","virtualizationSystem":"","virtualizationRole":""}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("HostInfoStat string is invalid: %v", v)
|
t.Errorf("HostInfoStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ type VirtualMemoryStat struct {
|
|||||||
// Percentage of RAM used by programs
|
// Percentage of RAM used by programs
|
||||||
//
|
//
|
||||||
// This value is computed from the kernel specific values.
|
// This value is computed from the kernel specific values.
|
||||||
UsedPercent float64 `json:"used_percent"`
|
UsedPercent float64 `json:"usedPercent"`
|
||||||
|
|
||||||
// This is the kernel's notion of free memory; RAM chips whose bits nobody
|
// This is the kernel's notion of free memory; RAM chips whose bits nobody
|
||||||
// cares about the value of right now. For a human consumable number,
|
// cares about the value of right now. For a human consumable number,
|
||||||
@ -48,7 +48,7 @@ type SwapMemoryStat struct {
|
|||||||
Total uint64 `json:"total"`
|
Total uint64 `json:"total"`
|
||||||
Used uint64 `json:"used"`
|
Used uint64 `json:"used"`
|
||||||
Free uint64 `json:"free"`
|
Free uint64 `json:"free"`
|
||||||
UsedPercent float64 `json:"used_percent"`
|
UsedPercent float64 `json:"usedPercent"`
|
||||||
Sin uint64 `json:"sin"`
|
Sin uint64 `json:"sin"`
|
||||||
Sout uint64 `json:"sout"`
|
Sout uint64 `json:"sout"`
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func TestVirtualMemoryStat_String(t *testing.T) {
|
|||||||
UsedPercent: 30.1,
|
UsedPercent: 30.1,
|
||||||
Free: 40,
|
Free: 40,
|
||||||
}
|
}
|
||||||
e := `{"total":10,"available":20,"used":30,"used_percent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"buffers":0,"cached":0}`
|
e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"buffers":0,"cached":0}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("VirtualMemoryStat string is invalid: %v", v)
|
t.Errorf("VirtualMemoryStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ func TestSwapMemoryStat_String(t *testing.T) {
|
|||||||
Free: 40,
|
Free: 40,
|
||||||
UsedPercent: 30.1,
|
UsedPercent: 30.1,
|
||||||
}
|
}
|
||||||
e := `{"total":10,"used":30,"free":40,"used_percent":30.1,"sin":0,"sout":0}`
|
e := `{"total":10,"used":30,"free":40,"usedPercent":30.1,"sin":0,"sout":0}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("SwapMemoryStat string is invalid: %v", v)
|
t.Errorf("SwapMemoryStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
|
12
net/net.go
12
net/net.go
@ -19,10 +19,10 @@ func init() {
|
|||||||
|
|
||||||
type IOCountersStat struct {
|
type IOCountersStat struct {
|
||||||
Name string `json:"name"` // interface name
|
Name string `json:"name"` // interface name
|
||||||
BytesSent uint64 `json:"bytes_sent"` // number of bytes sent
|
BytesSent uint64 `json:"bytesSent"` // number of bytes sent
|
||||||
BytesRecv uint64 `json:"bytes_recv"` // number of bytes received
|
BytesRecv uint64 `json:"bytesRecv"` // number of bytes received
|
||||||
PacketsSent uint64 `json:"packets_sent"` // number of packets sent
|
PacketsSent uint64 `json:"packetsSent"` // number of packets sent
|
||||||
PacketsRecv uint64 `json:"packets_recv"` // number of packets received
|
PacketsRecv uint64 `json:"packetsRecv"` // number of packets received
|
||||||
Errin uint64 `json:"errin"` // total number of errors while receiving
|
Errin uint64 `json:"errin"` // total number of errors while receiving
|
||||||
Errout uint64 `json:"errout"` // total number of errors while sending
|
Errout uint64 `json:"errout"` // total number of errors while sending
|
||||||
Dropin uint64 `json:"dropin"` // total number of incoming packets which were dropped
|
Dropin uint64 `json:"dropin"` // total number of incoming packets which were dropped
|
||||||
@ -65,8 +65,8 @@ type InterfaceStat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FilterStat struct {
|
type FilterStat struct {
|
||||||
ConnTrackCount int64 `json:"conntrack_count"`
|
ConnTrackCount int64 `json:"conntrackCount"`
|
||||||
ConnTrackMax int64 `json:"conntrack_max"`
|
ConnTrackMax int64 `json:"conntrackMax"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var constMap = map[string]int{
|
var constMap = map[string]int{
|
||||||
|
@ -175,8 +175,8 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
|
|||||||
// the currently in use conntrack count and the max.
|
// the currently in use conntrack count and the max.
|
||||||
// If the file does not exist or is invalid it will return nil.
|
// If the file does not exist or is invalid it will return nil.
|
||||||
func FilterCounters() ([]FilterStat, error) {
|
func FilterCounters() ([]FilterStat, error) {
|
||||||
countfile := common.HostProc("sys/net/netfilter/nf_conntrack_count")
|
countfile := common.HostProc("sys/net/netfilter/nf_conntrackCount")
|
||||||
maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max")
|
maxfile := common.HostProc("sys/net/netfilter/nf_conntrackMax")
|
||||||
|
|
||||||
count, err := common.ReadInts(countfile)
|
count, err := common.ReadInts(countfile)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func TestNetIOCountersStatString(t *testing.T) {
|
|||||||
Name: "test",
|
Name: "test",
|
||||||
BytesSent: 100,
|
BytesSent: 100,
|
||||||
}
|
}
|
||||||
e := `{"name":"test","bytes_sent":100,"bytes_recv":0,"packets_sent":0,"packets_recv":0,"errin":0,"errout":0,"dropin":0,"dropout":0}`
|
e := `{"name":"test","bytesSent":100,"bytesRecv":0,"packetsSent":0,"packetsRecv":0,"errin":0,"errout":0,"dropin":0,"dropout":0}`
|
||||||
if e != fmt.Sprintf("%v", v) {
|
if e != fmt.Sprintf("%v", v) {
|
||||||
t.Errorf("NetIOCountersStat string is invalid: %v", v)
|
t.Errorf("NetIOCountersStat string is invalid: %v", v)
|
||||||
}
|
}
|
||||||
@ -207,7 +207,7 @@ func TestNetFilterCounters(t *testing.T) {
|
|||||||
|
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
// some test environment has not the path.
|
// some test environment has not the path.
|
||||||
if !common.PathExists("/proc/sys/net/netfilter/nf_conntrack_count") {
|
if !common.PathExists("/proc/sys/net/netfilter/nf_conntrackCount") {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ func TestNetFilterCounters(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, vv := range v {
|
for _, vv := range v {
|
||||||
if vv.ConnTrackMax == 0 {
|
if vv.ConnTrackMax == 0 {
|
||||||
t.Errorf("nf_conntrack_max needs to be greater than zero: %v", vv)
|
t.Errorf("nf_conntrackMax needs to be greater than zero: %v", vv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +48,10 @@ type RlimitStat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IOCountersStat struct {
|
type IOCountersStat struct {
|
||||||
ReadCount uint64 `json:"read_count"`
|
ReadCount uint64 `json:"readCount"`
|
||||||
WriteCount uint64 `json:"write_count"`
|
WriteCount uint64 `json:"writeCount"`
|
||||||
ReadBytes uint64 `json:"read_bytes"`
|
ReadBytes uint64 `json:"readBytes"`
|
||||||
WriteBytes uint64 `json:"write_bytes"`
|
WriteBytes uint64 `json:"writeBytes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NumCtxSwitchesStat struct {
|
type NumCtxSwitchesStat struct {
|
||||||
|
@ -48,10 +48,10 @@ type MemoryMapsStat struct {
|
|||||||
Rss uint64 `json:"rss"`
|
Rss uint64 `json:"rss"`
|
||||||
Size uint64 `json:"size"`
|
Size uint64 `json:"size"`
|
||||||
Pss uint64 `json:"pss"`
|
Pss uint64 `json:"pss"`
|
||||||
SharedClean uint64 `json:"shared_clean"`
|
SharedClean uint64 `json:"sharedClean"`
|
||||||
SharedDirty uint64 `json:"shared_dirty"`
|
SharedDirty uint64 `json:"sharedDirty"`
|
||||||
PrivateClean uint64 `json:"private_clean"`
|
PrivateClean uint64 `json:"privateClean"`
|
||||||
PrivateDirty uint64 `json:"private_dirty"`
|
PrivateDirty uint64 `json:"privateDirty"`
|
||||||
Referenced uint64 `json:"referenced"`
|
Referenced uint64 `json:"referenced"`
|
||||||
Anonymous uint64 `json:"anonymous"`
|
Anonymous uint64 `json:"anonymous"`
|
||||||
Swap uint64 `json:"swap"`
|
Swap uint64 `json:"swap"`
|
||||||
@ -473,9 +473,9 @@ func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
|||||||
ret.ReadCount = t
|
ret.ReadCount = t
|
||||||
case "syscw":
|
case "syscw":
|
||||||
ret.WriteCount = t
|
ret.WriteCount = t
|
||||||
case "read_bytes":
|
case "readBytes":
|
||||||
ret.ReadBytes = t
|
ret.ReadBytes = t
|
||||||
case "write_bytes":
|
case "writeBytes":
|
||||||
ret.WriteBytes = t
|
ret.WriteBytes = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,16 @@
|
|||||||
#
|
#
|
||||||
# go get golang.org/x/tools/cmd/gorename
|
# go get golang.org/x/tools/cmd/gorename
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
|
||||||
|
## Part 1. rename Functions to pass golint. ex) cpu.CPUTimesStat -> cpu.TimesStat
|
||||||
|
|
||||||
#
|
#
|
||||||
# Note:
|
# Note:
|
||||||
# process has IOCounters() for file IO, and also NetIOCounters() for Net IO.
|
# process has IOCounters() for file IO, and also NetIOCounters() for Net IO.
|
||||||
# This scripts replace process.NetIOCounters() to IOCounters().
|
# This scripts replace process.NetIOCounters() to IOCounters().
|
||||||
# So you need hand-fixing process.
|
# So you need hand-fixing process.
|
||||||
|
|
||||||
|
|
||||||
TARGETS=`cat <<EOF
|
TARGETS=`cat <<EOF
|
||||||
CPUTimesStat -> TimesStat
|
CPUTimesStat -> TimesStat
|
||||||
CPUInfoStat -> InfoStat
|
CPUInfoStat -> InfoStat
|
||||||
@ -47,7 +50,6 @@ Id -> ID
|
|||||||
convertCpuTimes -> convertCPUTimes
|
convertCpuTimes -> convertCPUTimes
|
||||||
EOF`
|
EOF`
|
||||||
|
|
||||||
IFS=$'\n'
|
|
||||||
for T in $TARGETS
|
for T in $TARGETS
|
||||||
do
|
do
|
||||||
echo $T
|
echo $T
|
||||||
@ -55,3 +57,78 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
###### Part 2 rename JSON key name
|
||||||
|
## Google JSOn style
|
||||||
|
## https://google.github.io/styleguide/jsoncstyleguide.xml
|
||||||
|
|
||||||
|
sed -i "" 's/guest_nice/guestNice/g' cpu/*.go
|
||||||
|
sed -i "" 's/vendor_id/vendorId/g' cpu/*.go
|
||||||
|
sed -i "" 's/physical_id/physicalId/g' cpu/*.go
|
||||||
|
sed -i "" 's/model_name/modelName/g' cpu/*.go
|
||||||
|
sed -i "" 's/cache_size/cacheSize/g' cpu/*.go
|
||||||
|
sed -i "" 's/core_id/coreId/g' cpu/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/inodes_total/inodesTotal/g' disk/*.go
|
||||||
|
sed -i "" 's/inodes_used/inodesUsed/g' disk/*.go
|
||||||
|
sed -i "" 's/inodes_free/inodesFree/g' disk/*.go
|
||||||
|
sed -i "" 's/inodes_used_percent/inodesUsedPercent/g' disk/*.go
|
||||||
|
sed -i "" 's/read_count/readCount/g' disk/*.go
|
||||||
|
sed -i "" 's/write_count/writeCount/g' disk/*.go
|
||||||
|
sed -i "" 's/read_bytes/readBytes/g' disk/*.go
|
||||||
|
sed -i "" 's/write_bytes/writeBytes/g' disk/*.go
|
||||||
|
sed -i "" 's/read_time/readTime/g' disk/*.go
|
||||||
|
sed -i "" 's/write_time/writeTime/g' disk/*.go
|
||||||
|
sed -i "" 's/io_time/ioTime/g' disk/*.go
|
||||||
|
sed -i "" 's/serial_number/serialNumber/g' disk/*.go
|
||||||
|
sed -i "" 's/used_percent/usedPercent/g' disk/*.go
|
||||||
|
sed -i "" 's/inodesUsed_percent/inodesUsedPercent/g' disk/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/total_cache/totalCache/g' docker/*.go
|
||||||
|
sed -i "" 's/total_rss_huge/totalRssHuge/g' docker/*.go
|
||||||
|
sed -i "" 's/total_rss/totalRss/g' docker/*.go
|
||||||
|
sed -i "" 's/total_mapped_file/totalMappedFile/g' docker/*.go
|
||||||
|
sed -i "" 's/total_pgpgin/totalPgpgin/g' docker/*.go
|
||||||
|
sed -i "" 's/total_pgpgout/totalPgpgout/g' docker/*.go
|
||||||
|
sed -i "" 's/total_pgfault/totalPgfault/g' docker/*.go
|
||||||
|
sed -i "" 's/total_pgmajfault/totalPgmajfault/g' docker/*.go
|
||||||
|
sed -i "" 's/total_inactive_anon/totalInactiveAnon/g' docker/*.go
|
||||||
|
sed -i "" 's/total_active_anon/totalActiveAnon/g' docker/*.go
|
||||||
|
sed -i "" 's/total_inactive_file/totalInactiveFile/g' docker/*.go
|
||||||
|
sed -i "" 's/total_active_file/totalActiveFile/g' docker/*.go
|
||||||
|
sed -i "" 's/total_unevictable/totalUnevictable/g' docker/*.go
|
||||||
|
sed -i "" 's/mem_usage_in_bytes/memUsageInBytes/g' docker/*.go
|
||||||
|
sed -i "" 's/mem_max_usage_in_bytes/memMaxUsageInBytes/g' docker/*.go
|
||||||
|
sed -i "" 's/memory.limit_in_bytes/memoryLimitInBbytes/g' docker/*.go
|
||||||
|
sed -i "" 's/memory.failcnt/memoryFailcnt/g' docker/*.go
|
||||||
|
sed -i "" 's/mapped_file/mappedFile/g' docker/*.go
|
||||||
|
sed -i "" 's/container_id/containerID/g' docker/*.go
|
||||||
|
sed -i "" 's/rss_huge/rssHuge/g' docker/*.go
|
||||||
|
sed -i "" 's/inactive_anon/inactiveAnon/g' docker/*.go
|
||||||
|
sed -i "" 's/active_anon/activeAnon/g' docker/*.go
|
||||||
|
sed -i "" 's/inactive_file/inactiveFile/g' docker/*.go
|
||||||
|
sed -i "" 's/active_file/activeFile/g' docker/*.go
|
||||||
|
sed -i "" 's/hierarchical_memory_limit/hierarchicalMemoryLimit/g' docker/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/boot_time/bootTime/g' host/*.go
|
||||||
|
sed -i "" 's/platform_family/platformFamily/g' host/*.go
|
||||||
|
sed -i "" 's/platform_version/platformVersion/g' host/*.go
|
||||||
|
sed -i "" 's/virtualization_system/virtualizationSystem/g' host/*.go
|
||||||
|
sed -i "" 's/virtualization_role/virtualizationRole/g' host/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/used_percent/usedPercent/g' mem/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/bytes_sent/bytesSent/g' net/*.go
|
||||||
|
sed -i "" 's/bytes_recv/bytesRecv/g' net/*.go
|
||||||
|
sed -i "" 's/packets_sent/packetsSent/g' net/*.go
|
||||||
|
sed -i "" 's/packets_recv/packetsRecv/g' net/*.go
|
||||||
|
sed -i "" 's/conntrack_count/conntrackCount/g' net/*.go
|
||||||
|
sed -i "" 's/conntrack_max/conntrackMax/g' net/*.go
|
||||||
|
|
||||||
|
sed -i "" 's/read_count/readCount/g' process/*.go
|
||||||
|
sed -i "" 's/write_count/writeCount/g' process/*.go
|
||||||
|
sed -i "" 's/read_bytes/readBytes/g' process/*.go
|
||||||
|
sed -i "" 's/write_bytes/writeBytes/g' process/*.go
|
||||||
|
sed -i "" 's/shared_clean/sharedClean/g' process/*.go
|
||||||
|
sed -i "" 's/shared_dirty/sharedDirty/g' process/*.go
|
||||||
|
sed -i "" 's/private_clean/privateClean/g' process/*.go
|
||||||
|
sed -i "" 's/private_dirty/privateDirty/g' process/*.go
|
||||||
|
Loading…
x
Reference in New Issue
Block a user