Merge lp:~jbernard/byobu/rcs-cost into lp:byobu

Proposed by Jon Bernard
Status: Merged
Merge reported by: Dustin Kirkland 
Merged at revision: not available
Proposed branch: lp:~jbernard/byobu/rcs-cost
Merge into: lp:byobu
Diff against target: 161 lines (+105/-1)
5 files modified
etc/byobu/statusrc (+1/-0)
usr/bin/byobu-config (+1/-0)
usr/lib/byobu/rcs_cost (+99/-0)
usr/share/byobu/profiles/common (+2/-1)
usr/share/man/man1/byobu.1 (+2/-0)
To merge this branch: bzr merge lp:~jbernard/byobu/rcs-cost
Reviewer Review Type Date Requested Status
Dustin Kirkland  Approve
Review via email: mp+24329@code.launchpad.net
To post a comment you must log in.
lp:~jbernard/byobu/rcs-cost updated
1013. By Jon Bernard

Include rcs_cost in statusline

1014. By Jon Bernard

Use tabs instead of spaces in rcs_cost

Revision history for this message
Dustin Kirkland  (kirkland) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'etc/byobu/statusrc'
2--- etc/byobu/statusrc 2010-04-26 19:07:01 +0000
3+++ etc/byobu/statusrc 2010-04-28 15:33:38 +0000
4@@ -42,6 +42,7 @@
5 menu=1
6 network=0
7 processes=0
8+rcs_cost=0
9 reboot_required=1
10 release=1
11 services=1
12
13=== modified file 'usr/bin/byobu-config'
14--- usr/bin/byobu-config 2010-04-26 19:07:01 +0000
15+++ usr/bin/byobu-config 2010-04-28 15:33:38 +0000
16@@ -302,6 +302,7 @@
17 status["menu"]=1
18 status["network"]=0
19 status["processes"]=0
20+ status["rcs_cost"]=0
21 status["reboot_required"]=1
22 status["release"]=1
23 status["services"]=1
24
25=== added file 'usr/lib/byobu/rcs_cost'
26--- usr/lib/byobu/rcs_cost 1970-01-01 00:00:00 +0000
27+++ usr/lib/byobu/rcs_cost 2010-04-28 15:33:38 +0000
28@@ -0,0 +1,99 @@
29+#!/bin/sh
30+#
31+# rcs_cost: approximate Rackspace Cloud Server cost (USD) of the current
32+# instance
33+#
34+# Copyright (C) 2009-2010 Jon Bernard
35+#
36+# Author: Jon Bernard <jbernard@debian.org>
37+#
38+# Derived from byobu's ec2_cost written by Dustin Kirkland, see
39+# Byobu's project page: https://launchpad.net/byobu for more information
40+#
41+# This program is free software: you can redistribute it and/or modify it
42+# under the terms of the GNU General Public License as published by the
43+# Free Software Foundation, version 3 of the License.
44+#
45+# This program is distributed in the hope that it will be useful, but
46+# WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
48+# Public License for more details.
49+#
50+# You should have received a copy of the GNU General Public License along
51+# with this program. If not, see <http://www.gnu.org/licenses/>.
52+
53+DETAIL=0
54+PKG="byobu"
55+color 2>/dev/null || color() { true; }
56+
57+for arg in $@; do
58+ case "$arg" in
59+ -d|--detail)
60+ DETAIL=1
61+ ;;
62+ esac
63+done
64+
65+# Approximate Instance Cost Basis
66+# Memory US
67+# 256MB $0.015/h
68+# 512MB $0.030/h
69+# 1024MB $0.060/h
70+# 2048MB $0.120/h
71+# 4096MB $0.240/h
72+# 8192MB $0.480/h
73+# 15872MB $0.960/h
74+
75+# Instance memory
76+memory=`grep "^MemTotal:" /proc/meminfo | awk '{print $2}'`
77+
78+# Round memory down to the nearest multiple of 64MB
79+memory=$((${memory} - (${memory} % (64 * 1024))))
80+
81+# Apply the going rate
82+INCREMENTS="256 512 1024 2048 4096 8192 16384 32768 65536"
83+for X in ${INCREMENTS}; do
84+ test "$((${X} * 1024 + 65536))" -ge ${memory} && break
85+done
86+MEMORY_RATE=`echo "$X" | awk '{printf "%f", $1 / 256 * 15 / 1000}'`
87+
88+# Data Transfer Cost Basis
89+# Incoming $0.08/GB
90+# Outgoing $0.22/GB
91+RX_RATE="0.08"
92+TX_RATE="0.22"
93+
94+# Auto detect network interface
95+IF=`tail -n1 /proc/net/route | awk '{print $1}'`
96+
97+ifconfig_out=`/sbin/ifconfig "$IF"`
98+
99+# Calculate bandwidth cost
100+tx_gb=`echo "$ifconfig_out" | grep "TX bytes:" | sed "s/^.*TX bytes://" | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }'`
101+rx_gb=`echo "$ifconfig_out" | grep "RX bytes:" | sed "s/^.*RX bytes://" | awk '{ printf "%f", $1 / 1024 / 1024 / 1024 }'`
102+network_cost=`echo "$tx_gb" "$TX_RATE" "$rx_gb" "$RX_RATE" | awk '{printf "%f %f", $1*$2, $3*$4}' | awk '{printf "%f", $1 + $2}'`
103+
104+# Calculate uptime cost
105+# BUG: This will only calculate uptime since boot!
106+# Some additional input will be required to account for reboots!!!
107+hours=`awk '{printf "%f", 1 + $1 / 60 / 60 }' /proc/uptime | sed 's/\..*$//' `
108+uptime_cost=`echo "$hours" | awk "{printf \"%f\", "$MEMORY_RATE" * $hours}"`
109+total_cost=`echo "$network_cost" "$uptime_cost" | awk '{printf "%.2f", $1 + $2}'`
110+
111+if [ "$DETAIL" = "1" ]; then
112+ echo "=========================================================="
113+ echo "Estimated cost in Rackspace Cloud Server since last reboot"
114+ echo "=========================================================="
115+ echo " Network sent: $tx_gb GB @ \$$RX_RATE/GB"
116+ echo " Network recv: $rx_gb GB @ \$$TX_RATE/GB"
117+ echo " Network cost: \$$network_cost"
118+ echo "----------------------------------------------------------"
119+ echo " Uptime: $hours hr @ \$$MEMORY_RATE/hr"
120+ echo " Uptime cost: \$$uptime_cost"
121+ echo "----------------------------------------------------------"
122+ echo "Total cost: ~\$$total_cost"
123+ echo "=========================================================="
124+ exit 0
125+fi
126+
127+printf "$(color K G)~\$$(color -)$(color b K G)%s$(color -) " $total_cost
128
129=== modified file 'usr/share/byobu/profiles/common'
130--- usr/share/byobu/profiles/common 2010-04-26 19:07:01 +0000
131+++ usr/share/byobu/profiles/common 2010-04-28 15:33:38 +0000
132@@ -71,6 +71,7 @@
133 backtick 131 53 53 byobu-status services
134 backtick 132 11 11 byobu-status time_utc
135 backtick 133 3 3 byobu-status disk_io
136+backtick 134 613 613 byobu-status rcs_cost
137
138 hardstatus alwayslastline
139
140@@ -104,7 +105,7 @@
141 caption always "%12`%?%-Lw%50L>%?%{=r}%n*%f %t%?(%u)%?%{-}%12`%?%+Lw%?%11` %=%12`%110`%109`%122`%111`%10`%<"
142
143 # Status string, last line
144-hardstatus string '%99`%{-}%{=r}%12` %100`%112`%= %130`%102`%101`%129`%131`%127`%114`%115`%108`%128`%125`%126`%113`%119`%133`%117`%116`%106`%104`%103`%105`%107`%123`%132`%120`%121`'
145+hardstatus string '%99`%{-}%{=r}%12` %100`%112`%= %130`%102`%101`%129`%131`%127`%114`%115`%108`%134`%128`%125`%126`%113`%119`%133`%117`%116`%106`%104`%103`%105`%107`%123`%132`%120`%121`'
146
147 # NOTE: Older version of screen have an arbitrary limit of only being able
148 # to change colors 16 times in this 'hardstatus string'.
149
150=== modified file 'usr/share/man/man1/byobu.1'
151--- usr/share/man/man1/byobu.1 2010-04-26 19:07:01 +0000
152+++ usr/share/man/man1/byobu.1 2010-04-28 15:33:38 +0000
153@@ -36,6 +36,8 @@
154
155 \fBec2_cost\fP \- an estimation of the cost of the current boot of the system in terms of the Amazon EC2 billing model; displayed in the lower bar toward the right in green text on a black background; there is a leading '~' to indicate that this is an estimation, and the monetary units are US Dollars '$'
156
157+\fBrcs_cost\fP \- an estimation of the cost of the current boot of the system in terms of the Rackspace Cloud Server billing model; displayed in the lower bar toward the right in green text on a black background; there is a leading '~' to indicate that this is an estimation, and the monetary units are US Dollars '$'
158+
159 \fBfan_speed\fP \- cpu or system fan speed as reported by lm-sensors; displayed in the lower bar toward the right in black text on a grey background; there is a trailing 'rpm' for units
160
161 \fBhostname\fP \- the hostname of the system; displayed in the upper bar on the far right in bold black text on a grey background; there is a leading '@' symbol if the username status is also enabled

Subscribers

People subscribed via source and target branches