Skip to content

Commit 3b236a6

Browse files
authored
Merge pull request #1 from patrickjahns/initial_version
Initial version
2 parents 3756cb8 + db0e714 commit 3b236a6

File tree

11 files changed

+721
-20
lines changed

11 files changed

+721
-20
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ ifndef REVISION
2828
endif
2929

3030
LDFLAGS += -s -w
31-
LDFLAGS += -X "$(IMPORT)/pkg/version.String=$(VERSION)"
32-
LDFLAGS += -X "$(IMPORT)/pkg/version.Date=$(DATE)"
31+
LDFLAGS += -X "$(IMPORT)/pkg/version.Version=$(VERSION)"
32+
LDFLAGS += -X "$(IMPORT)/pkg/version.BuildDate=$(DATE)"
3333
LDFLAGS += -X "$(IMPORT)/pkg/version.Revision=$(REVISION)"
3434

3535
.PHONY: all
@@ -38,6 +38,7 @@ all: build
3838
.PHONY: clean
3939
clean:
4040
$(GO) clean -i ./...
41+
rm -rf $(BIN)/
4142
rm -rf $(DIST)/
4243

4344
.PHONY: sync

example/version1.status

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
OpenVPN CLIENT LIST
2+
Updated,Thu Apr 23 20:14:31 2020
3+
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
4+
user1,1.2.3.4:60102,7883858,7762340,Wed Apr 22 12:36:42 2020
5+
user2,1.2.3.5:50976,1673200,2065632,Wed Apr 22 12:36:52 2020
6+
[email protected],1.2.3.6:57688,19602844,23599532,Wed Apr 22 12:42:45 2020
7+
user4,1.2.3.7:40832,582207,575193,Wed Apr 22 12:36:54 2020
8+
ROUTING TABLE
9+
Virtual Address,Common Name,Real Address,Last Ref
10+
10.240.1.222,user4,1.2.3.7:40832,Wed Apr 22 12:36:56 2020
11+
10.240.10.126,user1,1.2.3.4:50976,Thu Apr 23 18:44:56 2020
12+
10.240.79.134,user2,1.2.3.5:60102,Thu Apr 23 20:14:30 2020
13+
10.240.37.214,[email protected],1.2.3.6:57688,Thu Apr 23 20:14:16 2020
14+
GLOBAL STATS
15+
Max bcast/mcast queue length,5
16+
END

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/patrickjahns/openvpn_exporter
33
go 1.14
44

55
require (
6-
github.com/hashicorp/go-version v1.2.0 // indirect
7-
github.com/mitchellh/gox v1.0.1 // indirect
6+
github.com/go-kit/kit v0.9.0
7+
github.com/prometheus/client_golang v1.5.1
88
github.com/urfave/cli/v2 v2.2.0
99
)

go.sum

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,103 @@
11
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2+
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
4+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
5+
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
6+
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
7+
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
8+
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
9+
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
10+
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
11+
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
212
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
313
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
4-
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
5-
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
6-
github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E=
7-
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
8-
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
9-
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
10-
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
11-
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
14+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
17+
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
18+
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
19+
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
20+
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
21+
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
22+
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
23+
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
24+
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
25+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
26+
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
27+
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
28+
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
29+
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
30+
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
31+
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
32+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
33+
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
34+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
35+
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
36+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
37+
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
38+
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
39+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
40+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
41+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
42+
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
43+
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
44+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
45+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
46+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
47+
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
48+
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
49+
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
50+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1251
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1352
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
53+
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
54+
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
55+
github.com/prometheus/client_golang v1.5.1 h1:bdHYieyGlH+6OLEk2YQha8THib30KP0/yD0YH9m6xcA=
56+
github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU=
57+
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
58+
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
59+
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
60+
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
61+
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
62+
github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U=
63+
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
64+
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
65+
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
66+
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
67+
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
1468
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
1569
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1670
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
1771
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
72+
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
73+
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
74+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
75+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
76+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
77+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
78+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
1879
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
1980
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
81+
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
82+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
83+
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
84+
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
85+
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
86+
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
87+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
88+
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
89+
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
90+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
91+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
92+
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU=
93+
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
94+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
95+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
96+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
97+
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
2098
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
99+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
100+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
21101
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
102+
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
103+
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

