Skip to content

Commit

Permalink
JSON representation is renamed to fit Google JSON style, camelCase.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed Mar 23, 2016
1 parent 46ddd57 commit 4bb8464
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 105 deletions.
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_ .


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
------------------------------------

Expand Down
14 changes: 7 additions & 7 deletions cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ type TimesStat struct {
Softirq float64 `json:"softirq"`
Steal float64 `json:"steal"`
Guest float64 `json:"guest"`
GuestNice float64 `json:"guest_nice"`
GuestNice float64 `json:"guestNice"`
Stolen float64 `json:"stolen"`
}

type InfoStat struct {
CPU int32 `json:"cpu"`
VendorID string `json:"vendor_id"`
VendorID string `json:"vendorId"`
Family string `json:"family"`
Model string `json:"model"`
Stepping int32 `json:"stepping"`
PhysicalID string `json:"physical_id"`
CoreID string `json:"core_id"`
PhysicalID string `json:"physicalId"`
CoreID string `json:"coreId"`
Cores int32 `json:"cores"`
ModelName string `json:"model_name"`
ModelName string `json:"modelName"`
Mhz float64 `json:"mhz"`
CacheSize int32 `json:"cache_size"`
CacheSize int32 `json:"cacheSize"`
Flags []string `json:"flags"`
}

