Skip to content

Examples

This page provides detailed examples of how to use the xmrig API. Each example demonstrates a specific functionality.

Examples List

  1. Add Miners
  2. List All Miners
  3. Get Individual Miners
  4. Update Config
  5. Update Individual Miners Endpoints
  6. Update All Endpoints for All Miners
  7. Start/Stop All Miners
  8. Pause/Resume All Miners
  9. Remove Miner
  10. Access Properties
  11. Full Example

Add Miners

This example demonstrates how to add XMRig miners to the XMRigManager. It shows how to configure logging and add miners to the manager.

add_miners.py
1
2
3
4
5
6
7
8
9
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)

List All Miners

This example demonstrates how to list all XMRig miners managed by the XMRigManager. It shows how to configure logging, add miners to the manager, and list all miners.

list_all_miners.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
log.info("Retrieving individual miners...")
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info(f"Retrieved miner: {miner_a._miner_name}")
log.info(f"Retrieved miner: {miner_b._miner_name}")

Get Individual Miners

This example demonstrates how to retrieve individual XMRig miners from the XMRigManager. It shows how to configure logging, add miners to the manager, and retrieve individual miners.

get_individual_miners.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
log.info("Retrieving individual miners...")
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info(f"Retrieved miner: {miner_a._miner_name}")
log.info(f"Retrieved miner: {miner_b._miner_name}")

Update Config

This example demonstrates how to update the configuration of an XMRig miner using the XMRigManager. It shows how to configure logging, add miners to the manager, retrieve the current config, modify it, and post the updated config.

update_config.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info("Retrieving individual miner")
miner_a = manager.get_miner("MinerB")
miner_a.get_endpoint("config")
config = miner_a.data.config
log.info("Updating miner configuration")
config["api"]["worker-id"] = "NEW_WORKER_ID"
miner_a.post_config(config)

Update Individual Miners Endpoints

This example demonstrates how to update the endpoints for individual XMRig miners using the XMRigManager. It shows how to configure logging, add miners to the manager, and update the summary, backends, and config endpoints for each miner.

update_individual_miners_endpoints.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
log.info("Retrieving individual miners...")
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info(f"Updating endpoints for {name_a}")
miner_a.get_endpoint("summary")
miner_a.get_endpoint("backends")
miner_a.get_endpoint("config")
log.info(f"Updating endpoints for {name_b}")
miner_b.get_endpoint("summary")
miner_b.get_endpoint("backends")
miner_b.get_endpoint("config")

Update All Endpoints for All Miners

This example demonstrates how to update all endpoints for all XMRig miners using the XMRigManager. It shows how to configure logging, add miners to the manager, and update all endpoints for all miners in the manager.

update_all_miners.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info("Updating all endpoints for all miners")
manager.update_miners()
log.info("Updating a single endpoint for all miners")
manager.update_miners("summary")

Start Or Stop All Miners

This example demonstrates how to start and stop all XMRig miners using the XMRigManager. It shows how to configure logging, add miners to the manager, and perform start/stop actions on all miners.

start_stop_all_miners.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info("Stopping all miners")
manager.perform_action_on_all("stop")
log.info("Starting all miners")
manager.perform_action_on_all("start")

Pause Or Resume All Miners

This example demonstrates how to pause and resume all XMRig miners using the XMRigManager. It shows how to configure logging, add miners to the manager, and perform pause/resume actions on all miners.

pause_resume_all_miners.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info("Pausing all miners")
manager.perform_action_on_all("pause")
log.info("Resuming all miners")
manager.perform_action_on_all("resume")

Remove Miner

This example demonstrates how to remove an XMRig miner from the XMRigManager. It shows how to configure logging, add miners to the manager, list all miners, remove a miner, and list all miners again.

remove_miner.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info("Listing all miners")
log.info(manager.list_miners())
log.info("Removing MinerB")
manager.remove_miner("MinerB")
log.info("Listing all miners after removal")
log.info(manager.list_miners())

Access Properties

This example demonstrates how to use the XMRigManager to manage multiple XMRig miners. It shows how to configure logging, add miners to the manager, and retrieve data from individual miners. The example logs various properties of the miners, such as summary, backends, config, hashrates, and job counters.

access_properties.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
miner_a = manager.get_miner(name_a)
log.info(f"{miner_a._miner_name} Full JSON Data Examples")
log.info(f"Summary Endpoint: {miner_a.data.summary}")
log.info(f"Backends Endpoint: {miner_a.data.backends}")
log.info(f"Config Endpoint: {miner_a.data.config}")
miner_b = manager.get_miner(name_b)
log.info(f"{miner_b._miner_name} Individual Data Examples")
log.info(f"Hashrates: {miner_b.data.sum_hashrates}")
log.info(f"Accepted Jobs: {miner_b.data.sum_pool_accepted_jobs}")
log.info(f"Rejected Jobs: {miner_b.data.sum_pool_rejected_jobs}")

Full Example

This full example demonstrates various functionalities of the XMRigManager. It shows how to configure logging, add and remove miners, list all miners, update endpoints, pause/resume miners, start/stop miners, and update the miner's config.

full_example.py
from env import log, name_a, ip_a, port_a, access_token_a, tls_enabled_a, name_b, ip_b, port_b, access_token_b, tls_enabled_b
from xmrig import XMRigManager

manager = XMRigManager()
log.info("Adding miners to the manager...")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
manager.add_miner(name_b, ip_b, port_b, access_token_b, tls_enabled_b)
log.info("Retrieving individual miners...")
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info(f"Retrieved miner: {miner_a._miner_name}")
log.info(f"Retrieved miner: {miner_b._miner_name}")

# List all miners
log.info("Listing all miners...")
log.info(manager.list_miners())
# Remove miners
log.info(f"Removing miner: {name_a}")
manager.remove_miner(name_a)
# List all miners
log.info("Listing all miners...")
log.info(manager.list_miners())
# Add back for rest of example code
log.info(f"Adding miner back: {name_a}")
manager.add_miner(name_a, ip_a, port_a, access_token_a, tls_enabled_a)
# Get individual miners
log.info("Retrieving individual miners...")
miner_a = manager.get_miner(name_a)
miner_b = manager.get_miner(name_b)
log.info(f"Retrieved miner: {miner_a._miner_name}")
log.info(f"Retrieved miner: {miner_b._miner_name}")
# Update an individual miner's endpoints
log.info(f"Updating endpoints for miner: {miner_a._miner_name}")
miner_a.get_endpoint("summary")
miner_a.get_endpoint("backends")
miner_a.get_endpoint("config")
log.info(f"Updating endpoints for miner: {miner_b._miner_name}")
miner_b.get_endpoint("summary")
miner_b.get_endpoint("backends")
miner_b.get_endpoint("config")
# Update all endpoints for all miners
log.info("Updating all endpoints for all miners...")
manager.update_miners()
# Pause all miners
log.info("Pausing all miners...")
manager.perform_action_on_all("pause")
log.info("Resuming all miners...")
manager.perform_action_on_all("resume")
# Start/stop a specific miner
log.info(f"Stopping miner: {miner_a._miner_name}")
miner_a.perform_action("stop")
log.info(f"Starting miner: {miner_a._miner_name}")
miner_a.perform_action("start")
# Pause/Resume a specific miner
log.info(f"Pausing miner: {miner_b._miner_name}")
miner_b.perform_action("pause")
log.info(f"Resuming miner: {miner_b._miner_name}")
miner_b.perform_action("resume")
# Edit and update the miners `config.json` via the HTTP API.
log.info(f"Editing config for miner: {miner_a._miner_name}")
miner_a.get_endpoint("config")
config = miner_a.data.config
config["api"]["worker-id"] = "NEW_WORKER_ID"
miner_a.post_config(config)
# Summary and Backends API data is available as properties in either full or individual format.
log.info(f"Summary data for miner: {miner_b._miner_name}")
log.info(miner_b.data.summary)
log.info(f"Hashrates for miner: {miner_b._miner_name}")
log.info(miner_b.data.sum_hashrates)
log.info(f"Accepted jobs for miner: {miner_b._miner_name}")
log.info(miner_b.data.sum_pool_accepted_jobs)
log.info(f"Rejected jobs for miner: {miner_b._miner_name}")
log.info(miner_b.data.sum_pool_rejected_jobs)
log.info(f"Current difficulty for miner: {miner_b._miner_name}")
log.info(miner_b.data.sum_current_difficulty)