Added API docs and bug fixes.

This commit is contained in:
XMRig 2018-04-18 09:58:06 +07:00
parent d04a1fcb8f
commit bc67216f7f
8 changed files with 261 additions and 5 deletions

View File

@ -167,7 +167,7 @@ endif()
add_definitions(/D__STDC_FORMAT_MACROS)
add_definitions(/DUNICODE)
add_definitions(/DAPP_DEBUG)
#add_definitions(/DAPP_DEBUG)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

53
doc/API.md Normal file
View File

@ -0,0 +1,53 @@
# HTTP API
If you want use API you need choice a port where is internal HTTP server will listen for incoming connections. API will not available if miner built without `libmicrohttpd`.
Example configuration:
```json
"api": {
"port": 44444,
"access-token": "TOKEN",
"worker-id": null,
"ipv6": false,
"restricted": false
},
```
* **port** Port for incoming connections `http://<miner ip>:<port>`.
* **access-token** [Bearer](https://gist.github.com/xmrig/c75fdd1f8e0f3bac05500be2ab718f8e#file-api-html-L54) access token to secure access to API.
* **worker-id** Optional worker name, if not set will be detected automatically.
* **ipv6** Enable (`true`) or disable (`false`) IPv6 for API.
* **restricted** Use `false` to allow remote configuration.
If you prefer use command line options instead of config file, you can use options: `--api-port`, `--api-access-token`, `--api-worker-id`, `--api-ipv6` and `api-no-restricted`.
## Endpoints
### GET /1/summary
Get miner summary information. [Example](api/1/summary.json).
### GET /1/threads
Get detailed information about miner threads. [Example](api/1/threads.json).
## Restricted endpoints
All API endpoints below allow access to sensitive information and remote configure miner. You should set `access-token` and allow unrestricted access (`"restricted": false`).
### GET /1/config
Get current miner configuration. [Example](api/1/config.json).
### PUT /1/config
Update current miner configuration. Common use case, get current configuration, make changes, and upload it to miner.
Curl example:
```
curl -v --data-binary @config.json -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer SECRET" http://127.0.0.1:44444/1/config
```

63
doc/api/1/config.json Normal file
View File

@ -0,0 +1,63 @@
{
"algo": "cryptonight",
"api": {
"port": 44444,
"access-token": "TOKEN",
"worker-id": null,
"ipv6": false,
"restricted": false
},
"av": 1,
"background": false,
"colors": true,
"cpu-affinity": null,
"cpu-priority": null,
"donate-level": 5,
"huge-pages": true,
"hw-aes": null,
"log-file": null,
"max-cpu-usage": 75,
"pools": [
{
"url": "pool.monero.hashvault.pro:3333",
"user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD",
"pass": "x",
"keepalive": false,
"nicehash": false,
"variant": -1
},
{
"url": "pool.supportxmr.com:3333",
"user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD",
"pass": "x",
"keepalive": false,
"nicehash": false,
"variant": -1
}
],
"print-time": 60,
"retries": 5,
"retry-pause": 5,
"safe": false,
"threads": [
{
"low_power_mode": 1,
"affine_to_cpu": 0
},
{
"low_power_mode": 1,
"affine_to_cpu": 1
},
{
"low_power_mode": 1,
"affine_to_cpu": 2
},
{
"low_power_mode": 1,
"affine_to_cpu": 3
}
],
"user-agent": null,
"syslog": false,
"watch": false
}

73
doc/api/1/summary.json Normal file
View File

@ -0,0 +1,73 @@
{
"id": "92f3104f9a2ee78c",
"worker_id": "Ubuntu-1604-xenial-64-minimal",
"version": "2.6.0-beta3",
"kind": "cpu",
"ua": "XMRig/2.6.0-beta3 (Linux x86_64) libuv/1.8.0 gcc/5.4.0",
"cpu": {
"brand": "Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz",
"aes": true,
"x64": true,
"sockets": 1
},
"algo": "cryptonight",
"hugepages": true,
"donate_level": 5,
"hashrate": {
"total": [
296.24,
296.23,
295.97
],
"highest": 296.5,
"threads": [
[
73.39,
73.39,
73.28
],
[
74.72,
74.72,
74.71
],
[
74.72,
74.72,
74.71
],
[
73.39,
73.39,
73.27
]
]
},
"results": {
"diff_current": 9990,
"shares_good": 30,
"shares_total": 30,
"avg_time": 31,
"hashes_total": 311833,
"best": [
278199,
181923,
103717,
96632,
56154,
51580,
45667,
33159,
29581,
29514
],
"error_log": []
},
"connection": {
"pool": "pool.monero.hashvault.pro:3333",
"uptime": 953,
"ping": 35,
"failures": 0,
"error_log": []
}
}

65
doc/api/1/threads.json Normal file
View File

@ -0,0 +1,65 @@
{
"hugepages": [
4,
4
],
"memory": 8388608,
"threads": [
{
"type": "cpu",
"algo": "cryptonight",
"av": 1,
"low_power_mode": 1,
"affine_to_cpu": 0,
"priority": -1,
"soft_aes": false,
"hashrate": [
73.39,
73.4,
73.28
]
},
{
"type": "cpu",
"algo": "cryptonight",
"av": 1,
"low_power_mode": 1,
"affine_to_cpu": 1,
"priority": -1,
"soft_aes": false,
"hashrate": [
74.72,
74.72,
74.7
]
},
{
"type": "cpu",
"algo": "cryptonight",
"av": 1,
"low_power_mode": 1,
"affine_to_cpu": 2,
"priority": -1,
"soft_aes": false,
"hashrate": [
74.71,
74.72,
74.7
]
},
{
"type": "cpu",
"algo": "cryptonight",
"av": 1,
"low_power_mode": 1,
"affine_to_cpu": 3,
"priority": -1,
"soft_aes": false,
"hashrate": [
73.39,
73.4,
73.28
]
}
]
}

View File

@ -205,12 +205,12 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
case SyslogKey: /* --syslog */
case KeepAliveKey: /* --keepalive */
case NicehashKey: /* --nicehash */
case ApiIPv6Key: /* --api-ipv6 */
return parseBoolean(key, true);
case ColorKey: /* --no-color */
case WatchKey: /* --no-watch */
case ApiRestrictedKey: /* --api-no-restricted */
case ApiIPv6Key: /* --api-no-ipv6 */
return parseBoolean(key, false);
case DonateLevelKey: /* --donate-level */

View File

@ -85,6 +85,8 @@ Options:\n\
--api-port=N port for the miner API\n\
--api-access-token=T access token for API\n\
--api-worker-id=ID custom worker-id for API\n\
--api-ipv6 enable IPv6 support for API\n\
--api-no-restricted enable full remote access (only if API token set)\n\
-h, --help display this help and exit\n\
-V, --version output version information and exit\n\
";
@ -98,7 +100,7 @@ static struct option const options[] = {
{ "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
{ "api-no-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
{ "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
{ "av", 1, nullptr, xmrig::IConfig::AVKey },
{ "background", 0, nullptr, xmrig::IConfig::BackgroundKey },

View File

@ -193,8 +193,8 @@ void Workers::submit(const JobResult &result)
void Workers::threadsSummary(rapidjson::Document &doc)
{
uv_mutex_lock(&m_mutex);
const size_t pages[2] = { m_status.hugePages, m_status.pages };
const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo);
const uint64_t pages[2] = { m_status.hugePages, m_status.pages };
const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo);
uv_mutex_unlock(&m_mutex);
auto &allocator = doc.GetAllocator();