...

Text file src/github.com/shirou/gopsutil/v2migration.sh

Documentation: github.com/shirou/gopsutil

     1#!/usr/bin/env bash
     2# This script is a helper of migration to gopsutil v2 using gorename
     3#
     4# go get golang.org/x/tools/cmd/gorename
     5
     6IFS=$'\n'
     7
     8## Part 1. rename Functions to pass golint.  ex) cpu.CPUTimesStat -> cpu.TimesStat
     9
    10#
    11# Note:
    12#   process has IOCounters() for file IO, and also NetIOCounters() for Net IO.
    13#   This scripts replace process.NetIOCounters() to IOCounters().
    14#   So you need hand-fixing process.
    15
    16TARGETS=$(cat <<EOF
    17CPUTimesStat -> TimesStat
    18CPUInfoStat -> InfoStat
    19CPUTimes -> Times
    20CPUInfo -> Info
    21CPUCounts -> Counts
    22CPUPercent -> Percent
    23DiskUsageStat -> UsageStat
    24DiskPartitionStat -> PartitionStat
    25DiskIOCountersStat -> IOCountersStat
    26DiskPartitions -> Partitions
    27DiskIOCounters -> IOCounters
    28DiskUsage -> Usage
    29HostInfoStat -> InfoStat
    30HostInfo -> Info
    31GetVirtualization -> Virtualization
    32GetPlatformInformation -> PlatformInformation
    33LoadAvgStat -> AvgStat
    34LoadAvg -> Avg
    35NetIOCountersStat -> IOCountersStat
    36NetConnectionStat -> ConnectionStat
    37NetProtoCountersStat -> ProtoCountersStat
    38NetInterfaceAddr -> InterfaceAddr
    39NetInterfaceStat -> InterfaceStat
    40NetFilterStat -> FilterStat
    41NetInterfaces -> Interfaces
    42getNetIOCountersAll -> getIOCountersAll
    43NetIOCounters -> IOCounters
    44NetIOCountersByFile -> IOCountersByFile
    45NetProtoCounters -> ProtoCounters
    46NetFilterCounters -> FilterCounters
    47NetConnections -> Connections
    48NetConnectionsPid -> ConnectionsPid
    49Uid -> UID
    50Id -> ID
    51convertCpuTimes -> convertCPUTimes
    52EOF
    53)
    54
    55for T in $TARGETS
    56do
    57  echo "$T"
    58  gofmt -w -r "$T" ./*.go
    59done
    60
    61
    62###### Part 2  rename JSON key name
    63## Google JSOn style
    64## https://google.github.io/styleguide/jsoncstyleguide.xml
    65
    66sed -i "" 's/guest_nice/guestNice/g' cpu/*.go
    67sed -i "" 's/vendor_id/vendorId/g' cpu/*.go
    68sed -i "" 's/physical_id/physicalId/g' cpu/*.go
    69sed -i "" 's/model_name/modelName/g' cpu/*.go
    70sed -i "" 's/cache_size/cacheSize/g' cpu/*.go
    71sed -i "" 's/core_id/coreId/g' cpu/*.go
    72
    73sed -i "" 's/inodes_total/inodesTotal/g' disk/*.go
    74sed -i "" 's/inodes_used/inodesUsed/g' disk/*.go
    75sed -i "" 's/inodes_free/inodesFree/g' disk/*.go
    76sed -i "" 's/inodes_used_percent/inodesUsedPercent/g' disk/*.go
    77sed -i "" 's/read_count/readCount/g' disk/*.go
    78sed -i "" 's/write_count/writeCount/g' disk/*.go
    79sed -i "" 's/read_bytes/readBytes/g' disk/*.go
    80sed -i "" 's/write_bytes/writeBytes/g' disk/*.go
    81sed -i "" 's/read_time/readTime/g' disk/*.go
    82sed -i "" 's/write_time/writeTime/g' disk/*.go
    83sed -i "" 's/io_time/ioTime/g' disk/*.go
    84sed -i "" 's/serial_number/serialNumber/g' disk/*.go
    85sed -i "" 's/used_percent/usedPercent/g' disk/*.go
    86sed -i "" 's/inodesUsed_percent/inodesUsedPercent/g' disk/*.go
    87
    88sed -i "" 's/total_cache/totalCache/g' docker/*.go
    89sed -i "" 's/total_rss_huge/totalRssHuge/g' docker/*.go
    90sed -i "" 's/total_rss/totalRss/g' docker/*.go
    91sed -i "" 's/total_mapped_file/totalMappedFile/g' docker/*.go
    92sed -i "" 's/total_pgpgin/totalPgpgin/g' docker/*.go
    93sed -i "" 's/total_pgpgout/totalPgpgout/g' docker/*.go
    94sed -i "" 's/total_pgfault/totalPgfault/g' docker/*.go
    95sed -i "" 's/total_pgmajfault/totalPgmajfault/g' docker/*.go
    96sed -i "" 's/total_inactive_anon/totalInactiveAnon/g' docker/*.go
    97sed -i "" 's/total_active_anon/totalActiveAnon/g' docker/*.go
    98sed -i "" 's/total_inactive_file/totalInactiveFile/g' docker/*.go
    99sed -i "" 's/total_active_file/totalActiveFile/g' docker/*.go
   100sed -i "" 's/total_unevictable/totalUnevictable/g' docker/*.go
   101sed -i "" 's/mem_usage_in_bytes/memUsageInBytes/g' docker/*.go
   102sed -i "" 's/mem_max_usage_in_bytes/memMaxUsageInBytes/g' docker/*.go
   103sed -i "" 's/memory.limit_in_bytes/memoryLimitInBbytes/g' docker/*.go
   104sed -i "" 's/memory.failcnt/memoryFailcnt/g' docker/*.go
   105sed -i "" 's/mapped_file/mappedFile/g' docker/*.go
   106sed -i "" 's/container_id/containerID/g' docker/*.go
   107sed -i "" 's/rss_huge/rssHuge/g' docker/*.go
   108sed -i "" 's/inactive_anon/inactiveAnon/g' docker/*.go
   109sed -i "" 's/active_anon/activeAnon/g' docker/*.go
   110sed -i "" 's/inactive_file/inactiveFile/g' docker/*.go
   111sed -i "" 's/active_file/activeFile/g' docker/*.go
   112sed -i "" 's/hierarchical_memory_limit/hierarchicalMemoryLimit/g' docker/*.go
   113
   114sed -i "" 's/boot_time/bootTime/g' host/*.go
   115sed -i "" 's/platform_family/platformFamily/g' host/*.go
   116sed -i "" 's/platform_version/platformVersion/g' host/*.go
   117sed -i "" 's/virtualization_system/virtualizationSystem/g' host/*.go
   118sed -i "" 's/virtualization_role/virtualizationRole/g' host/*.go
   119
   120sed -i "" 's/used_percent/usedPercent/g' mem/*.go
   121
   122sed -i "" 's/bytes_sent/bytesSent/g' net/*.go
   123sed -i "" 's/bytes_recv/bytesRecv/g' net/*.go
   124sed -i "" 's/packets_sent/packetsSent/g' net/*.go
   125sed -i "" 's/packets_recv/packetsRecv/g' net/*.go
   126sed -i "" 's/conntrack_count/conntrackCount/g' net/*.go
   127sed -i "" 's/conntrack_max/conntrackMax/g' net/*.go
   128
   129sed -i "" 's/read_count/readCount/g' process/*.go
   130sed -i "" 's/write_count/writeCount/g' process/*.go
   131sed -i "" 's/read_bytes/readBytes/g' process/*.go
   132sed -i "" 's/write_bytes/writeBytes/g' process/*.go
   133sed -i "" 's/shared_clean/sharedClean/g' process/*.go
   134sed -i "" 's/shared_dirty/sharedDirty/g' process/*.go
   135sed -i "" 's/private_clean/privateClean/g' process/*.go
   136sed -i "" 's/private_dirty/privateDirty/g' process/*.go

View as plain text