File: loadavg.lua

package info (click to toggle)
weechat-scripts 20071011
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 400 kB
  • ctags: 377
  • sloc: python: 3,470; perl: 1,305; ruby: 270; makefile: 37
file content (27 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Author: Julien Louis <ptitlouis@sysif.net>
-- License: GPLv2
-- Description: This lua script prints in the infobar the machine load average
--
weechat.register("loadavg", "0.1", "unload", "Print the load average in infobar")

local refresh = weechat.get_config("loadavg_refresh")

if refresh == "" then
	refresh = 5
	weechat.set_config("loadavg_refresh", 5)
end
	
weechat.add_timer_handler(refresh, "loadavg")

function loadavg()
	local load = io.open("/proc/loadavg"):read()
	load = string.gsub(load, "^([%w.]+) ([%w.]+) ([%w.]+).*", "%1 %2 %3")
	weechat.print_infobar(refresh, "load: "..load)
	return weechat.PLUGIN_RC_OK;
end

function unload()
	weechat.remove_timer_handler("loadavg")
	return weechat.remove_infobar(1)
end