Using Counters

Counters play a vital role in Game Carrier, offering system monitoring capabilities that allow tracking and measuring network statistics, server load, application performance and a variety of other useful metrics.

Counters are used to measure:

  1. Number of Requests: Counting the total number of incoming requests to the server.
  2. Amount of Data Transferred: Measuring the volume of data exchanged between the server and clients.
  3. Number of Clients Connected: Providing data on the active client connections at any given time.
  4. API and Events Call Statistics: Recording the usage statistics of various APIs and events within the system.

Counters can be used to:

  1. Identify Bottlenecks: Pinpointing performance issues and areas that require optimization.
  2. Analyze Applications: Understanding the behavior and performance characteristics of applications.
  3. Optimize Network Performance: Fine-tuning the network settings to enhance overall efficiency.
  4. Detect Malicious Activities: Identifying and mitigating potential threats and malicious actions.
  5. Detect Potential Security Threats: Alerting about suspicious patterns that could indicate security risks.

Server applications can easily register their own custom counters to precisely track and analyze the performance of their applications.

The counters data is sourced from the server in real-time and projected into the interactive analytics tool available in the web portal. To access the analytics tool and corresponding data you must log into your account and navigate to the Statistics section of the dashboard. See the Statistics user guide for more information.

Counter Groups

All counters in Game Carrier can be categorized into two groups: system counters and custom counters.

  • System counters are available at any stage and can be accessed immediately.
  • Custom counters, on the other hand, become accessible and modifiable after they are created. They appear in the counterGetNames API call only during the second stage.

Counters in Game Carrier can further be classified as atomic and non-atomic:

  • Atomic counters are updated in a single operation and are thread-safe, meaning multiple threads can access and modify them simultaneously without issues.
  • Non-atomic counters, on the other hand, are updated in multiple operations and are not thread-safe, so they require synchronization mechanisms to ensure data integrity.

All system counters are inherently thread-safe and protected from modifications by applications. Additionally, applications have the option to subscribe to counter modification notification events, allowing them to receive real-time updates on specific counter changes.

Counters Format

Counter names in Game Carrier follow a standardized and unified format, represented as a path separated by dots. This path begins with the module name, followed by sections within the module, subsections, and finally the counter name itself, with an optional suffix. For instance, a counter name might look like Module.Section.Subsection.CounterName.Suffix.

The Suffix part of the counter name is significant as it conveys the counting and measurement unit, providing valuable information about how the value is calculated and what it represents.

See all supportes Suffixes below:

Name Description
Total Monolithic counter calculated from the beginning of the server. It will never decrease in value.
Failures Monolithic counter of failures calculated from the beginning of the server. It will never decrease in value.
Current Current usage for a specific resource. It will be increased when a resource is acquired and decreased when the resource is freed.
PerSecond Average per second value calculated. The window size is stored in the configuration at counters.per_second_window. It is typically used in conjunction with a Total counter to indicate the speed of increase.
Duration Time spent at specific points in nanoseconds from the beginning. It will never decrease in value.
Average Average value for a counter. The window size is stored in the configuration at counters.per_second_window. It is usually used together with Current values.

Counter Types

Threads

Module Name Suffixes Description
Threads Counts Total, Current, PerSecond The number of threads in the system.
Threads Active Current The “Active” counter shows the current number of threads that are currently handling requests or tasks in the system.

Examples: Threads.Counts.Current.

Memory

The Memory Usage category provides insights into the allocation of memory within the Game Carrier (GC) and LSW (Libwebsockets) library. It includes the following counters:

Section Module Name Suffixes Description
Memory GC, LWS Allocs Total, Current, Failures, PerSecond The number of allocations.
Memory GC, LWS Bytes Total, Current, PerSecond The number of allocated bytes.
Memory GC, LWS Reallocs Total, Failures, PerSecond The nubmer of reallocs.

Examples: Memory.LWS.Bytes.PerSecond, Memory.GC.Allocs.Current.

Network

The Network Counters category provides valuable insights into the data transmission and reception via the network for both the server and clients.

