| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package openvpn_status_log |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 9 | ) |
| 10 | |
| 11 | var charts = collectorapi.Charts{ |
| 12 | { |
| 13 | ID: "active_clients", |
| 14 | Title: "Active Clients", |
| 15 | Units: "active clients", |
| 16 | Fam: "active_clients", |
| 17 | Ctx: "openvpn.active_clients", |
| 18 | Dims: collectorapi.Dims{ |
| 19 | {ID: "clients"}, |
| 20 | }, |
| 21 | }, |
| 22 | { |
| 23 | ID: "traffic", |
| 24 | Title: "Traffic", |
| 25 | Units: "kilobits/s", |
| 26 | Fam: "traffic", |
| 27 | Ctx: "openvpn.total_traffic", |
| 28 | Type: collectorapi.Area, |
| 29 | Dims: collectorapi.Dims{ |
| 30 | {ID: "bytes_in", Name: "in", Algo: collectorapi.Incremental, Mul: 8, Div: 1000}, |
| 31 | {ID: "bytes_out", Name: "out", Algo: collectorapi.Incremental, Mul: -8, Div: 1000}, |
| 32 | }, |
| 33 | }, |
| 34 | } |
| 35 | |
| 36 | var userCharts = collectorapi.Charts{ |
| 37 | { |
| 38 | ID: "%s_user_traffic", |
| 39 | Title: "User Traffic", |
| 40 | Units: "kilobits/s", |
| 41 | Fam: "user stats", |
| 42 | Ctx: "openvpn.user_traffic", |
| 43 | Type: collectorapi.Area, |
| 44 | Dims: collectorapi.Dims{ |
| 45 | {ID: "%s_bytes_in", Name: "in", Algo: collectorapi.Incremental, Mul: 8, Div: 1000}, |
| 46 | {ID: "%s_bytes_out", Name: "out", Algo: collectorapi.Incremental, Mul: -8, Div: 1000}, |
| 47 | }, |
| 48 | }, |
| 49 | { |
| 50 | ID: "%s_user_connection_time", |
| 51 | Title: "User Connection Time", |
| 52 | Units: "seconds", |
| 53 | Fam: "user stats", |
| 54 | Ctx: "openvpn.user_connection_time", |
| 55 | Dims: collectorapi.Dims{ |
| 56 | {ID: "%s_connection_time", Name: "time"}, |
| 57 | }, |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | func (c *Collector) addUserCharts(userName string) error { |
| 62 | cs := userCharts.Copy() |
| 63 | |
| 64 | for _, chart := range *cs { |
| 65 | chart.ID = fmt.Sprintf(chart.ID, userName) |
| 66 | for _, dim := range chart.Dims { |
| 67 | dim.ID = fmt.Sprintf(dim.ID, userName) |
| 68 | } |
| 69 | chart.MarkNotCreated() |
| 70 | } |
| 71 | return c.charts.Add(*cs...) |
| 72 | } |