]> git.99rst.org Git - openwrt-luci.git/blob
fea570f8d3b6aad09a289148af05b46f92223009
[openwrt-luci.git] /
1 /* Licensed to the public under the Apache License 2.0. */
2
3 'use strict';
4 'require baseclass';
5
6 return baseclass.extend({
7 title: _('OpenVPN'),
8
9 rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
10 var inst = plugin_instance.replace(/^openvpn\.(.+)\.status$/, '$1');
11 const types = graph.dataTypes(host, plugin, plugin_instance);
12 const rv = [];
13 let instances;
14 const typeinstances = graph.dataInstances(host, plugin, plugin_instance, "if_octets").sort();
15
16 function find_instances(dtype, wanted) {
17 const matching = graph.dataInstances(host, plugin, plugin_instance, dtype).filter(function(instance) {
18 return wanted.indexOf(instance) > -1;
19 });
20 return matching.length ? { [dtype]: matching } : null;
21 }
22
23 if ((instances = find_instances('if_octets', ['overhead', 'traffic'])) !== null) {
24 rv.push({
25 title: "%%H: OpenVPN \"%s\" - Traffic".format(inst),
26 vlabel: "Bytes/s",
27 data: {
28 instances: {
29 if_octets: [ "traffic", "overhead" ]
30 },
31 sources: {
32 if_octets: [ "tx", "rx" ]
33 },
34 options: {
35 if_octets_traffic_tx : { weight: 0, title: "Bytes (TX)", total: true, color: "00ff00" },
36 if_octets_overhead_tx: { weight: 1, title: "Overhead (TX)", total: true, color: "ff9900" },
37 if_octets_overhead_rx: { weight: 2, title: "Overhead (RX)", total: true, flip: true, color: "ff00ff" },
38 if_octets_traffic_rx : { weight: 3, title: "Bytes (RX)", total: true, flip: true, color: "0000ff" }
39 }
40 }
41 });
42 } else {
43 for (const tinstance of typeinstances) {
44 const rx = "if_octets_%s_rx".format(tinstance);
45 const tx = "if_octets_%s_tx".format(tinstance);
46 const opts = {};
47 opts[tx] = { weight: 0, title: "Bytes " + tinstance + " (TX)", total: true, color: "00ff00" };
48 opts[rx] = { weight: 1, title: "Bytes " + tinstance + " (RX)", total: true, flip: true, color: "0000ff" };
49
50 rv.push({
51 title: "%%H: OpenVPN Server \"%s\" - User Traffic - ".format(inst) + tinstance,
52 vlabel: "Bytes/s",
53 data: {
54 instances: {
55 if_octets: [ tinstance ]
56 },
57 sources: {
58 if_octets: [ "tx", "rx" ]
59 },
60 options: opts
61 }
62 });
63 }
64 }
65
66 if (types.indexOf('users') > -1) {
67 let optionUsers = `users_${plugin_instance}`;
68 let optsUsers = {};
69 optsUsers[optionUsers] = { title: "Total users connected", color: "00ff00" };
70 let userInstances = graph.dataInstances(host, plugin, plugin_instance, 'users');
71 if (userInstances.length > 0) {
72 rv.push({
73 title: `%H: OpenVPN Server "${inst}" - Connected Users`,
74 vlabel: "Users",
75 y_min: "0",
76 alt_autoscale_max: true,
77 number_format: "%3.0lf",
78 data: {
79 instances: {
80 users: userInstances
81 },
82 options: optsUsers
83 }
84 });
85 } else {
86 console.error('Source "value" not found in any user instances:', sources);
87 }
88 }
89
90 if (types.indexOf('compression') > -1) {
91 rv.push({
92 title: "%%H: OpenVPN \"%s\" - Compression".format(inst),
93 vlabel: "Bytes/s",
94 data: {
95 instances: {
96 compression: [ "data_out", "data_in" ]
97 },
98 sources: {
99 compression: [ "uncompressed", "compressed" ]
100 },
101 options: {
102 compression_data_out_uncompressed: { weight: 0, title: "Uncompressed (TX)", total: true, color: "00ff00" },
103 compression_data_out_compressed : { weight: 1, title: "Compressed (TX)", total: true, color: "008800" },
104 compression_data_in_compressed : { weight: 2, title: "Compressed (RX)", total: true, flip: true, color: "000088" },
105 compression_data_in_uncompressed : { weight: 3, title: "Uncompressed (RX)", total: true, flip: true, color: "0000ff" }
106 }
107 }
108 });
109 }
110 return rv;
111 }
112 });
git clone https://git.99rst.org/PROJECT