github.com/mackerelio/mackerel-agent-plugins@v0.89.3/mackerel-plugin-multicore/lib/multicore_test.go (about) 1 package mpmulticore 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestParseProcStats(t *testing.T) { 9 stab := `cpu 25308302 2 19470191 35582590482 432542 4227 1237778 2053417 1 2 10 cpu0 14786891 2 4570343 2196397805 364717 4072 1209169 526216 1 2 11 cpu1 2031368 0 2810375 2220960345 44625 21 6306 215873 0 0 12 cpu2 1136965 0 2003305 2223401399 16913 34 2490 150020 0 0 13 cpu3 887262 0 1351478 2225031553 1842 34 1984 106188 0 0 14 cpu4 698240 0 1022997 2225790144 688 5 1726 92769 0 0 15 cpu5 633207 0 855102 2226094460 512 7 1473 94372 0 0 16 cpu6 560396 0 772765 2226295609 465 4 1375 86695 0 0 17 cpu7 550697 0 717794 2226396684 314 4 1358 87411 0 0 18 cpu8 516476 0 684738 2226480673 388 4 1358 83375 0 0 19 cpu9 539329 0 690613 2226463131 329 4 1553 85872 0 0 20 cpu10 511186 0 681326 2226525771 323 5 1532 78527 0 0 21 cpu11 523958 0 689858 2226494064 280 6 1644 85290 0 0 22 cpu12 503041 0 696754 2226525183 313 4 1647 81350 0 0 23 cpu13 491136 0 652495 2226560016 268 9 1368 91025 0 0 24 cpu14 463343 0 635362 2226607769 291 3 1351 89751 0 0 25 cpu15 474802 0 634877 2226565867 266 6 1434 98675 0 0 26 intr 10189662361 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 514520202 67947609 233900 0 275291 698846453 217070356 243231 0 279760 640805807 126705906 256807 0 308045 324533905 96494233 262605 0 307572 247100682 86989223 263747 0 329175 231787116 86942679 262067 0 345493 211239797 83799100 257524 0 335479 201229182 80301598 258051 0 337002 192338035 78887243 261288 0 324064 194020233 77276543 264627 0 313805 184420804 77598965 268260 0 306992 188987565 76213860 270250 0 315551 181737220 76019767 268350 0 302552 191458500 76433789 266589 0 299170 188638355 77097745 266078 0 292540 201812993 77509758 263478 0 289432 494 300 67773621 285 2583576515 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 27 ctxt 8676303806 28 btime 1444899785 29 processes 30982630 30 procs_running 2 31 procs_blocked 0 32 softirq 8788848490 0 2700996173 1094252449 1510759801 0 0 1 1761055606 1241616 1720542844` 33 34 stat, _ := parseProcStat(strings.NewReader(stab)) 35 if len(stat) != 16 { 36 t.Errorf("parseProcStat: size should be 16, but '%d'", len(stat)) 37 } 38 if *stat["cpu0"].User != 14786890 { 39 t.Errorf("parseProcStat: user should be 14786890, but '%d'", *stat["cpu0"].User) 40 } 41 if *stat["cpu0"].Nice != 0 { 42 t.Errorf("parseProcStat: nice should be 0, but '%d'", *stat["cpu0"].Nice) 43 } 44 if *stat["cpu0"].System != 4570343 { 45 t.Errorf("parseProcStat: system should be 4570343, but '%d'", *stat["cpu0"].System) 46 } 47 if *stat["cpu0"].Idle != 2196397805 { 48 t.Errorf("parseProcStat: idle should be 2196397805, but '%d'", *stat["cpu0"].Idle) 49 } 50 if *stat["cpu0"].IoWait != 364717 { 51 t.Errorf("parseProcStat: iowait should be 364717, but '%d'", *stat["cpu0"].IoWait) 52 } 53 if *stat["cpu0"].Irq != 4072 { 54 t.Errorf("parseProcStat: irq should be 4072, but '%d'", *stat["cpu0"].Irq) 55 } 56 if *stat["cpu0"].SoftIrq != 1209169 { 57 t.Errorf("parseProcStat: softirq should be 1209169, but '%d'", *stat["cpu0"].SoftIrq) 58 } 59 if *stat["cpu0"].Steal != 526216 { 60 t.Errorf("parseProcStat: steal should be 526216, but '%d'", *stat["cpu0"].Steal) 61 } 62 if *stat["cpu0"].Guest != 1 { 63 t.Errorf("parseProcStat: guest should be 1, but '%d'", *stat["cpu0"].Guest) 64 } 65 if *stat["cpu0"].GuestNice != 2 { 66 t.Errorf("parseProcStat: guest should be 2, but '%d'", *stat["cpu0"].Guest) 67 } 68 if stat["cpu0"].Total != 2217859215 { 69 t.Errorf("parseProcStat: total should be 2217859215, but '%d'", stat["cpu0"].Total) 70 } 71 } 72 73 func TestParseProcStatsOldKernel(t *testing.T) { 74 stab := `cpu0 14786890 0 4570343 2196397805` 75 76 stat, _ := parseProcStat(strings.NewReader(stab)) 77 if len(stat) != 1 { 78 t.Errorf("parseProcStat: size should be 1, but '%d'", len(stat)) 79 } 80 if *stat["cpu0"].User != 14786890 { 81 t.Errorf("parseProcStat: user should be 14786890, but '%d'", *stat["cpu0"].User) 82 } 83 if *stat["cpu0"].Nice != 0 { 84 t.Errorf("parseProcStat: nice should be 0, but '%d'", *stat["cpu0"].Nice) 85 } 86 if *stat["cpu0"].System != 4570343 { 87 t.Errorf("parseProcStat: system should be 4570343, but '%d'", *stat["cpu0"].System) 88 } 89 if *stat["cpu0"].Idle != 2196397805 { 90 t.Errorf("parseProcStat: idle should be 2196397805, but '%d'", *stat["cpu0"].Idle) 91 } 92 if stat["cpu0"].IoWait != nil { 93 t.Errorf("parseProcStat: iowait should be nil, but '%d'", *stat["cpu0"].IoWait) 94 } 95 if stat["cpu0"].Irq != nil { 96 t.Errorf("parseProcStat: irq should be nil, but '%d'", *stat["cpu0"].Irq) 97 } 98 if stat["cpu0"].SoftIrq != nil { 99 t.Errorf("parseProcStat: softirq should be nil, but '%d'", *stat["cpu0"].SoftIrq) 100 } 101 if stat["cpu0"].Steal != nil { 102 t.Errorf("parseProcStat: steal should be nil, but '%d'", *stat["cpu0"].Steal) 103 } 104 if stat["cpu0"].Guest != nil { 105 t.Errorf("parseProcStat: guest should be nil, but '%d'", *stat["cpu0"].Guest) 106 } 107 }