Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Modified version of https://github.com/felixhageloh/uebersicht-widgets/tree/master/disk-usage
- # You may exclude certain drives (separate with a pipe)
- # Example: exclude = 'MyBook' or exclude = 'MyBook|WD Passport'
- # Set as something obscure to show all drives (strange, but easier than editing the command)
- exclude = 'VM'
- # Use base 10 numbers, i.e. 1GB = 1000MB. Leave this true to show disk sizes as
- # OS X would (since Snow Leopard)
- base10 = true
- # appearance
- filledStyle = false # set to true for the second style variant. bgColor will become the text color
- width = '367px'
- barHeight = '36px'
- labelColor = '#fff'
- #usedColor = '#d7051d'
- usedColor = '#d7051d'
- freeColor = '#525252'
- bgColor = '#fff'
- borderRadius = '3px'
- bgOpacity = 0.9
- # You may optionally limit the number of disk to show
- maxDisks: 10
- localDisksAmount = "df -H | grep '/dev/' | wc -l | awk '{$1=$1};1'"
- localDisks = "df -#{if base10 then 'H' else 'h'} | grep '/dev/' | while read -r line; do fs=$(echo $line | awk '{print $1}'); name=$(diskutil info $fs | grep 'Volume Name' | awk '{print substr($0, index($0,$3))}'); echo $(echo $line | awk '{print $2, $3, $4, $5}') $(echo $name | awk '{print substr($0, index($0,$1))}'); done | grep -vE '#{exclude}'"
- # ######## SERVER SETUP ########
- # Enable server setup
- serverDisksEnabled = false
- # Regex of what disks to show
- serverDisks = "/dev/sda1|/dev/sdb1"
- # Edit 'sshHost' to match your SSH credentials
- sshHost = "user@host"
- serverDisksCmd = ""
- if (serverDisksEnabled)
- serverDisksCmd = " && ssh -t #{sshHost} df -H 2> /dev/null | egrep '#{serverDisks}'"
- #serverDisks = "ssh -t qpqp df -H 2> /dev/null | egrep '/dev/mapper/(qpqp--vg-(data|root|home)|backup--vg-backup)' | grep '/dev/' | while read -r line; do fs=$(echo $line | awk '{print $1}'); name=$(diskutil info $fs | grep 'Volume Name' | awk '{print substr($0, index($0,$3))}'); echo $(echo $line | awk '{print $2, $3, $4, $5}') $(echo $name | awk '{print substr($0, index($0,$1))}'); done"
- command: localDisksAmount + ' && ' + localDisks + serverDisksCmd
- refreshFrequency: 60000 * 60 # 1h
- style: """
- bottom: 50px
- left: 50px
- font-family: Helvetica Neue
- font-weight: 200
- h2
- color: #{labelColor}
- padding: 0
- margin: 20px 0 -10px
- font-weight: 200
- .label
- font-size: 12px
- color: #{labelColor}
- margin-left: 1px
- font-style: italic
- font-family: Myriad Set Pro, Helvetica Neue
- .total
- display: inline-block
- margin-left: 8px
- font-weight: bold
- .disk:not(:first-child)
- margin-top: 16px
- .wrapper
- height: #{barHeight}
- font-size: #{Math.round(parseInt(barHeight)*0.8)}px
- line-height: 1
- width: #{width}
- max-width: #{width}
- margin: 4px 0 0 0
- position: relative
- overflow: hidden
- border-radius: #{borderRadius}
- background: rgba(#{bgColor}, #{bgOpacity})
- #{'background: none' if filledStyle }
- .wrapper:first-of-type
- margin: 0px
- .bar
- position: absolute
- top: 0
- bottom: 0px
- &.used
- border-radius: #{borderRadius} 0 0 #{borderRadius}
- background: rgba(#{usedColor}, #{ if filledStyle then bgOpacity else 0.1 })
- border-bottom: 1px solid #{usedColor}
- #{'border-bottom: none' if filledStyle }
- &.free
- right: 0
- border-radius: 0 #{borderRadius} #{borderRadius} 0
- background: rgba(#{freeColor}, #{ if filledStyle then bgOpacity else 0.05 })
- border-bottom: 1px solid #{freeColor}
- #{'border-bottom: none' if filledStyle }
- .stats
- display: inline-block
- font-size: 0.5em
- line-height: 1
- word-spacing: -2px
- text-overflow: ellipsis
- vertical-align: middle
- position: relative
- span
- font-size: 0.8em
- margin-left: 2px
- .free, .used
- display: inline-block
- white-space: nowrap
- .free
- margin-left: 12px
- color: #{if filledStyle then bgColor else freeColor}
- .used
- color: #{if filledStyle then bgColor else usedColor}
- margin-left: 6px
- font-size: 0.9em
- .needle
- width: 0
- border-left: 1px dashed rgba(#{usedColor}, 0.2)
- position: absolute
- top: 0
- bottom: -2px
- display: #{'none' if filledStyle}
- &:after, &:before
- content: ' '
- border-top: 5px solid #{usedColor}
- border-left: 4px solid transparent
- border-right: 4px solid transparent
- position: absolute
- left: -4px
- """
- humanize: (sizeString) ->
- sizeString + 'B'
- renderInfo: (total, used, free, pctg, name) -> """
- <div class='disk'>
- <div class='label'>#{name} <span class='total'>#{@humanize(total)}</span></div>
- <div class='wrapper'>
- <div class='bar used' style='width: #{pctg}'></div>
- <div class='bar free' style='width: #{100 - parseInt(pctg)}%'></div>
- <div class='stats'>
- <div class='free'>#{@humanize(free)} <span>free</span> </div>
- <div class='used'>#{@humanize(used)} <span>used</span></div>
- </div>
- <div class='needle' style="left: #{pctg}"></div>
- </div>
- </div>
- """
- update: (output, domEl) ->
- commands = output.split('\n')
- localDisksAmount = commands[0]
- localDisks = commands[1..localDisksAmount]
- serverDisks = commands[localDisksAmount..]
- $(domEl).html ''
- $(domEl).append("<h2>Local</h2>")
- # Local
- for disk, i in localDisks[..(@maxDisks - 1)]
- args = disk.split(' ')
- if (args[4])
- args[4] = args[4..].join(' ')
- $(domEl).append @renderInfo(args...)
- # Server
- if (serverDisksEnabled)
- $(domEl).append("<h2>Server</h2>")
- for disk, i in serverDisks
- args = disk.split(' ')
- args = args.filter (x) -> x != ''
- args = args[1..]
- if (args[4])
- args[4] = args[4..].join(' ')
- $(domEl).append @renderInfo(args...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement