Projet

Général

Profil

Révision 3c20ac15

ID3c20ac15f4a9ccea5ed77649f95f95af4c20c9f6
Parent 38f3a429
Enfant d212e126

Ajouté par Codimp il y a presque 4 ans

[exodus_] Add plugin to monitore number of applications, reports and trackers (#1286)

Add monitoring of count for applications, reports and trackers of an
exodus instance.

Voir les différences:

plugins/exodus/exodus_
1
#!/usr/bin/env python3
2
"""
3
=head1 NAME
4

  
5
exodus_ - Exodus wildcard-plugin to monitor an L<Exodus|https://github.com/Exodus-Privacy/exodus/>
6
instance.
7

  
8
This wildcard plugin provides the suffixes C<applications>, C<reports> and C<trackers>.
9

  
10
=head1 INSTALLATION
11

  
12
- Copy this plugin in your munin plugins directory
13

  
14
=over 2
15

  
16
    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_applications
17
    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_reports
18
    ln -s /usr/share/munin/plugins/exodus_ /etc/munin/plugins/exodus_trackers
19

  
20
=back
21

  
22
After the installation you need to restart your munin-node service.
23

  
24
=head1 CONFIGURATION
25

  
26
You need to create a file named exodus placed in the directory
27
/etc/munin/plugin-conf.d/ with the following config:
28

  
29
=over 2
30

  
31
    [exodus_*]
32
    env.exodus_url https://reports.exodus-privacy.eu.org
33
    env.exodus_token your-api-token
34

  
35
=back
36

  
37
=head1 AUTHORS
38

  
39
Codimp <contact@lithio.fr>
40

  
41
=head1 LICENSE
42

  
43
GPLv3
44

  
45
=head1 MAGIC MARKERS
46

  
47
 #%# family=manual
48
 #%# capabilities=suggest
49

  
50
=cut
51
"""
52

  
53
import os
54
import sys
55
import json
56
import urllib.request
57

  
58

  
59
def print_count(element):
60
    endpoint = os.getenv("exodus_url") + "/api/" + element + "/count"
61
    headers = {"Authorization": "Token " + os.getenv("exodus_token")}
62
    request = urllib.request.Request(endpoint, method="POST", headers=headers)
63
    with urllib.request.urlopen(request) as connection:
64
        if connection.getcode() == 200:
65
            count = json.loads(connection.read())["count"]
66
            print(element + ".value", count)
67

  
68

  
69
def main():
70
    try:
71
        mode = sys.argv[1]
72
    except IndexError:
73
        mode = ""
74
    wildcard = sys.argv[0].split("exodus_")[1]
75

  
76
    if mode == "suggest":
77
        print("applications")
78
        print("reports")
79
        print("trackers")
80
        exit(0)
81

  
82
    if wildcard == "applications":
83
        if mode == "config":
84
            print("graph_title Exodus applications")
85
            print("graph_vlabel applications")
86
            print("graph_category exodus")
87
            print("applications.label Applications")
88
        else:
89
            print_count("applications")
90
    elif wildcard == "reports":
91
        if mode == "config":
92
            print("graph_title Exodus reports")
93
            print("graph_vlabel reports")
94
            print("graph_category exodus")
95
            print("reports.label Reports")
96
        else:
97
            print_count("reports")
98
    elif wildcard == "trackers":
99
        if mode == "config":
100
            print("graph_title Exodus trackers")
101
            print("graph_vlabel trackers")
102
            print("graph_category exodus")
103
            print("trackers.label Trackers")
104
        else:
105
            print_count("trackers")
106

  
107

  
108
if __name__ == "__main__":
109
    main()

Formats disponibles : Unified diff