mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add config item for the stat disk device name
This commit is contained in:
parent
7c1dd97513
commit
b334021836
5 changed files with 73 additions and 11 deletions
|
@ -1249,7 +1249,7 @@ int SrsConfig::check_config()
|
|||
SrsConfDirective* conf = get_stats();
|
||||
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
||||
string n = conf->at(i)->name;
|
||||
if (n != "network_device_index") {
|
||||
if (n != "network_device_index" && n != "disk_device_name") {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported stats directive %s, ret=%d", n.c_str(), ret);
|
||||
return ret;
|
||||
|
@ -3194,6 +3194,22 @@ int SrsConfig::get_stats_network_device_index()
|
|||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
SrsConfDirective* SrsConfig::get_stats_disk_device()
|
||||
{
|
||||
SrsConfDirective* conf = get_stats();
|
||||
|
||||
if (!conf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conf = conf->get("disk_device_name");
|
||||
if (!conf || conf->args.size() == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
namespace _srs_internal
|
||||
{
|
||||
SrsConfigBuffer::SrsConfigBuffer()
|
||||
|
|
|
@ -943,6 +943,12 @@ public:
|
|||
* for example, 0 means the eth0 maybe.
|
||||
*/
|
||||
virtual int get_stats_network_device_index();
|
||||
/**
|
||||
* get the disk stat device name list.
|
||||
* the device name configed in args of directive.
|
||||
* @return the disk device name to stat. NULL if not configed.
|
||||
*/
|
||||
virtual SrsConfDirective* get_stats_disk_device();
|
||||
};
|
||||
|
||||
namespace _srs_internal
|
||||
|
|
|
@ -415,15 +415,22 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
|
|||
|
||||
bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
|
||||
{
|
||||
r.ok = false;
|
||||
r.sample_time = srs_get_system_time_ms();
|
||||
|
||||
// if disabled, ignore all devices.
|
||||
SrsConfDirective* conf = _srs_config->get_stats_disk_device();
|
||||
if (conf == NULL) {
|
||||
r.ok = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
FILE* f = fopen("/proc/diskstats", "r");
|
||||
if (f == NULL) {
|
||||
srs_warn("open vmstat failed, ignore");
|
||||
return false;
|
||||
}
|
||||
|
||||
r.ok = false;
|
||||
r.sample_time = srs_get_system_time_ms();
|
||||
|
||||
static char buf[1024];
|
||||
while (fgets(buf, sizeof(buf), f)) {
|
||||
unsigned int major = 0;
|
||||
|
@ -447,9 +454,14 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
|
|||
&rd_sectors, &rd_ticks, &wr_ios, &wr_merges,
|
||||
&wr_sectors, &wr_ticks, &nb_current, &ticks, &aveq);
|
||||
srs_assert(ret == 14);
|
||||
|
||||
// TODO: FIMXE: config it.
|
||||
if (strcmp("sda", name) == 0) {
|
||||
|
||||
for (int i = 0; i < (int)conf->args.size(); i++) {
|
||||
string name_ok = conf->args.at(i);
|
||||
|
||||
if (strcmp(name_ok.c_str(), name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r.rd_ios += rd_ios;
|
||||
r.rd_merges += rd_merges;
|
||||
r.rd_sectors += rd_sectors;
|
||||
|
@ -461,6 +473,8 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
|
|||
r.nb_current += nb_current;
|
||||
r.ticks += ticks;
|
||||
r.aveq += aveq;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,9 +491,18 @@ void srs_update_disk_stat()
|
|||
if (!srs_get_disk_vmstat_stat(r)) {
|
||||
return;
|
||||
}
|
||||
if (!srs_get_disk_diskstats_stat(r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SrsDiskStat& o = _srs_disk_stat;
|
||||
if (o.ok) {
|
||||
if (!o.ok) {
|
||||
_srs_disk_stat = r;
|
||||
return;
|
||||
}
|
||||
|
||||
// vmstat
|
||||
if (true) {
|
||||
int64_t duration_ms = r.sample_time - o.sample_time;
|
||||
|
||||
if (o.pgpgin > 0 && r.pgpgin > o.pgpgin && duration_ms > 0) {
|
||||
|
@ -492,8 +515,6 @@ void srs_update_disk_stat()
|
|||
r.out_KBps = (r.pgpgout - o.pgpgout) * 1000 / duration_ms;
|
||||
}
|
||||
}
|
||||
|
||||
_srs_disk_stat = r;
|
||||
}
|
||||
|
||||
SrsMemInfo::SrsMemInfo()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue