Feature: Statistical Analysis
Relevant source files
The following files were used as context for generating this wiki page:Introduction
The Statistical Analysis feature is a core part of the LLaMa Leaks frontend, responsible for consuming raw server data and transforming it into meaningful, aggregated metrics. Its primary purpose is to provide a high-level overview of the state of exposed Ollama servers by fetching data from a static JSON file, performing various calculations, and displaying the results through several specialized React components.
This system powers the main statistics on the homepage, the dashboard summary, and the version leaderboard. It processes server information to calculate totals, filter by status or time, and group data by specific attributes like the Ollama version. The entire process is client-side, occurring within the user's browser upon page load.
Architecture and Data Flow
The statistical analysis is performed entirely on the client-side. React components fetch server data from a static JSON file, process it, and render the calculated statistics.
High-Level Data Flow
The following diagram illustrates the general flow of data from the source file to the UI components.
This diagram shows that multiple components independently fetch and process the same live_servers.json data to render different statistical views.
Sources: frontend/src/components/ServerStats.tsx:112, frontend/src/components/dashboard/SummaryStats.tsx, frontend/src/components/VersionLeaderboard.tsx:64
Data Source and Structure
The central data source for all statistical calculations is /data/live_servers.json. The structure of the server objects within this file is defined by the ServerData and ServerModel TypeScript interfaces.
Sources: frontend/src/components/ServerStats.tsx:11, frontend/src/components/LocationInfo.tsx:15
ServerData Interface
This interface represents a single discovered Ollama server.
| Field | Type | Description |
|---|---|---|
ip | string | Masked IP address of the server. |
port | number | Port number the server is running on. |
version | string | Ollama version string. |
city | string | City where the server is located. |
country | string | Two-letter country code. |
country_name | string | Full country name. |
region | string | Region or state. |
latitude | string | Latitude coordinate. |
longitude | string | Longitude coordinate. |
local | ServerModel[] | An array of local models available on the server. |
running | ServerModel[] | An array of models currently running. |
first_seen_online | string | ISO timestamp of when the server was first discovered. |
age | string | Human-readable string representing how long the server has been known. |
status | string | The current status of the server (e.g., "live"). |
Sources: frontend/src/components/ServerStats.tsx:11-28, frontend/src/components/LocationInfo.tsx:15-31
ServerModel Interface
This interface represents an AI model on a server.
| Field | Type | Description |
|---|---|---|
name | string | The name of the model (e.g., "llama3:latest"). |
model | string | The base model identifier. |
size | number | The size of the model in bytes. |
Sources: frontend/src/components/ServerStats.tsx:5-9, frontend/src/components/LocationInfo.tsx:9-13
Core Components and Logic
ServerStats Component
This component is responsible for displaying the primary statistics on the main page. It fetches the server data and performs calculations for four key metrics.
Sources: frontend/src/components/ServerStats.tsx
Data Fetching and Calculation Sequence
The useEffect hook in ServerStats.tsx orchestrates the entire process for this component.
This sequence shows the steps from fetching data to updating the component's state and rendering the final statistics.
Sources: frontend/src/components/ServerStats.tsx:109-152
Calculated Metrics
- Total Servers: The total number of server entries in
live_servers.json.
Sources: frontend/src/components/ServerStats.tsx:127 - Live Servers: The count of servers where
status === 'live'.
Sources: frontend/src/components/ServerStats.tsx:130 - New Today: The count of servers where
first_seen_onlineis within the last 24 hours.
Sources: frontend/src/components/ServerStats.tsx:133-140 - Latest Find: The time elapsed since the most recent
first_seen_onlinetimestamp among all servers.
Sources: frontend/src/components/ServerStats.tsx:143-152
VersionLeaderboard Component
This component fetches the same server data but groups it by Ollama version to create a "leaderboard" of the most frequently exposed versions.
Sources: frontend/src/components/VersionLeaderboard.tsx
Grouping and Aggregation Logic
- Fetch Data: Retrieves
live_servers.json. - Parse Version: A
parseVersionutility extracts themajor.minorversion from the full version string (e.g., "0.5.7-0-ga420a45-dirty" becomes "0.5"). - Group by Version: A
Mapis used to group server entries by their parsedmajor.minorversion. - Aggregate Stats: For each version group, the following are calculated:
serverCount: Total servers for that version.totalModels: Sum ofserver.local.length.totalModelSize: Sum of thesizeof all models.liveServers: Count of servers withstatus === 'live'.
- Sort: The resulting groups are sorted by version number in ascending order (older versions first).
- Render: The top 10 groups are displayed in the UI.
Sources: frontend/src/components/VersionLeaderboard.tsx:51-55, frontend/src/components/VersionLeaderboard.tsx:61-105
The structure for each group is defined by the VersionGroup interface.
// frontend/src/components/VersionLeaderboard.tsx:43-49
interface VersionGroup {
version: string;
serverCount: number;
totalModels: number;
totalModelSize: number;
liveServers: number;
}
SummaryStats Component
This component, used in the dashboard, displays a different set of summary statistics. It relies on utility functions for its calculations.
Sources: frontend/src/components/dashboard/SummaryStats.tsx
Calculated Metrics & Utilities
- Unique Models: The total count of
modelExecutions.
Sources: frontend/src/components/dashboard/SummaryStats.tsx:21 - Active Executions: Calculated by
calculateActiveExecutions(modelExecutions).
Sources: frontend/src/components/dashboard/SummaryStats.tsx:16, frontend/src/components/dashboard/SummaryStats.tsx:26 - Total Servers: The total count of
serverData.
Sources: frontend/src/components/dashboard/SummaryStats.tsx:33 - Total Model Size: Calculated by
calculateTotalModelSize(modelExecutions)and formatted usingformatBytesToGB.
Sources: frontend/src/components/dashboard/SummaryStats.tsx:17, frontend/src/components/dashboard/SummaryStats.tsx:40
Utility Functions
A set of utility functions supports the statistical calculations and formatting across the application.
| Function | Location | Purpose |
|---|---|---|
calculateActiveExecutions | stats-calculator.ts | Calculates the number of currently active model executions. |
calculateTotalModelSize | stats-calculator.ts | Sums the size of all models from the execution data. |
formatBytesToGB | formatting.ts | Converts a byte value to gigabytes. |
formatSize | formatting.ts | Formats a byte value into a human-readable string (e.g., KB, MB, GB). |
parseVersion | VersionLeaderboard.tsx | Extracts major.minor version from a full version string. |
formatTimeDuration | ServerStats.tsx | Converts a duration in minutes to a human-readable string (e.g., "5 minutes ago", "2 hours ago"). |
Sources: frontend/src/components/dashboard/SummaryStats.tsx:16-17, frontend/src/components/VersionLeaderboard.tsx:51-55, frontend/src/components/ServerStats.tsx:48-70, frontend/src/components/LocationInfo.tsx:320
Conclusion
The Statistical Analysis feature provides crucial insights into the landscape of exposed Ollama servers. By fetching a single JSON data source and performing various client-side calculations, components like ServerStats, SummaryStats, and VersionLeaderboard can present a multi-faceted view of the data. This includes high-level totals, time-based metrics, and version-based aggregations. The modular design, with distinct components and helper utilities, allows for a clear and maintainable implementation of the application's core analytical capabilities.