Merge pull request #475 from kanoi/master API/miner.php add some % fields
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
diff --git a/API-README b/API-README
index 951da26..fe8f638 100644
--- a/API-README
+++ b/API-README
@@ -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:
diff --git a/api.c b/api.c
index 073cc08..11215dd 100644
--- a/api.c
+++ b/api.c
@@ -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
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
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
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
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
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
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
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
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);
diff --git a/miner.h b/miner.h
index 74e7e76..e54db78 100644
--- a/miner.h
+++ b/miner.h
@@ -1387,7 +1387,8 @@ enum api_data_type {
API_FREQ,
API_VOLTS,
API_HS,
- API_DIFF
+ API_DIFF,
+ API_PERCENT
};
struct api_data {
diff --git a/miner.php b/miner.php
index 10e52d1..f0f72d9 100644
--- a/miner.php
+++ b/miner.php
@@ -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)
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);