pkg/collector/exporter.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package collector
2+
3+
import (
4+
"time"
5+
6+
"github.com/go-kit/kit/log"
7+
"github.com/go-kit/kit/log/level"
8+
"github.com/prometheus/client_golang/prometheus"
9+
)
10+
11+
const (
12+
// namespace defines the namespace for the exporter.
13+
namespace = "openvpn"
14+
)
15+
16+
// GeneralCollector collects metrics, mostly runtime, about this exporter in general.
17+
type GeneralCollector struct {
18+
logger log.Logger
19+
version string
20+
revision string
21+
buildDate string
22+
goVersion string
23+
started time.Time
24+
25+
StartTime *prometheus.Desc
26+
BuildInfo *prometheus.Desc
27+
}
28+
29+
// NewGeneralCollector returns a new GeneralCollector.
30+
func NewGeneralCollector(logger log.Logger, version string, revision string, buildDate string, goVersion string, started time.Time) *GeneralCollector {
31+
return &GeneralCollector{
32+
logger: logger,
33+
version: version,
34+
revision: revision,
35+
buildDate: buildDate,
36+
goVersion: goVersion,
37+
started: started,
38+
39+
StartTime: prometheus.NewDesc(
40+
prometheus.BuildFQName(namespace, "", "start_time"),
41+
"Unix timestamp of the start time",
42+
nil,
43+
nil,
44+
),
45+
46+
BuildInfo: prometheus.NewDesc(
47+
prometheus.BuildFQName(namespace, "", "build_info"),
48+
"A metric with a constant '1' value labeled by version information",
49+
[]string{"version", "revision", "date", "go"},
50+
nil,
51+
),
52+
}
53+
}
54+
55+
// Describe sends the super-set of all possible descriptors of metrics collected by this Collector.
56+
func (c *GeneralCollector) Describe(ch chan<- *prometheus.Desc) {
57+
ch <- c.StartTime
58+
ch <- c.BuildInfo
59+
}
60+
61+
// Collect is called by the Prometheus registry when collecting metrics.
62+
func (c *GeneralCollector) Collect(ch chan<- prometheus.Metric) {
63+
level.Debug(c.logger).Log(
64+
"started", c.started.Unix(),
65+
"version", c.version,
66+
"revision", c.revision,
67+
"buildDate", c.buildDate,
68+
"goVersion", c.goVersion,
69+
"started", c.started,
70+
)
71+
ch <- prometheus.MustNewConstMetric(
72+
c.StartTime,
73+
prometheus.GaugeValue,
74+
float64(c.started.Unix()),
75+
)
76+
77+
ch <- prometheus.MustNewConstMetric(
78+
c.BuildInfo,
79+
prometheus.GaugeValue,
80+
1.0,
81+
c.version,
82+
c.revision,
83+
c.buildDate,
84+
c.goVersion,
85+
)
86+
}

