当前位置: 技术问答>linux和unix
centos 5.4 怎么查看每个进程的用户的IO
来源: 互联网 发布时间:2016-10-13
本文导语: 公司用的nfs,虽然员工有分服务器工作,但数据都来自文件服务器。 今天大家突然说很卡,ls一下都慢,打开文件也慢。我看了看,网络也挺正常,到是文件服务器的IO有些磁盘达到100%,我想可能问题出在这,可大...
公司用的nfs,虽然员工有分服务器工作,但数据都来自文件服务器。
今天大家突然说很卡,ls一下都慢,打开文件也慢。我看了看,网络也挺正常,到是文件服务器的IO有些磁盘达到100%,我想可能问题出在这,可大家都跟我说他们的操作跟平时一样,没有很频繁读写磁盘。
请问Centos 5.4下,怎么查看每个进程的用户的IO?
今天大家突然说很卡,ls一下都慢,打开文件也慢。我看了看,网络也挺正常,到是文件服务器的IO有些磁盘达到100%,我想可能问题出在这,可大家都跟我说他们的操作跟平时一样,没有很频繁读写磁盘。
请问Centos 5.4下,怎么查看每个进程的用户的IO?
|
只知道有个vmstat的能看IO,
还有iopp
还有iopp
|
lsof|grep 你要监视的程序
据说iotop这个工具很方便 可是需要内核2.6.20以上 CentOS还是2.6.18的内核
据说iotop这个工具很方便 可是需要内核2.6.20以上 CentOS还是2.6.18的内核
|
我用CentOS5.5 刚编译了下iopp.c 是可以用的哦 是不是你下载代码有问题 我贴下我用的
/*
* Copyright (C) 2008 Mark Wong
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PROC "/proc"
#define GET_VALUE(v)
p = strchr(p, ':');
++p;
++p;
q = strchr(p, 'n');
length = q - p;
if (length >= BUFFERLEN)
{
printf("ERROR - value is larger than the buffer: %dn", __LINE__);
exit(1);
}
strncpy(value, p, length);
value[length] = '';
v = atoll(value);
#define BTOKB(b) b >> 10
#define BTOMB(b) b >> 20
#define BUFFERLEN 255
#define COMMANDLEN 1024
#define VALUELEN 63
#define NUM_STRINGS 8
struct io_node
{
int pid;
long long rchar;
long long wchar;
long long syscr;
long long syscw;
long long read_bytes;
long long write_bytes;
long long cancelled_write_bytes;
char command[COMMANDLEN + 1];
struct io_node *next;
};
struct io_node *head = NULL;
int command_flag = 0;
int idle_flag = 0;
int mb_flag = 0;
int kb_flag = 0;
int hr_flag = 0;
/* Prototypes */
char *format_b(long long);
struct io_node *get_ion(int);
struct io_node *new_ion(char *);
void upsert_data(struct io_node *);
char *
format_b(long long amt)
{
static char retarray[NUM_STRINGS][16];
static int index = 0;
register char *ret;
register char tag = 'B';
ret = retarray[index];
index = (index + 1) % NUM_STRINGS;
if (amt >= 10000) {
amt = (amt + 512) / 1024;
tag = 'K';
if (amt >= 10000) {
amt = (amt + 512) / 1024;
tag = 'B';
if (amt >= 10000) {
amt = (amt + 512) / 1024;
tag = 'G';
}
}
}
snprintf(ret, sizeof(retarray[index]) - 1, "%lld%c", amt, tag);
return (ret);
}
int
get_cmdline(struct io_node *ion)
{
int fd;
int length;
char filename[BUFFERLEN + 1];
char buffer[COMMANDLEN + 1];
char *p;
char *q;
length = snprintf(filename, BUFFERLEN, "%s/%d/cmdline", PROC, ion->pid);
if (length == BUFFERLEN)
printf("WARNING - filename length may be too big for buffer: %dn",
__LINE__);
fd = open(filename, O_RDONLY);
if (fd == -1)
return 1;
length = read(fd, buffer, sizeof(buffer) - 1);
close(fd);
buffer[length] = '';
if (length == 0)
return 2;
if (command_flag == 0)
{
/*
* The command is near the beginning; we don't need to be able to
* the entire stat file.
*/
p = strchr(buffer, '(');
++p;
q = strchr(p, ')');
length = q - p;
}
else
p = buffer;
length = length command, p, length);
ion->command[length] = '';
return 0;
}
struct io_node *
get_ion(int pid)
{
struct io_node *c = head;
while (c != NULL)
{
if (c->pid == pid)
break;
c = c->next;
}
return c;
}
int
get_tcomm(struct io_node *ion)
{
int fd;
int length;
char filename[BUFFERLEN + 1];
char buffer[BUFFERLEN + 1];
char *p;
char *q;
length = snprintf(filename, BUFFERLEN, "%s/%d/stat", PROC, ion->pid);
if (length == BUFFERLEN)
printf("WARNING - filename length may be too big for buffer: %dn",
__LINE__);
fd = open(filename, O_RDONLY);
if (fd == -1)
return 1;
length = read(fd, buffer, sizeof(buffer) - 1);
close(fd);
/*
* The command is near the beginning; we don't need to be able to
* the entire stat file.
*/
p = strchr(buffer, '(');
++p;
q = strchr(p, ')');
length = q - p;
length = length command, p, length);
ion->command[length] = '';
return 0;
}
struct io_node *
insert_ion(struct io_node *ion)
{
struct io_node *c;
struct io_node *p;
/* Check the head of the list as a special case. */
if (ion->pid pid)
{
ion->next = head;
head = ion;
return head;
}
c = head->next;
p = head;
while (c != NULL)
{
if (ion->pid pid)
{
ion->next = c;
p->next = ion;
return head;
}
p = c;
c = c->next;
}
/* Append to the end of the list. */
if (c == NULL)
p->next = ion;
return head;
}
|
貌似iopp和主席说得iotop比较好
|
vmstat好像可以吧