1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

add network bytes to api summaries. 0.9.125

This commit is contained in:
winlin 2014-06-18 16:13:02 +08:00
parent 8822bface3
commit d0b08d0d51
6 changed files with 151 additions and 3 deletions

View file

@ -240,6 +240,7 @@ Supported operating systems and hardware:
* 2013-10-17, Created.<br/>
## History
* v1.0, 2014-06-18, add network bytes to api summaries. 0.9.125
* v1.0, 2014-06-14, fix [#98](https://github.com/winlinvip/simple-rtmp-server/issues/98), workaround for librtmp ping(fmt=1,cid=2 fresh stream). 0.9.124
* v1.0, 2014-05-29, support flv inject and flv http streaming with start=bytes. 0.9.122
* <strong>v1.0, 2014-05-28, [1.0 mainline4(0.9.120)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline4) released. 39200 lines.</strong>

View file

@ -389,6 +389,7 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
SrsCpuInfo* c = srs_get_cpuinfo();
SrsMemInfo* m = srs_get_meminfo();
SrsPlatformInfo* p = srs_get_platform_info();
SrsNetworkDevices* n = srs_get_network_devices();
float self_mem_percent = 0;
if (m->MemTotal > 0) {
@ -398,6 +399,21 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
int64_t now = srs_get_system_time_ms();
double srs_uptime = (now - p->srs_startup_time) / 100 / 10.0;
bool n_ok = false;
int64_t n_sample_time = 0;
int64_t nr_bytes = 0;
int64_t ns_bytes = 0;
int nb_n = srs_get_network_devices_count();
for (int i = 0; i < nb_n; i++) {
SrsNetworkDevices& o = n[i];
if (o.ok) {
n_ok = true;
nr_bytes += o.rbytes;
ns_bytes += o.sbytes;
n_sample_time = o.sample_time;
}
}
ss << JOBJECT_START
<< JFIELD_ERROR(ERROR_SUCCESS) << JFIELD_CONT
<< JFIELD_ORG("data", JOBJECT_START)
@ -407,6 +423,7 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<< JFIELD_ORG("cpuinfo_ok", (c->ok? "true":"false")) << JFIELD_CONT
<< JFIELD_ORG("meminfo_ok", (m->ok? "true":"false")) << JFIELD_CONT
<< JFIELD_ORG("platform_ok", (p->ok? "true":"false")) << JFIELD_CONT
<< JFIELD_ORG("network_ok", (n_ok? "true":"false")) << JFIELD_CONT
<< JFIELD_ORG("now_ms", now) << JFIELD_CONT
<< JFIELD_ORG("self", JOBJECT_START)
<< JFIELD_ORG("pid", getpid()) << JFIELD_CONT
@ -430,7 +447,10 @@ int SrsApiSummaries::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<< JFIELD_ORG("ilde_time", p->os_ilde_time) << JFIELD_CONT
<< JFIELD_ORG("load_1m", p->load_one_minutes) << JFIELD_CONT
<< JFIELD_ORG("load_5m", p->load_five_minutes) << JFIELD_CONT
<< JFIELD_ORG("load_15m", p->load_fifteen_minutes)
<< JFIELD_ORG("load_15m", p->load_fifteen_minutes) << JFIELD_CONT
<< JFIELD_ORG("net_sample_time", n_sample_time) << JFIELD_CONT
<< JFIELD_ORG("net_recv_bytes", nr_bytes) << JFIELD_CONT
<< JFIELD_ORG("net_send_bytes", ns_bytes)
<< JOBJECT_END
<< JOBJECT_END
<< JOBJECT_END;

View file

@ -78,6 +78,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES
#define SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES 90
// update network devices info interval:
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES
#define SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES 90
SrsListener::SrsListener(SrsServer* server, SrsListenerType type)
{
fd = -1;
@ -646,6 +650,7 @@ int SrsServer::do_cycle()
max = srs_max(max, SRS_SYS_CPU_STAT_RESOLUTION_TIMES);
max = srs_max(max, SRS_SYS_MEMINFO_RESOLUTION_TIMES);
max = srs_max(max, SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES);
max = srs_max(max, SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES);
// the deamon thread, update the time cache
while (true) {
@ -656,7 +661,7 @@ int SrsServer::do_cycle()
int __max = max;
__max = srs_max(__max, heartbeat_max_resolution);
for (int i = 1; i < __max + 1; i++) {
for (int i = 0; i < __max; i++) {
st_usleep(SRS_SYS_CYCLE_INTERVAL * 1000);
// for gperf heap checker,
@ -698,6 +703,9 @@ int SrsServer::do_cycle()
if ((i % SRS_SYS_PLATFORM_INFO_RESOLUTION_TIMES) == 0) {
srs_update_platform_info();
}
if ((i % SRS_SYS_NETWORK_DEVICE_RESOLUTION_TIMES) == 0) {
srs_update_network_devices();
}
#ifdef SRS_AUTO_HTTP_PARSER
if (_srs_config->get_heartbeat_enabled()) {
if ((i % heartbeat_max_resolution) == 0) {

View file

@ -444,6 +444,84 @@ void srs_update_platform_info()
}
}
SrsNetworkDevices::SrsNetworkDevices()
{
ok = false;
memset(name, 0, sizeof(name));
sample_time = 0;
rbytes = 0;
rpackets = 0;
rerrs = 0;
rdrop = 0;
rfifo = 0;
rframe = 0;
rcompressed = 0;
rmulticast = 0;
sbytes = 0;
spackets = 0;
serrs = 0;
sdrop = 0;
sfifo = 0;
scolls = 0;
scarrier = 0;
scompressed = 0;
}
#define MAX_NETWORK_DEVICES_COUNT 16
static SrsNetworkDevices _srs_system_network_devices[MAX_NETWORK_DEVICES_COUNT];
static int _nb_srs_system_network_devices = -1;
SrsNetworkDevices* srs_get_network_devices()
{
return _srs_system_network_devices;
}
int srs_get_network_devices_count()
{
return _nb_srs_system_network_devices;
}
void srs_update_network_devices()
{
if (true) {
FILE* f = fopen("/proc/net/dev", "r");
if (f == NULL) {
srs_warn("open proc network devices failed, ignore");
return;
}
// ignore title.
static char buf[1024];
fgets(buf, sizeof(buf), f);
fgets(buf, sizeof(buf), f);
for (int i = 0; i < MAX_NETWORK_DEVICES_COUNT; i++) {
SrsNetworkDevices& r = _srs_system_network_devices[i];
r.ok = false;
r.sample_time = 0;
int ret = fscanf(f, "%6[^:]:%llu %lu %lu %lu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu %lu %lu\n",
r.name, &r.rbytes, &r.rpackets, &r.rerrs, &r.rdrop, &r.rfifo, &r.rframe, &r.rcompressed, &r.rmulticast,
&r.sbytes, &r.spackets, &r.serrs, &r.sdrop, &r.sfifo, &r.scolls, &r.scarrier, &r.scompressed);
if (ret == 17) {
r.ok = true;
_nb_srs_system_network_devices = i + 1;
r.sample_time = srs_get_system_time_ms();
}
if (ret == EOF) {
break;
}
}
fclose(f);
}
}
vector<string> _srs_system_ipv4_ips;
void retrieve_local_ipv4_ips()

View file

@ -349,6 +349,47 @@ extern SrsPlatformInfo* srs_get_platform_info();
// the deamon st-thread will update it.
extern void srs_update_platform_info();
// network device summary
class SrsNetworkDevices
{
public:
// whether the network device is ok.
bool ok;
// 6-chars interfaces name
char name[7];
// the sample time in ms.
int64_t sample_time;
// data for receive.
unsigned long long rbytes;
unsigned long rpackets;
unsigned long rerrs;
unsigned long rdrop;
unsigned long rfifo;
unsigned long rframe;
unsigned long rcompressed;
unsigned long rmulticast;
// data for transmit
unsigned long long sbytes;
unsigned long spackets;
unsigned long serrs;
unsigned long sdrop;
unsigned long sfifo;
unsigned long scolls;
unsigned long scarrier;
unsigned long scompressed;
SrsNetworkDevices();
};
// get network devices info, use cache to avoid performance problem.
extern SrsNetworkDevices* srs_get_network_devices();
extern int srs_get_network_devices_count();
// the deamon st-thread will update it.
extern void srs_update_network_devices();
// get local ip, fill to @param ips
extern void srs_retrieve_local_ipv4_ips();
extern std::vector<std::string>& srs_get_local_ipv4_ips();

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "124"
#define VERSION_REVISION "125"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "SRS"