pkg/collector/openvpn.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package collector
2+
3+
import (
4+
"github.com/go-kit/kit/log"
5+
"github.com/go-kit/kit/log/level"
6+
"github.com/patrickjahns/openvpn_exporter/pkg/openvpn"
7+
"github.com/prometheus/client_golang/prometheus"
8+
)
9+
10+
// OpenVPNCollector collects metrics from openvpn status files
11+
type OpenVPNCollector struct {
12+
logger log.Logger
13+
name string
14+
statusFile string
15+
LastUpdated *prometheus.Desc
16+
ConnectedClients *prometheus.Desc
17+
BytesReceived *prometheus.Desc
18+
BytesSent *prometheus.Desc
19+
ConnectedSince *prometheus.Desc
20+
MaxBcastMcastQueueLen *prometheus.Desc
21+
}
22+
23+
// NewOpenVPNCollector returns a new OpenVPNCollector
24+
func NewOpenVPNCollector(logger log.Logger, name string, statusFile string) *OpenVPNCollector {
25+
return &OpenVPNCollector{
26+
logger: logger,
27+
statusFile: statusFile,
28+
name: name,
29+
30+
LastUpdated: prometheus.NewDesc(
31+
prometheus.BuildFQName(namespace, "", "last_updated"),
32+
"Unix timestamp when the last time the status was updated",
33+
[]string{"server"},
34+
nil,
35+
),
36+
ConnectedClients: prometheus.NewDesc(
37+
prometheus.BuildFQName(namespace, "", "connections"),
38+
"Amount of currently connected clients",
39+
[]string{"server"},
40+
nil,
41+
),
42+
MaxBcastMcastQueueLen: prometheus.NewDesc(
43+
prometheus.BuildFQName(namespace, "", "max_bcast_mcast_queue_len"),
44+
"MaxBcastMcastQueueLen of the server",
45+
[]string{"server"},
46+
nil,
47+
),
48+
BytesReceived: prometheus.NewDesc(
49+
prometheus.BuildFQName(namespace, "", "bytes_received"),
50+
"Amount of data received via the connection",
51+
[]string{"server", "common_name"},
52+
nil,
53+
),
54+
BytesSent: prometheus.NewDesc(
55+
prometheus.BuildFQName(namespace, "", "bytes_sent"),
56+
"Amount of data sent via the connection",
57+
[]string{"server", "common_name"},
58+
nil,
59+
),
60+
ConnectedSince: prometheus.NewDesc(
61+
prometheus.BuildFQName(namespace, "", "connected_since"),
62+
"Unixtimestamp when the connection was established",
63+
[]string{"server", "common_name"},
64+
nil,
65+
),
66+
}
67+
}
68+
69+
// Describe sends the super-set of all possible descriptors of metrics collected by this Collector.
70+
func (c *OpenVPNCollector) Describe(ch chan<- *prometheus.Desc) {
71+
ch <- c.LastUpdated
72+
ch <- c.ConnectedClients
73+
ch <- c.BytesSent
74+
ch <- c.BytesReceived
75+
ch <- c.ConnectedSince
76+
ch <- c.MaxBcastMcastQueueLen
77+
}
78+
79+
// Collect is called by the Prometheus registry when collecting metrics.
80+
func (c *OpenVPNCollector) Collect(ch chan<- prometheus.Metric) {
81+
level.Debug(c.logger).Log(
82+
"statusFile", c.statusFile,
83+
"name", c.name,
84+
)
85+
status, err := openvpn.ParseFile(c.statusFile)
86+
if err != nil {
87+
level.Warn(c.logger).Log(
88+
"msg", "error parsing statusfile",
89+
"err", err,
90+
)
91+
return
92+
}
93+
94+
connectedClients := 0
95+
for _, client := range status.ClientList {
96+
connectedClients++
97+
level.Debug(c.logger).Log(
98+
"commonName", client.CommonName,
99+
"connectedSince", client.ConnectedSince.Unix(),
100+
"bytesReceived", client.BytesReceived,
101+
"bytesSent", client.BytesSent,
102+
)
103+
ch <- prometheus.MustNewConstMetric(
104+
c.BytesReceived,
105+
prometheus.GaugeValue,
106+
client.BytesReceived,
107+
c.name, client.CommonName,
108+
)
109+
ch <- prometheus.MustNewConstMetric(
110+
c.BytesSent,
111+
prometheus.GaugeValue,
112+
client.BytesSent,
113+
c.name, client.CommonName,
114+
)
115+
ch <- prometheus.MustNewConstMetric(
116+
c.ConnectedSince,
117+
prometheus.GaugeValue,
118+
float64(client.ConnectedSince.Unix()),
119+
c.name, client.CommonName,
120+
)
121+
}
122+
level.Debug(c.logger).Log(
123+
"updatedAt", status.UpdatedAt,
124+
"connectedClients", connectedClients,
125+
"maxBcastMcastQueueLen", status.GlobalStats.MaxBcastMcastQueueLen,
126+
)
127+
ch <- prometheus.MustNewConstMetric(
128+
c.ConnectedClients,
129+
prometheus.GaugeValue,
130+
float64(connectedClients),
131+
c.name,
132+
)
133+
ch <- prometheus.MustNewConstMetric(
134+
c.LastUpdated,
135+
prometheus.GaugeValue,
136+
float64(status.UpdatedAt.Unix()),
137+
c.name,
138+
)
139+
ch <- prometheus.MustNewConstMetric(
140+
c.MaxBcastMcastQueueLen,
141+
prometheus.GaugeValue,
142+
float64(status.GlobalStats.MaxBcastMcastQueueLen),
143+
c.name,
144+
)
145+
}

0 commit comments

Comments
 (0)