1
+# -*- coding: utf-8 -*-
2
+# Description: logind netdata python.d module
3
+# Author: Austin S. Hemmelgarn (Ferroin)
4
+# SPDX-License-Identifier: GPL-3.0+
5
+
6
+import os
7
+import sys
8
+
9
+from bases.FrameworkServices.ExecutableService import ExecutableService
10
+
11
+PRIORITY = 40000
12
+
13
+ORDER = ['sessions', 'users', 'seats']
14
+
15
+CHARTS = {
16
+ 'sessions': {
17
+ 'options': [None, 'Logind Sessions', 'sessions', 'sessions', 'logind.sessions', 'stacked'],
18
+ 'lines': [
19
+ ['sessions_graphical', 'Graphical', 'absolute', 1, 1],
20
+ ['sessions_console', 'Console', 'absolute', 1, 1],
21
+ ['sessions_remote', 'Remote', 'absolute', 1, 1]
22
+ ]
23
+ },
24
+ 'users': {
25
+ 'options': [None, 'Logind Users', 'users', 'users', 'logind.users', 'stacked'],
26
+ 'lines': [
27
+ ['users_graphical', 'Graphical', 'absolute', 1, 1],
28
+ ['users_console', 'Console', 'absolute', 1, 1],
29
+ ['users_remote', 'Remote', 'absolute', 1, 1]
30
+ ]
31
+ },
32
+ 'seats': {
33
+ 'options': [None, 'Logind Seats', 'seats', 'seats', 'logind.seats', 'line'],
34
+ 'lines': [
35
+ ['seats', 'Active Seats', 'absolute', 1, 1]
36
+ ]
37
+ }
38
+}
39
+
40
+
41
+class Service(ExecutableService):
42
+ def __init__(self, configuration=None, name=None):
43
+ ExecutableService.__init__(self, configuration=configuration, name=name)
44
+ self.command = 'loginctl list-sessions --no-legend'
45
+ self.order = ORDER
46
+ self.definitions = CHARTS
47
+
48
+ def _get_data(self):
49
+ ret = {
50
+ 'sessions_graphical': 0,
51
+ 'sessions_console': 0,
52
+ 'sessions_remote': 0,
53
+ }
54
+ users = {
55
+ 'graphical': list(),
56
+ 'console': list(),
57
+ 'remote': list()
58
+ }
59
+ seats = list()
60
+ data = self._get_raw_data()
61
+
62
+ for item in data:
63
+ fields = item.split()
64
+ if len(fields) == 3:
65
+ users['remote'].append(fields[2])
66
+ ret['sessions_remote'] += 1
67
+ elif len(fields) == 4:
68
+ users['graphical'].append(fields[2])
69
+ ret['sessions_graphical'] += 1
70
+ seats.append(fields[3])
71
+ elif len(fields) == 5:
72
+ users['console'].append(fields[2])
73
+ ret['sessions_console'] += 1
74
+ seats.append(fields[3])
75
+
76
+ ret['users_graphical'] = len(set(users['graphical']))
77
+ ret['users_console'] = len(set(users['console']))
78
+ ret['users_remote'] = len(set(users['remote']))
79
+ ret['seats'] = len(set(seats))
80
+
81
+ return ret