Browse Source

API/miner.php add some % fields

nfactor-troky
Kano 11 years ago
parent
commit
6b62c402fa
  1. 10
      API-README
  2. 47
      api.c
  3. 3
      miner.h
  4. 21
      miner.php

10
API-README

@ -461,6 +461,16 @@ miner.php - an example web page to access the API @@ -461,6 +461,16 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
API V1.28 (cgminer v3.3.4)
Modified API commands:
'devs', 'pga', 'asc', 'gpu' - add 'Device Hardware%' and 'Device Rejected%'
'pools' - add 'Pool Rejected%' and 'Pool Stale%'
'summary' - add 'Device Hardware%', 'Device Rejected%', 'Pool Rejected%',
'Pool Stale%'
----------
API V1.27 (cgminer v3.3.2)
Added API commands:

47
api.c

@ -134,7 +134,7 @@ static const char SEPARATOR = '|'; @@ -134,7 +134,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
static const char *APIVERSION = "1.27";
static const char *APIVERSION = "1.28";
static const char *DEAD = "Dead";
#if defined(HAVE_OPENCL) || defined(HAVE_AN_FPGA) || defined(HAVE_AN_ASIC)
static const char *SICK = "Sick";
@ -938,6 +938,7 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu @@ -938,6 +938,7 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
case API_FREQ:
case API_HS:
case API_DIFF:
case API_PERCENT:
api_data->data = (void *)malloc(sizeof(double));
*((double *)(api_data->data)) = *((double *)data);
break;
@ -1069,6 +1070,11 @@ struct api_data *api_add_diff(struct api_data *root, char *name, double *data, b @@ -1069,6 +1070,11 @@ struct api_data *api_add_diff(struct api_data *root, char *name, double *data, b
return api_add_data_full(root, name, API_DIFF, (void *)data, copy_data);
}
struct api_data *api_add_percent(struct api_data *root, char *name, double *data, bool copy_data)
{
return api_add_data_full(root, name, API_PERCENT, (void *)data, copy_data);
}
static struct api_data *print_data(struct api_data *root, char *buf, bool isjson, bool precom)
{
struct api_data *tmp;
@ -1161,6 +1167,9 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson @@ -1161,6 +1167,9 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
case API_TEMP:
sprintf(buf, "%.2f", *((float *)(root->data)));
break;
case API_PERCENT:
sprintf(buf, "%.4f", *((double *)(root->data)) * 100.0);
break;
default:
applog(LOG_ERR, "API: unknown2 data type %d ignored", root->type);
sprintf(buf, "%s%s%s", quote, UNKNOWN, quote);
@ -1618,6 +1627,12 @@ static void gpustatus(struct io_data *io_data, int gpu, bool isjson, bool precom @@ -1618,6 +1627,12 @@ static void gpustatus(struct io_data *io_data, int gpu, bool isjson, bool precom
root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
root = api_add_diff(root, "Last Share Difficulty", &(cgpu->last_share_diff), false);
root = api_add_time(root, "Last Valid Work", &(cgpu->last_device_valid_work), false);
double hwp = (cgpu->hw_errors + cgpu->diff1) ?
(double)(cgpu->hw_errors) / (double)(cgpu->hw_errors + cgpu->diff1) : 0;
root = api_add_percent(root, "Device Hardware%", &hwp, false);
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
@ -1691,6 +1706,12 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom @@ -1691,6 +1706,12 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
root = api_add_bool(root, "No Device", &(cgpu->usbinfo.nodev), false);
#endif
root = api_add_time(root, "Last Valid Work", &(cgpu->last_device_valid_work), false);
double hwp = (cgpu->hw_errors + cgpu->diff1) ?
(double)(cgpu->hw_errors) / (double)(cgpu->hw_errors + cgpu->diff1) : 0;
root = api_add_percent(root, "Device Hardware%", &hwp, false);
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
@ -1775,6 +1796,12 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom @@ -1775,6 +1796,12 @@ static void pgastatus(struct io_data *io_data, int pga, bool isjson, bool precom
root = api_add_bool(root, "No Device", &(cgpu->usbinfo.nodev), false);
#endif
root = api_add_time(root, "Last Valid Work", &(cgpu->last_device_valid_work), false);
double hwp = (cgpu->hw_errors + cgpu->diff1) ?
(double)(cgpu->hw_errors) / (double)(cgpu->hw_errors + cgpu->diff1) : 0;
root = api_add_percent(root, "Device Hardware%", &hwp, false);
double rejp = cgpu->diff1 ?
(double)(cgpu->diff_rejected) / (double)(cgpu->diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
root = print_data(root, buf, isjson, precom);
io_add(io_data, buf);
@ -2145,6 +2172,12 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m @@ -2145,6 +2172,12 @@ static void poolstatus(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __m
root = api_add_const(root, "Stratum URL", BLANK, false);
root = api_add_bool(root, "Has GBT", &(pool->has_gbt), false);
root = api_add_uint64(root, "Best Share", &(pool->best_diff), true);
double rejp = (pool->diff_accepted + pool->diff_rejected + pool->diff_stale) ?
(double)(pool->diff_rejected) / (double)(pool->diff_accepted + pool->diff_rejected + pool->diff_stale) : 0;
root = api_add_percent(root, "Pool Rejected%", &rejp, false);
double stalep = (pool->diff_accepted + pool->diff_rejected + pool->diff_stale) ?
(double)(pool->diff_stale) / (double)(pool->diff_accepted + pool->diff_rejected + pool->diff_stale) : 0;
root = api_add_percent(root, "Pool Stale%", &stalep, false);
root = print_data(root, buf, isjson, isjson && (i > 0));
io_add(io_data, buf);
@ -2191,6 +2224,18 @@ static void summary(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __mayb @@ -2191,6 +2224,18 @@ static void summary(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __mayb
root = api_add_diff(root, "Difficulty Rejected", &(total_diff_rejected), true);
root = api_add_diff(root, "Difficulty Stale", &(total_diff_stale), true);
root = api_add_uint64(root, "Best Share", &(best_diff), true);
double hwp = (hw_errors + total_diff1) ?
(double)(hw_errors) / (double)(hw_errors + total_diff1) : 0;
root = api_add_percent(root, "Device Hardware%", &hwp, false);
double rejp = total_diff1 ?
(double)(total_diff_rejected) / (double)(total_diff1) : 0;
root = api_add_percent(root, "Device Rejected%", &rejp, false);
double prejp = (total_diff_accepted + total_diff_rejected + total_diff_stale) ?
(double)(total_diff_rejected) / (double)(total_diff_accepted + total_diff_rejected + total_diff_stale) : 0;
root = api_add_percent(root, "Pool Rejected%", &prejp, false);
double stalep = (total_diff_accepted + total_diff_rejected + total_diff_stale) ?
(double)(total_diff_stale) / (double)(total_diff_accepted + total_diff_rejected + total_diff_stale) : 0;
root = api_add_percent(root, "Pool Stale%", &stalep, false);
mutex_unlock(&hash_lock);

3
miner.h

@ -1387,7 +1387,8 @@ enum api_data_type { @@ -1387,7 +1387,8 @@ enum api_data_type {
API_FREQ,
API_VOLTS,
API_HS,
API_DIFF
API_DIFF,
API_PERCENT
};
struct api_data {

21
miner.php

@ -764,7 +764,11 @@ function fmt($section, $name, $value, $when, $alldata) @@ -764,7 +764,11 @@ function fmt($section, $name, $value, $when, $alldata)
case 'DEVS.Temperature':
$ret = $value.'°C';
if (!isset($alldata['GPU']))
{
if ($value == 0)
$ret = ' ';
break;
}
case 'GPU.GPU Clock':
case 'DEVS.GPU Clock':
case 'GPU.Memory Clock':
@ -962,6 +966,23 @@ function fmt($section, $name, $value, $when, $alldata) @@ -962,6 +966,23 @@ function fmt($section, $name, $value, $when, $alldata)
if ($value != '')
$ret = number_format((float)$value, 2);
break;
case 'DEVS.Device Hardware%':
case 'DEVS.Device Rejected%':
case 'ASC.Device Hardware%':
case 'ASC.Device Rejected%':
case 'PGA.Device Hardware%':
case 'PGA.Device Rejected%':
case 'GPU.Device Hardware%':
case 'GPU.Device Rejected%':
case 'POOL.Pool Rejected%':
case 'POOL.Pool Stale%':
case 'SUMMARY.Device Hardware%':
case 'SUMMARY.Device Rejected%':
case 'SUMMARY.Pool Rejected%':
case 'SUMMARY.Pool Stale%':
if ($value != '')
$ret = number_format((float)$value, 2) . '%';
break;
case 'SUMMARY.Best Share':
if ($value != '')
$ret = number_format((float)$value);

Loading…
Cancel
Save