Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import os 

2from pi3bar.plugins.base import Plugin 

3 

4 

5def get_loadavg_dict(): 

6 loadavg = os.getloadavg() 

7 return { 

8 1: loadavg[0], 

9 5: loadavg[1], 

10 15: loadavg[2] 

11 } 

12 

13 

14class LoadAvg(Plugin): 

15 """ 

16 :class:`pi3bar.app.Pi3Bar` plugin to show load average(s). 

17 

18 :param show_1: :class:`bool` - show load average 1 minute (default: True) 

19 :param show_5: :class:`bool` - show load average 5 minutes (default: True) 

20 :param show_15: :class:`bool` - show load average 15 minutes (default: True) 

21 :param short: :class:`int` - Which number to show if there is not enough space: ``1``, ``5`` or ``15`` (default: 1) 

22 :param warning: :class`int` - Warning breakpoint 

23 :param warning_color: :class`str` - Warning color 

24 :param warning_background: :class`str` - Warning background color 

25 :param critical: :class`int` - Critical breakpoint 

26 :param critical_color: :class`str` - Critical color 

27 :param critical_background: :class`str` - Critical background color 

28 

29 Examples: 

30 

31 .. code-block:: python 

32 

33 LoadAvg() 

34 

35 # adjust warning/critical breakpoints 

36 LoadAvg(warn=8, critical=10) 

37 

38 # adjust which numbers to show: 

39 LoadAvg(show_1=True, show_5=False, show_15=False) 

40 

41 # short shows only one 

42 LoadAvg(short=5) 

43 """ 

44 

45 #: Refresh every 5 seconds 

46 ticks = 5 

47 

48 def __init__(self, show_1=True, show_5=True, show_15=True, short=1, warning=6, critical=12, **kwargs): 

49 self.show_1 = show_1 

50 self.show_5 = show_5 

51 self.show_15 = show_15 

52 self.short = short 

53 self.warning = warning 

54 self.warning_color = kwargs.pop('warning_color', '#ffff00') 

55 self.warning_background = kwargs.pop('warning_background', None) 

56 self.critical = critical 

57 self.critical_color = kwargs.pop('critical_color', None) 

58 self.critical_background = kwargs.pop('critical_background', '#ff0000') 

59 super(LoadAvg, self).__init__(**kwargs) 

60 

61 def cycle(self): 

62 loadavg = get_loadavg_dict() 

63 

64 show = [] 

65 if self.show_1: 

66 show.append('%.2f' % loadavg[1]) 

67 if self.show_5: 

68 show.append('%.2f' % loadavg[5]) 

69 if self.show_15: 

70 show.append('%.2f' % loadavg[15]) 

71 self.full_text = ' '.join(show) 

72 

73 self.short_text = '%.2f' % loadavg[self.short] 

74 

75 if loadavg[1] > self.critical: 

76 self.color = self.critical_color 

77 self.background = self.critical_background 

78 elif loadavg[1] > self.warning: 

79 self.color = self.warning_color 

80 self.background = self.warning_background 

81 else: 

82 self.color = None 

83 self.background = None