Git Product home page Git Product logo

srcds_exporter's Introduction

Prometheus SRCDS Exporter

This is an exporter for the Prometheus monitoring system. It exports data from SRCDS Gameservers (e.g. CSGO, TF2, L4D2, ...) via rcon. It uses the status and stats commands for this.

Supported Servers:

  • CSGO
  • CSS
  • L4D2
  • FoF
  • HL2DM
  • TF2
  • Gmod

How to install:

  1. git clone https://github.com/991jo/srcds_exporter.git
  2. cd srcds_exporter
  3. python3 -m venv .
  4. source bin/activate
  5. pip install -r requirements.txt
  6. python3 main.py

Multi-Server vs. Single Server Mode

Initially this software was build as an exporter which can query many servers. This conflicts a bit with the Prometheus Exporter mentality that you should run one exporter per instance of your application. Also you would have to know the RCON password which would get passed around in HTTP requests. Therefore SRCDS Exporter now supports the single server mode. In this mode you have to specify the ip, port and password as a start parameter. But your HTTP requests dont need those parameters anymore. Also the exporter does not answer requests which have those fields set.

How to query via Prometheus:

Multi-Server-Mode

You can use the following example config. Please adjust the IP:port in the last row to the IP:port your exporter uses.

  - job_name: srcds

    scrape_interval: 5s

    metrics_path: /metrics

    static_configs:
          - targets: ["<ip>:<port>:<rconpassword>"]

    relabel_configs:
        - source_labels: [__address__]
          regex: "(.+:.+):.+"
          replacement: "$1"
          target_label: __param_target
        - source_labels: [__address__]
          regex: ".+:.+:(.+)"
          replacement: "$1"
          target_label: __param_password
        - source_labels: [__param_target]
          target_label: instance
        - target_label: __address__
          replacement: 127.0.0.1:9591 # The real ip/port of the srcds_exporter

Basically you have to build this URL: http://<exporter-address>:9591/metrics?target=<host>:<port>&password=<yourrconpassword> You can use this URL for debugging purposes ;)

Single-Server-Mode

For the single server mode you have to specify the parameters on the commandline.

python3 main.py --server_address <server address> --server_port <port> --password <rcon password>

Your Prometheus config could look like this:

  - job_name: srcds

    scrape_interval: 5s

    metrics_path: /metrics

    static_configs:
          - targets: ["<ip>:<port>"]

Known issues

Some servers do not respond to RCON while changing maps. This results in timeouts and connection errors for the exporter. This means that you won't get data while the server changes the map. This is okay because many of the metrics are irrelevant during map change anyway (e.g. the server FPS rate).

Getting Help

For a list of the commandline arguments start the exporter with the --help flag. If you have other problems, feel free to open an issue.

TODO

  • make example config for Prometheus
  • investigate aiorcon not timing out properly
  • make ip and port configurable
  • add a systemd unit file

Docker Support

The Dockerfile was added by [https://github.com/xvzf]. Thanks for that. I am not using docker, I can not give you support on that.

More information

I wrote a blog post about this exporter. You can find it here

Further information regarding var, varms and sv

(https://www.reddit.com/r/GlobalOffensive/comments/23zt18/explanation_of_the_new_net_graph_thanks_vitaliy/)

srcds_exporter's People

Contributors

techsupportjosh avatar xvzf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

srcds_exporter's Issues

Make it possible to run the exporter locally with a server

The Prometheus exporter docs say that if possible 1 exporter should run per service on the same host/VM/container/whatever.
Add commandline options to give the ip, port and the password which the exporter should use to query a server.

Error while running script

While the script is running it will throw this out every so often. I am running the scraper every 5s like your example. I also have 14 servers set to scrape in this way in the prometheus.yml:

        - targets: ["172.217.165.14:27015:password"] 
        - targets: ["172.217.165.14:27020:password"] 
[14/04/2019 18:14] ERROR test handler 135:
Traceback (most recent call last):
  File "test.py", line 81, in handler
    status, stats = await rcon_query(ip, port, password)
  File "test.py", line 58, in rcon_query
    2)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 404, in wait_for
    raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

as well as:

 Traceback (most recent call last):
  File "main.py", line 82, in handler
    status, stats = await rcon_query(ip, port, password)
  File "main.py", line 59, in rcon_query
    2)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/home/test/.local/lib/python3.5/site-packages/aiorcon/rcon.py", line 32, in create
    await rcon._connect()
  File "/home/test/.local/lib/python3.5/site-packages/aiorcon/rcon.py", line 37, in _connect
    await protocol.authenticate()
  File "/home/test/.local/lib/python3.5/site-packages/aiorcon/protocol.py", line 40, in wrapper
    return await func(instance, *args, **kwargs)
  File "/home/test/.local/lib/python3.5/site-packages/aiorcon/protocol.py", line 78, in authenticate
    res = await self._receive()
  File "/home/test/.local/lib/python3.5/site-packages/aiorcon/protocol.py", line 99, in _receive
    await self._waiters[id_]
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
aiorcon.exceptions.RCONClosedError: Connection closed before message was received

