Using Crafty OpenMetrics for Monitoring
This document covers Crafty's Open Metrics implementation, which allows for comprehensive monitoring and scraping of Crafty Statistics by prometheus.
With this functionality, users can leverage platforms like Grafana to visualize and monitor host metrics, Crafty's operational stats, and individual server statistics.
Available Metrics Endpoints
Crafty provides several endpoints for metrics collection, each serving a specific set of data:
/metrics- Global Crafty metrics, including Python runtime stats and Crafty instance information./metrics/host- Host machine metrics, including CPU and memory usage of the system Crafty is running on./metrics/servers/{serverID}- Detailed metrics for an individual managed server. The{serverID}value is the server’s UUID, not a numeric database index.
For a complete reference to all the data points available through these endpoints, as well as curl examples please consult the Crafty API Documentation.
User Permissions and Access
Server administrators (SuperUsers) have unfettered access to all server statistics via the Open Metrics endpoints. Non-admin users must be assigned a specific role linked to a server to access its statistics.
Prometheus Configuration
To integrate with Prometheus, you will need to configure Prometheus to scrape metrics from Crafty's endpoints.
API Token Preparation
Remember, API tokens are sensitive and should be kept secure. Ensure that they are not exposed in configuration files or logs.
Prometheus Configs
In your prometheus.yml, add the following jobs under the existing scrape_configs: section.
- job_name: 'crafty-global'
scheme: https
metrics_path: /metrics
scrape_interval: 5s
tls_config:
# For self-signed certs while testing – better to install a CA in production
insecure_skip_verify: true
authorization:
type: Bearer
# Prometheus sends: Authorization: Bearer <contents of this file>
credentials_file: /etc/prometheus/secrets/crafty_token
static_configs:
- targets:
- '127.0.0.1:8443'
- job_name: 'crafty-host'
scheme: https
metrics_path: /metrics/host
scrape_interval: 5s
tls_config:
# For self-signed certs while testing – better to install a CA in production
insecure_skip_verify: true
authorization:
type: Bearer
# Prometheus sends: Authorization: Bearer <contents of this file>
credentials_file: /etc/prometheus/secrets/crafty_token
static_configs:
- targets:
- '127.0.0.1:8443'
- job_name: 'crafty-server-ef3fb2d1'
scheme: https
metrics_path: /metrics/servers/ef3fb2d1-a94c-4d9b-8c65-c4274be706cb'
scrape_interval: 5s
tls_config:
# For self-signed certs while testing – better to install a CA in production
insecure_skip_verify: true
authorization:
type: Bearer
# Prometheus sends: Authorization: Bearer <contents of this file>
credentials_file: /etc/prometheus/secrets/crafty_token
static_configs:
- targets:
- '127.0.0.1:8443'
labels:
crafty_server_id: 'ef3fb2d1-a94c-4d9b-8c65-c4274be706cb'
crafty_server_name: 'ExampleServer'
- job_name: 'crafty-servers'
scheme: https
scrape_interval: 5s
tls_config:
# For self-signed certs while testing – better to install a CA in production
insecure_skip_verify: true
authorization:
type: Bearer
# Prometheus sends: Authorization: Bearer <contents of this file>
credentials_file: /etc/prometheus/secrets/crafty_token
static_configs:
- targets:
- '127.0.0.1:8443'
labels:
__metrics_path__: '/metrics/servers/ef3fb2d1-a94c-4d9b-8c65-c4274be706cb'
crafty_server_name: 'Lobby'
- targets:
- '127.0.0.1:8443'
labels:
__metrics_path__: '/metrics/servers/another-server-id-here'
crafty_server_name: 'Survival'
With these metrics, system administrators can keep a close eye on server health, performance, and user activities, enabling proactive maintenance and swift response to any issues.