Expand All @@ -56,7 +56,7 @@ func (c TimesStat) String() string {
`"softirq":` + strconv.FormatFloat(c.Softirq, 'f', 1, 64),
`"steal":` + strconv.FormatFloat(c.Steal, '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),
}

Expand Down
4 changes: 2 additions & 2 deletions cpu/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func finishCPUInfo(c *InfoStat) error {
}
}
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 {
c.CoreID = lines[0]
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func Info() ([]InfoStat, error) {
return ret, err
}
c.CPU = int32(t)
case "vendor_id":
case "vendorId":
c.VendorID = value
case "cpu family":
c.Family = value
Expand Down
2 changes: 1 addition & 1 deletion cpu/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestCPUTimeStat_String(t *testing.T) {
System: 200.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) {
t.Errorf("CPUTimesStat string is invalid: %v", v)
}
Expand Down
26 changes: 13 additions & 13 deletions disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type UsageStat struct {
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"used_percent"`
InodesTotal uint64 `json:"inodes_total"`
InodesUsed uint64 `json:"inodes_used"`
InodesFree uint64 `json:"inodes_free"`
InodesUsedPercent float64 `json:"inodes_used_percent"`
UsedPercent float64 `json:"usedPercent"`
InodesTotal uint64 `json:"inodesTotal"`
InodesUsed uint64 `json:"inodesUsed"`
InodesFree uint64 `json:"inodesFree"`
InodesUsedPercent float64 `json:"inodesUsedPercent"`
}

type PartitionStat struct {
Expand All @@ -25,15 +25,15 @@ type PartitionStat struct {
}

type IOCountersStat struct {
ReadCount uint64 `json:"read_count"`
WriteCount uint64 `json:"write_count"`
ReadBytes uint64 `json:"read_bytes"`
WriteBytes uint64 `json:"write_bytes"`
ReadTime uint64 `json:"read_time"`
WriteTime uint64 `json:"write_time"`
ReadCount uint64 `json:"readCount"`
WriteCount uint64 `json:"writeCount"`
ReadBytes uint64 `json:"readBytes"`
WriteBytes uint64 `json:"writeBytes"`
ReadTime uint64 `json:"readTime"`
WriteTime uint64 `json:"writeTime"`
Name string `json:"name"`
IoTime uint64 `json:"io_time"`
SerialNumber string `json:"serial_number"`
IoTime uint64 `json:"ioTime"`
SerialNumber string `json:"serialNumber"`
}

func (d UsageStat) String() string {
Expand Down
4 changes: 2 additions & 2 deletions disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDiskUsageStat_String(t *testing.T) {
InodesUsedPercent: 49.1,
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) {
t.Errorf("DiskUsageStat string is invalid: %v", v)
}
Expand Down Expand Up @@ -90,7 +90,7 @@ func TestDiskIOCountersStat_String(t *testing.T) {
WriteBytes: 400,
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) {
t.Errorf("DiskUsageStat string is invalid: %v", v)
}
Expand Down
50 changes: 25 additions & 25 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ var ErrDockerNotAvailable = errors.New("docker not available")
var ErrCgroupNotAvailable = errors.New("cgroup not available")

type CgroupMemStat struct {
ContainerID string `json:"container_id"`
ContainerID string `json:"containerID"`
Cache uint64 `json:"cache"`
RSS uint64 `json:"rss"`
RSSHuge uint64 `json:"rss_huge"`
MappedFile uint64 `json:"mapped_file"`
RSSHuge uint64 `json:"rssHuge"`
MappedFile uint64 `json:"mappedFile"`
Pgpgin uint64 `json:"pgpgin"`
Pgpgout uint64 `json:"pgpgout"`
Pgfault uint64 `json:"pgfault"`
Pgmajfault uint64 `json:"pgmajfault"`
InactiveAnon uint64 `json:"inactive_anon"`
ActiveAnon uint64 `json:"active_anon"`
InactiveFile uint64 `json:"inactive_file"`
ActiveFile uint64 `json:"active_file"`
InactiveAnon uint64 `json:"inactiveAnon"`
ActiveAnon uint64 `json:"activeAnon"`
InactiveFile uint64 `json:"inactiveFile"`
ActiveFile uint64 `json:"activeFile"`
Unevictable uint64 `json:"unevictable"`
HierarchicalMemoryLimit uint64 `json:"hierarchical_memory_limit"`
TotalCache uint64 `json:"total_cache"`
TotalRSS uint64 `json:"total_rss"`
TotalRSSHuge uint64 `json:"total_rss_huge"`
TotalMappedFile uint64 `json:"total_mapped_file"`
TotalPgpgIn uint64 `json:"total_pgpgin"`
TotalPgpgOut uint64 `json:"total_pgpgout"`
TotalPgFault uint64 `json:"total_pgfault"`
TotalPgMajFault uint64 `json:"total_pgmajfault"`
TotalInactiveAnon uint64 `json:"total_inactive_anon"`
TotalActiveAnon uint64 `json:"total_active_anon"`
TotalInactiveFile uint64 `json:"total_inactive_file"`
TotalActiveFile uint64 `json:"total_active_file"`
TotalUnevictable uint64 `json:"total_unevictable"`
MemUsageInBytes uint64 `json:"mem_usage_in_bytes"`
MemMaxUsageInBytes uint64 `json:"mem_max_usage_in_bytes"`
MemLimitInBytes uint64 `json:"memory.limit_in_bytes"`
MemFailCnt uint64 `json:"memory.failcnt"`
HierarchicalMemoryLimit uint64 `json:"hierarchicalMemoryLimit"`
TotalCache uint64 `json:"totalCache"`
TotalRSS uint64 `json:"totalRss"`
TotalRSSHuge uint64 `json:"totalRssHuge"`
TotalMappedFile uint64 `json:"totalMappedFile"`
TotalPgpgIn uint64 `json:"totalPgpgin"`
TotalPgpgOut uint64 `json:"totalPgpgout"`
TotalPgFault uint64 `json:"totalPgfault"`
TotalPgMajFault uint64 `json:"totalPgmajfault"`
TotalInactiveAnon uint64 `json:"totalInactiveAnon"`
TotalActiveAnon uint64 `json:"totalActiveAnon"`
TotalInactiveFile uint64 `json:"totalInactiveFile"`
TotalActiveFile uint64 `json:"totalActiveFile"`
TotalUnevictable uint64 `json:"totalUnevictable"`
MemUsageInBytes uint64 `json:"memUsageInBytes"`
MemMaxUsageInBytes uint64 `json:"memMaxUsageInBytes"`
MemLimitInBytes uint64 `json:"memoryLimitInBbytes"`
MemFailCnt uint64 `json:"memoryFailcnt"`
}
44 changes: 22 additions & 22 deletions docker/docker_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
ret.Cache = v
case "rss":
ret.RSS = v
case "rss_huge":
case "rssHuge":
ret.RSSHuge = v
case "mapped_file":
case "mappedFile":
ret.MappedFile = v
case "pgpgin":
ret.Pgpgin = v
Expand All @@ -113,43 +113,43 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
ret.Pgfault = v
case "pgmajfault":
ret.Pgmajfault = v
case "inactive_anon":
case "inactiveAnon":
ret.InactiveAnon = v
case "active_anon":
case "activeAnon":
ret.ActiveAnon = v
case "inactive_file":
case "inactiveFile":
ret.InactiveFile = v
case "active_file":
case "activeFile":
ret.ActiveFile = v
case "unevictable":
ret.Unevictable = v
case "hierarchical_memory_limit":
case "hierarchicalMemoryLimit":
ret.HierarchicalMemoryLimit = v
case "total_cache":
case "totalCache":
ret.TotalCache = v
case "total_rss":
case "totalRss":
ret.TotalRSS = v
case "total_rss_huge":
case "totalRssHuge":
ret.TotalRSSHuge = v
case "total_mapped_file":
case "totalMappedFile":
ret.TotalMappedFile = v
case "total_pgpgin":
case "totalPgpgin":
ret.TotalPgpgIn = v
case "total_pgpgout":
case "totalPgpgout":
ret.TotalPgpgOut = v
case "total_pgfault":
case "totalPgfault":
ret.TotalPgFault = v
case "total_pgmajfault":
case "totalPgmajfault":
ret.TotalPgMajFault = v
case "total_inactive_anon":
case "totalInactiveAnon":
ret.TotalInactiveAnon = v
case "total_active_anon":
case "totalActiveAnon":
ret.TotalActiveAnon = v
case "total_inactive_file":
case "totalInactiveFile":
ret.TotalInactiveFile = v
case "total_active_file":
case "totalActiveFile":
ret.TotalActiveFile = v
case "total_unevictable":
case "totalUnevictable":
ret.TotalUnevictable = v
}
}
Expand All @@ -162,11 +162,11 @@ func CgroupMem(containerId string, base string) (*CgroupMemStat, error) {
if err == nil {
ret.MemMaxUsageInBytes = r
}
r, err = getCgroupMemFile(containerId, base, "memory.limit_in_bytes")
r, err = getCgroupMemFile(containerId, base, "memoryLimitInBbytes")
if err == nil {
ret.MemLimitInBytes = r
}
r, err = getCgroupMemFile(containerId, base, "memory.failcnt")
r, err = getCgroupMemFile(containerId, base, "memoryFailcnt")
if err == nil {
ret.MemFailCnt = r
}
Expand Down
10 changes: 5 additions & 5 deletions host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
type InfoStat struct {
Hostname string `json:"hostname"`
Uptime uint64 `json:"uptime"`
BootTime uint64 `json:"boot_time"`
BootTime uint64 `json:"bootTime"`
Procs uint64 `json:"procs"` // number of processes
OS string `json:"os"` // ex: freebsd, linux
Platform string `json:"platform"` // ex: ubuntu, linuxmint
PlatformFamily string `json:"platform_family"` // ex: debian, rhel
PlatformVersion string `json:"platform_version"`
VirtualizationSystem string `json:"virtualization_system"`
VirtualizationRole string `json:"virtualization_role"` // guest or host
PlatformFamily string `json:"platformFamily"` // ex: debian, rhel
PlatformVersion string `json:"platformVersion"`
VirtualizationSystem string `json:"virtualizationSystem"`
VirtualizationRole string `json:"virtualizationRole"` // guest or host

}

Expand Down
2 changes: 1 addition & 1 deletion host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestHostInfoStat_String(t *testing.T) {
Platform: "ubuntu",
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) {
t.Errorf("HostInfoStat string is invalid: %v", v)
}
Expand Down
4 changes: 2 additions & 2 deletions mem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type VirtualMemoryStat struct {
// Percentage of RAM used by programs
//
// 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
// cares about the value of right now. For a human consumable number,
Expand All @@ -48,7 +48,7 @@ type SwapMemoryStat struct {
Total uint64 `json:"total"`
Used uint64 `json:"used"`
Free uint64 `json:"free"`
UsedPercent float64 `json:"used_percent"`
UsedPercent float64 `json:"usedPercent"`
Sin uint64 `json:"sin"`
Sout uint64 `json:"sout"`
}
Expand Down
4 changes: 2 additions & 2 deletions mem/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestVirtualMemoryStat_String(t *testing.T) {
UsedPercent: 30.1,
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) {
t.Errorf("VirtualMemoryStat string is invalid: %v", v)
}
Expand All @@ -65,7 +65,7 @@ func TestSwapMemoryStat_String(t *testing.T) {
Free: 40,
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) {
t.Errorf("SwapMemoryStat string is invalid: %v", v)
}
Expand Down
12 changes: 6 additions & 6 deletions net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func init() {

type IOCountersStat struct {
Name string `json:"name"` // interface name
BytesSent uint64 `json:"bytes_sent"` // number of bytes sent
BytesRecv uint64 `json:"bytes_recv"` // number of bytes received
PacketsSent uint64 `json:"packets_sent"` // number of packets sent
PacketsRecv uint64 `json:"packets_recv"` // number of packets received
BytesSent uint64 `json:"bytesSent"` // number of bytes sent
BytesRecv uint64 `json:"bytesRecv"` // number of bytes received
PacketsSent uint64 `json:"packetsSent"` // number of packets sent
PacketsRecv uint64 `json:"packetsRecv"` // number of packets received
Errin uint64 `json:"errin"` // total number of errors while receiving
Errout uint64 `json:"errout"` // total number of errors while sending
Dropin uint64 `json:"dropin"` // total number of incoming packets which were dropped
Expand Down Expand Up @@ -65,8 +65,8 @@ type InterfaceStat struct {
}

type FilterStat struct {
ConnTrackCount int64 `json:"conntrack_count"`
ConnTrackMax int64 `json:"conntrack_max"`
ConnTrackCount int64 `json:"conntrackCount"`
ConnTrackMax int64 `json:"conntrackMax"`
}

var constMap = map[string]int{
Expand Down
4 changes: 2 additions & 2 deletions net/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) {
// the currently in use conntrack count and the max.
// If the file does not exist or is invalid it will return nil.
func FilterCounters() ([]FilterStat, error) {
countfile := common.HostProc("sys/net/netfilter/nf_conntrack_count")
maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max")
countfile := common.HostProc("sys/net/netfilter/nf_conntrackCount")
maxfile := common.HostProc("sys/net/netfilter/nf_conntrackMax")

count, err := common.ReadInts(countfile)

Expand Down
Loading

0 comments on commit 4bb8464

Please sign in to comment.