Section Module Name Suffixes Description
Network Server, Client Connections Total, Current, PerSecond The number of connections.
Network Server, Client Disconnects Total, PerSecond The number of disconnections.
Network Server, Client Bytes.Sent Total, PerSecond Measures the number of sent bytes.
Network Server, Client Bytes.Received Total, PerSecond Measures the number of received bytes.
Network Server, Client Messages.In Total, PerSecond The number of received messages.
Network Server, Client Messages.Out Total, PerSecond, Failures, Failures.PerSecond The number of sent messages.
Network Server, Client Chunks.In Total, PerSecond The number of received message chunks.
Network Server, Client OneChunksMessages.In Total, PerSecond Indicates the number of received messages that conist of a single chunk.

Examples: Server.Client.Bytes.Sent.PerSecond, Network.Server.OneChunksMessages.In.Total.

API

API Counters provide essential data about the interactions between users and the server, including the number of calls from users to the server and the amount of notification calls from the server to users. These counters offer valuable insights into the usage and performance of the API functions and events, enabling effective monitoring and optimization of the system.

API Call Metrics

These counters track the number of calls made by users to the server for various API functions. They provide valuable insights into the frequency and performance of user interactions with the server. The counters include total counts, rates per second, and information on any failures encountered during the calls. Monitoring these metrics helps optimize the API usage and identify potential issues in the user-server communication.

Module.Section API function Suffixes
API.Calls ConnectionClose Total, PerSecond, Failures, Failures.PerSecond
API.Calls ConnectionAddMessage Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupSize Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupCreate Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupDestroy Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupAddMessage Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupAddConnection Total, PerSecond, Failures, Failures.PerSecond
API.Calls GroupRemoveConnection Total, PerSecond, Failures, Failures.PerSecond
API.Calls LogMessage Total, PerSecond
API.Calls GetOpt Total, PerSecond, Failures, Failures.PerSecond
API.Calls ClientCreate Total, PerSecond, Failures, Failures.PerSecond
API.Calls ClientAddMessage Total, PerSecond
API.Calls ClientSetTimer Total, PerSecond
API.Calls ClientDestroy Total, PerSecond
API.Calls ClientService Total, PerSecond

Examples: API.Calls.GroupAddMessage.Failures.PerSecond, API.Calls.ConnectionAddMessage.Total.

Events

Event counters monitor the notification calls from the server to users, giving insights into the event processing and interaction between the server and clients.

Module.Section Event name Suffixes
API.Events OnConnect Total, PerSecond, Duration, Rejects.Total, Rejects.PerSecond
API.Events OnDisconnect Total, PerSecond, Duration
API.Events OnGroupMessage Total, PerSecond, Duration
API.Events OnMessage Total, PerSecond, Duration
API.Events OnMessageSent Total, PerSecond, Duration
API.Events OnClientConnect Total, PerSecond, Duration
API.Events OnClientConnectionError Total, PerSecond, Duration
API.Events OnClientDisconnect Total, PerSecond, Duration
API.Events OnClientMessage Total, PerSecond, Duration
API.Events OnClientMessageSent Total, PerSecond, Duration

Examples: API.Events.OnConnect.Rejects.PerSecond, API.Events.OnClientConnect.Duration.

System

The system monitor counters provide valuable information on the system’s CPU and memory usage, allowing for performance analysis and resource optimization.

Module Section Name Suffixes Description
System CPU Idle.Persent Current, Average Current and average CPU idle percentage (0% to 100%).
System CPU System.Persent Current, Average Current and average CPU kernel load percentage (0% to 100%).
System CPU User.Persent Current, Average Current and average CPU user mode load percentage (0% to 100%).
System Memory Free.Bytes Current, Average Amount of available memory on the system in bytes.
System Memory Free.Persent Current, Average Current and average percentage of available memory (0% to 100%).
System Swap Swap.Bytes Current, Average Amount of available swap memory on the system in bytes.
System Swap Swap.Persent Current, Average Current and average percentage of available swap memory (0% to 100%).

Examples: System.CPU.Idle.Persent.Current, System.Memory.Free.Bytes.Average.