Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
API/miner.php add some % fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kanoi committed Aug 14, 2013
1 parent e95ad04 commit 6b62c40
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
10 changes: 10 additions & 0 deletions API-README
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 46 additions & 1 deletion api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,8 @@ enum api_data_type {
API_FREQ,
API_VOLTS,
API_HS,
API_DIFF
API_DIFF,
API_PERCENT
};

struct api_data {
Expand Down
21 changes: 21 additions & 0 deletions miner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6b62c40

Please sign in to comment.