示例#1
0
func TestOpenFiles(t *testing.T) {
	expect := expect.New(t)
	f, e := os.Open("fixtures/lsof.txt")
	expect(e).ToBeNil()
	defer f.Close()

	files := &OpenFiles{}
	expect(files.Load(f)).ToBeNil()
	expect(files.Files).ToNotBeNil()
	expect(files.Files).ToHaveLength(265)

	selectFile := func(pid string) *File {
		for _, f := range files.Files {
			if f.ProcessId == pid {
				return f
			}
		}
		return nil
	}

	file := selectFile("1")
	expect(file).ToNotBeNil()
	expect(file.FileInodeNumber).ToEqual("6964")
	expect(file.FileName).ToEqual("/dev/ptmx")
}
示例#2
0
func TestNumeric(t *testing.T) {
	expect := expect.New(t)
	expect(numeric("1234")).ToEqual(true)
	expect(numeric("1")).ToEqual(true)
	expect(numeric("")).ToEqual(false)
	expect(numeric("12a")).ToEqual(false)
}
示例#3
0
func TestEc2Metadata(t *testing.T) {
	expect := expect.New(t)
	f, err := os.Open("fixtures/ec2metadata.txt")
	expect(err).ToBeNil()
	defer f.Close()

	em := &Ec2Metadata{}
	err = em.Load(f)
	expect(err).ToBeNil()
	expect(em.AvailabilityZone).ToEqual("eu-west-1a")
	expect(em.InstanceId).ToEqual("i-72d0fa30")
	expect(em.AmiId).ToEqual("ami-905e81e7")
}
示例#4
0
func TestUrlForAction(t *testing.T) {
	expect := expect.New(t)
	pr := &dummyAction{DurationSeconds: 3601}
	expect(pr).ToNotBeNil()

	params, err := ParamsForAction(pr)
	expect(err).ToBeNil()
	expect(params).ToNotBeNil()
	expect(params["DurationSeconds"]).ToContain("3601")
	expect(params["Version"]).ToContain("2011-06-15")
	expect(params["Action"]).ToContain("GetSessionToken")

}
示例#5
0
func TestLoadAVG(t *testing.T) {
	expect := expect.New(t)
	f, e := os.Open("fixtures/loadavg.txt")
	expect(e).ToBeNil()
	defer f.Close()
	l := &LoadAvg{}
	expect(l.Load(f)).ToBeNil()
	expect(l.Min1).ToEqual(0.00)
	expect(l.Min5).ToEqual(0.01)
	expect(l.Min15).ToEqual(0.05)
	expect(l.RunnableEntities).ToEqual(1)
	expect(l.ExistingEntities).ToEqual(258)
	expect(l.MostRecentPid).ToEqual(8518)
}
示例#6
0
func TestProcCmdline(t *testing.T) {
	expect := expect.New(t)
	f, err := os.Open("fixtures/proc_cmdline.txt")
	expect(err).ToBeNil()
	defer f.Close()

	cmd := &ProcCmdline{}
	err = cmd.Load(f)
	expect(err).ToBeNil()
	expect(cmd.Cmd).ToEqual("/opt/postgresql-9.3.5/bin/postgres")
	expect(cmd.Args).ToHaveLength(2)
	expect(cmd.Args[0]).ToEqual("-D")
	expect(cmd.Args[1]).ToEqual("/data/postgres")
}
示例#7
0
文件: df_test.go 项目: neutony/metrix
func TestParseDf(t *testing.T) {
	expect := expect.New(t)
	f, e := os.Open("fixtures/df.txt")
	expect(e).ToBeNil()
	defer f.Close()

	disks, e := ParseDf(f)
	expect(e).ToBeNil()
	expect(disks).ToHaveLength(7)
	expect(disks[0].Filesystem).ToEqual("/dev/xvda1")
	expect(disks[0].Blocks).ToEqual(51466360)
	expect(disks[0].Used).ToEqual(32923572)
	expect(disks[0].Available).ToEqual(16346296)
	expect(disks[0].Use).ToEqual(67)
	expect(disks[0].MountedOn).ToEqual("/")
}
示例#8
0
func TestStat(t *testing.T) {
	expect := expect.New(t)
	f, e := os.Open("fixtures/stat.txt")
	expect(e).ToBeNil()
	defer f.Close()

	s := &Stat{}
	e = s.Load(f)
	expect(e).ToBeNil()
	expect(s.Cpu).ToNotBeNil()
	expect(s.Cpu.User).ToEqual(13586)
	expect(s.Cpu.System).ToEqual(32308)
	expect(s.Cpu.IOWait).ToEqual(762)
	expect(len(s.Cpus)).ToEqual(4)
	expect(s.Cpus[0].User).ToEqual(4488)
	expect(s.Cpus[0].System).ToEqual(23009)
	expect(s.BootTime).ToEqual(1412216124)
	expect(s.ContextSwitches).ToEqual(4087538)
	expect(s.Processes).ToEqual(20491)
}
示例#9
0
func TestParseProcStat(t *testing.T) {
	expect := expect.New(t)
	f, e := os.Open("fixtures/proc_stat.txt")
	expect(e).ToBeNil()
	defer f.Close()
	p := &ProcStat{}
	expect(p).ToNotBeNil()
	expect(p.Load(f)).ToBeNil()
	expect(p.Pid).ToEqual(1153)
	expect(p.Comm).ToEqual("(cron)")
	expect(p.State).ToEqual("S")
	expect(p.Ppid).ToEqual(1)
	expect(p.Pgrp).ToEqual(1153)
	expect(p.Utime).ToEqual(17)
	expect(p.Stime).ToEqual(115)
	expect(p.Cutime).ToEqual(3549)
	expect(p.Cstime).ToEqual(2293)
	expect(p.NumThreads).ToEqual(1)
	expect(p.RSS).ToEqual(262)
	expect(p.VSize).ToEqual(24223744)
	expect(p.RSSlim).ToEqual(0)
	expect(p.StatStartTime).ToEqual(1301)
}