Giter Club home page Giter Club logo

ocserv-exporter's Introduction

Latest Go CI GitHub

Prometheus ocserv exporter

This exporter allows to expose statistics from ocserv in Prometheus format. It simply parses the output of occtl tool to gather VPN server and user statistics.

Usage

Installation

Binaries can be download from the Github releases page.

Running

Start ocserv-exporter as a daemon or from CLI on the same host running ocserv (use-occtl = true must be set in ocserv configuration):

$ ./ocserv-exporter
$ curl -s http://127.0.0.1:8000/metrics
occtl_status_scrape_error_total 0
occtl_users_scrape_error_total 0
vpn_active_sessions 29
vpn_authentication_failures 32
vpn_average_auth_time_seconds 0
vpn_average_session_time_seconds 9960
vpn_closed_error_sessions 0
vpn_handled_sessions 589
vpn_ips_banned 0
vpn_max_auth_time_seconds 46
vpn_max_session_time_seconds 43200
vpn_rx_bytes 2.4823e+07
vpn_sessions_handled 139
vpn_timed_out_idle_sessions 0
vpn_timed_out_sessions 0
vpn_total_authentication_failures 171
vpn_tx_bytes 2.84913e+08
vpn_user_rx_bytes{device="vpns0",mtu="1434",remote_ip="203.0.113.0",username="j.doe",vpn_ipv4="10.0.0.1",vpn_ipv6=""} 962053
vpn_user_rx_bytes{device="vpns1",mtu="1434",remote_ip="203.0.113.1",username="a.bob",vpn_ipv4="10.0.0.2",vpn_ipv6=""} 532733
vpn_user_tx_bytes{device="vpns0",mtu="1434",remote_ip="203.0.113.0",username="j.doe",vpn_ipv4="10.0.0.1",vpn_ipv6=""} 3.474418e+06
vpn_user_tx_bytes{device="vpns1",mtu="1434",remote_ip="203.0.113.1",username="a.bob",vpn_ipv4="10.0.0.2",vpn_ipv6=""} 200146

Command line flags

Name Description
interval Delay between occtl scrape (default 30s)
listen Prometheus HTTP listen IP and port (default "127.0.01:8000")

Prometheus Configuration

Example config:

scrape_configs:
  - job_name: 'ocserv-exporter'
    scrape_interval: 30s
    static_configs:
      - targets:
        - 127.0.0.1:8000  # The ocserv exporter's real ip:port
    metrics_path: /metrics

Contributing

Contributions are welcome! Before starting work on significant changes, please create an issue first.

Commit message

Use Conventional Commits. Conventional commit messages is enforced by the CI.

ocserv-exporter's People

Contributors

dimitripapadopoulos avatar fdomain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocserv-exporter's Issues

No info about connected users

Hi! Thank you for your project!
Unfortunately, I get error (in exporter stdout) when the user is connected to ocserv:
ERRO[0000] Failed to get users details: error while decoding json json: cannot unmarshal number 4.9 MB/sec into Go struct field UsersMessage.TX of type int64
and I don't see "vpn_user_rx_bytes" block in /metrics page

I have ocserv 1.2.0 with rx/tx limits. Of course I activated use-occtl parameter. I use this docker image - evilbox/ocserv:1.2.0

Limits in ocserv.conf:
rx-data-per-sec = 4900000
tx-data-per-sec = 4900000

when I use "occtl --json show users" I get this json (maybe this will help)

[
  {
    "ID":  44,
    "Username":  "user_me-xi09",
    "Groupname":  "(none)",
    "State":  "connected",
    "vhost":  "default",
    "Device":  "vpn0",
    "MTU":  "1434",
    "Remote IP":  "37.XXX.XXX.XXX",
    "Location":  "unknown",
    "Local Device IP":  "100.XXX.XXX.XXX",
    "IPv4":  "10.XXX.XXX.XXX",
    "P-t-P IPv4":  "10.XXX.XXX.XXX",
    "User-Agent":  "AnyConnect AppleSSLVPN_Darwin_ARM (iPhone) 5.0.02602",
    "Limit RX":  "4.9 MB/sec",
    "TX":  "4.9 MB/sec",
    "RX":  "12209987",
    "TX":  "574756426",
    "_RX":  "12.2 MB",
    "_TX":  "574.8 MB",
    "Average RX":  "2.0 KB/sec",
    "Average TX":  "93.3 KB/sec",
    "DPD":  "90",
    "KeepAlive":  "32400",
    "Hostname":  "iPhone-User",
    "Connected at":  "2023-08-10 11:03",
    "_Connected at":  " 1h:42m",
    "Full session":  "XXXXXXXXXXIuq4czpcPRGGwOaO0=",
    "Session":  "XXXkJL",
    "TLS ciphersuite":  "(TLS1.3)-(ECDHE-SECP256R1)-(ECDSA-SECP256R1-SHA256)-(AES-256-GC",
    "DTLS cipher":  "(DTLS1.2)-(ECDHE-RSA)-(AES-256-GCM)",
    "DNS":	["100.XXX.XXX.XXX"],
    "NBNS":	[],
    "Split-DNS-Domains":	[],
    "Routes":	[],
    "Routes":  "defaultroute",
    "No-routes":	[],
    "iRoutes":	[],
    "Restricted to routes":  "False",
    "Restricted to ports":	[]
  }
]

and I see the same text (4.9 MB/sec)

Can you know how to resolve this error? Thank you so much again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.