]> git.ipfire.org Git - collecty.git/blame - src/collecty/colours.py
psi: Add graph template
[collecty.git] / src / collecty / colours.py
CommitLineData
9823dfef
MT
1#!/usr/bin/python3
2###############################################################################
3# #
4# collecty - A system statistics collection daemon for IPFire #
5# Copyright (C) 2015 IPFire development team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21
80eb8d10
MT
22def _add(colour, amount):
23 """
24 Adds some value to colours
25 """
26 # Parse hex array
27 bytes = bytearray.fromhex(colour.lstrip("#"))
28
29 if not len(bytes) == 3:
30 raise ValueError("Invalid colour: %s" % colour)
31
32 ret = bytearray()
33
34 for byte in bytes:
35 byte = round(byte * amount)
36
37 # Ensure the result is within range
38 byte = min(byte, 255)
39 byte = max(byte, 0)
40
41 # Update the array
42 ret.append(byte)
43
44 return "#%s" % ret.hex()
45
eb06d20a 46def lighten(colour, scale=0.25):
80eb8d10
MT
47 """
48 Takes a hexadecimal colour code
49 and brightens the colour.
50 """
51 return _add(colour, scale)
52
eb06d20a 53def darken(colour, scale=0.25):
80eb8d10
MT
54 """
55 Takes a hexadecimal colour code
56 and darkens the colour.
57 """
58 return _add(colour, -scale)
59
60def transparency(colour, scale=0.1):
61 """
62 Adds transparency to the given colour code
63 """
a650ac0a 64 return "%s%02X" % (colour, round(0xff * scale))
03ba5630 65
29455c5f
MT
66BLACK = "#000000"
67WHITE = "#FFFFFF"
03ba5630
MT
68GREY = "#9E9E9E"
69LIGHT_GREY = "#F5F5F5"
29455c5f 70
03ba5630
MT
71RED = "#F44336"
72LIGHT_RED = "#CC0033"
73YELLOW = "#FFEB3B"
29455c5f 74LIGHT_YELLOW = "#FFFF66"
03ba5630
MT
75GREEN = "#4CAF50"
76LIGHT_GREEN = "#8BC34A"
77BLUE = "#2196F3"
78LIGHT_BLUE = "#03A9F4"
29455c5f 79
03ba5630
MT
80AMBER = "#FFC107"
81BROWN = "#795548"
82CYAN = "#00BCD4"
83INDIGO = "#3F51B5"
84LIME = "#CDDC39"
85ORANGE = "#FF9800"
86DEEP_ORANGE = "#FF5722"
87PINK = "#E91E63"
88PURPLE = "#9C27B0"
89DEEP_PURPLE = "#673AB7"
90TEAL = "#009688"
91
92COLOUR_OK = LIGHT_GREEN
93COLOUR_CRITICAL = LIGHT_RED
94COLOUR_ERROR = COLOUR_CRITICAL
95COLOUR_WARN = LIGHT_YELLOW
80eb8d10 96COLOUR_TEXT = lighten(BLACK, 0.87) # 87% grey
03ba5630
MT
97
98PRIMARY = INDIGO
99ACCENT = PINK
100
101# Lighten the areas by this factor
8185c2cd 102AREA_OPACITY = 0.75
03ba5630
MT
103STDDEV_OPACITY = 0.33
104
105# Receive and transmit
106COLOUR_RX = RED
107COLOUR_TX = GREEN
108
109# I/O
110COLOUR_READ = GREEN
111COLOUR_WRITE = RED
112
113# IPv6 + IPv4
114COLOUR_IPV6 = INDIGO
115COLOUR_IPV4 = PINK
116COLOUR_IPVX = GREY # other
117
118COLOUR_TCP = INDIGO
119COLOUR_UDP = YELLOW
120COLOUR_ICMP = PURPLE
121COLOUR_IGMP = TEAL
122COLOUR_UDPLITE = DEEP_ORANGE
123COLOUR_SCTP = LIGHT_GREEN
124COLOUR_DCCP = LIGHT_BLUE
125COLOUR_OTHER = COLOUR_IPVX
126
127# Processor
306a119a
MT
128CPU_USER = LIGHT_GREEN
129CPU_NICE = BLUE
130CPU_SYS = RED
131CPU_WAIT = DEEP_PURPLE
132CPU_IRQ = ORANGE
133CPU_SIRQ = YELLOW
134CPU_STEAL = LIGHT_BLUE
135CPU_GUEST = PINK
136CPU_GUEST_NICE = lighten(PINK, 0.8)
137CPU_IDLE = LIGHT_GREY
03ba5630
MT
138
139# Memory
140MEMORY_USED = GREEN
141MEMORY_BUFFERED = BLUE
142MEMORY_CACHED = YELLOW
143MEMORY_SWAP = RED
1eecd71a 144MEMORY_FREE = LIGHT_GREY
03ba5630 145
03ba5630
MT
146COLOURS_PROTOCOL_STATES = {
147 # General states
148 "NONE" : GREY,
149 "TIME_WAIT" : AMBER,
150
151 # TCP
152 "CLOSE" : BLACK,
80eb8d10 153 "CLOSE_WAIT" : lighten(BLACK, 0.25),
03ba5630
MT
154 "ESTABLISHED" : LIGHT_GREEN,
155 "FIN_WAIT" : ORANGE,
156 "LAST_ACK" : PURPLE,
157 "SYN_RECV" : CYAN,
158 "SYN_SENT" : TEAL,
159 "SYN_SENT2" : AMBER,
160
161 # DCCP
80eb8d10
MT
162 "CLOSEREQ" : lighten(BLACK, 0.5),
163 "CLOSING" : lighten(BLACK, 0.25),
03ba5630
MT
164 "IGNORE" : WHITE,
165 "INVALID" : RED,
166 "OPEN" : LIGHT_GREEN,
167 "PARTOPEN" : YELLOW,
168 "REQUEST" : CYAN,
169 "RESPOND" : TEAL,
29455c5f 170
03ba5630
MT
171 # SCTP
172 "CLOSED" : BLACK,
173 "COOKIE_ECHOED" : AMBER,
174 "COOKIE_WAIT" : CYAN,
175 "SHUTDOWN_ACK_SENT" : TEAL,
176 "SHUTDOWN_RECD" : PURPLE,
177 "SHUTDOWN_SENT" : LIGHT_BLUE,
178}