Error when using exporter

This is the output I get when I run the script. (I added traceback)

Python Version: Python 3.5.3

Running it with the debug URL:

[14/04/2019 01:06] INFO test <module> 19: Using uvloop
[14/04/2019 01:07] ERROR test handler 134: 'coroutine' object is not iterable
Traceback (most recent call last):
  File "main.py", line 83, in handler
    status, stats = rcon_query(ip, port, password)
TypeError: 'coroutine' object is not iterable
[14/04/2019 01:07] INFO web_log log 233: 127.0.0.1 [14/Apr/2019:01:07:10 +0000] "GET /metrics?target=127.0.0.1:27015&password=password HTTP/1.1" 200 227 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"

Running it from Promethus:

[14/04/2019 01:11] ERROR test handler 134: 'coroutine' object is not iterable
Traceback (most recent call last):
  File "main.py", line 83, in handler
    status, stats = rcon_query(ip, port, password)
TypeError: 'coroutine' object is not iterable
[14/04/2019 01:11] INFO web_log log 233: 127.0.0.1 [14/Apr/2019:01:11:21 +0000] "GET /metrics?password=password&target=127.0.0.1:27015 HTTP/1.1" 200 227 "-" "Prometheus/2.8.1

Counter-Strike: Source

Hi mate, to get this to work nicely for CS:S, I had to change:

playerCountRegex = regexp.MustCompile(`(?m)^players : (?P<current1>([0-9]+)) humans, (?P<bots>[0-9]+) bots \((?P<max2>[0-9]+) max\)`)
playerRegex      = regexp.MustCompile(`(?m)^#[ ]+(\d+)\s\"(.+)\"\s+?(\[.+\])\s+([\d|\:]+)\s+(\d+)\s+(\d+)\s+(\w+)\s+([\d|\.]+)\:(\d+)$`)

and for the extraction part:

for _, m := range matches {
        userID, _ := strconv.Atoi(m[1])
        ping, _ := strconv.Atoi(m[5])
        loss, _ := strconv.Atoi(m[6])
        connPort, _ := strconv.Atoi(m[9])
        players[m[3]] = &models.Player{
                Username: m[2],
                UserID:   userID,
                SteamID:  m[3],
                State:    m[7],
                Ping:     ping,
                Loss:     loss,
                IP:       m[8],
                ConnPort: connPort,
        }
}

Just leaving this here in case you want to officially add support for it.

make srcds_exporter hl2dm compatible

Sample stats output:

rcon from "10.10.0.100:37956": command "status"
CPU    In_(KB/s)  Out_(KB/s)  Uptime  Map_changes  FPS      Players  Connects
0.00   0.00       0.00        3       0            66.72    0        0

Adopt for TF2 stats

TF2 uses this format in the stats command:

CPU    In_(KB/s)  Out_(KB/s)  Uptime  Map_changes  FPS      Players  Connects
0.00   2.11       2.41        3       0            66.32    1        1

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.