|
23 | 23 | import org.testng.annotations.Test; |
24 | 24 |
|
25 | 25 | import java.io.ByteArrayInputStream; |
26 | | -import java.io.IOException; |
27 | | -import java.io.InputStream; |
28 | 26 | import java.util.ArrayList; |
29 | 27 | import java.util.Arrays; |
30 | 28 | import java.util.List; |
@@ -127,4 +125,76 @@ public void testParse() throws Exception { |
127 | 125 |
|
128 | 126 | assertEquals(metrics, expected); |
129 | 127 | } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void testParseNewFormat() throws Exception { |
| 131 | + final String statusText = "localhost\n" |
| 132 | + + "ServerVersion: Apache/2.4.16 (Ubuntu)\n" |
| 133 | + + "ServerMPM: worker\n" |
| 134 | + + "Server Built: 2015-09-08T00:00:00\n" |
| 135 | + + "CurrentTime: Tuesday, 08-Sep-2015 21:07:08 UTC\n" |
| 136 | + + "RestartTime: Tuesday, 08-Sep-2015 19:51:38 UTC\n" |
| 137 | + + "ParentServerConfigGeneration: 1\n" |
| 138 | + + "ParentServerMPMGeneration: 0\n" |
| 139 | + + "ServerUptimeSeconds: \n" |
| 140 | + + "ServerUptime: 1 hour 15 minutes 29 seconds\n" |
| 141 | + + "Load1: 0.04\n" |
| 142 | + + "Load5: 0.03\n" |
| 143 | + + "Load15: 0.05\n" |
| 144 | + + "Total Accesses: " + TOTAL_ACCESSES + "\n" |
| 145 | + + "Total kBytes: " + KBYTES + "\n" |
| 146 | + + "CPUUser: .36\n" |
| 147 | + + "CPUSystem: .26\n" |
| 148 | + + "CPUChildrenUser: 0\n" |
| 149 | + + "CPUChildrenSystem: 0\n" |
| 150 | + + "CPULoad: .044688\n" |
| 151 | + + "Uptime: " + UPTIME + "\n" |
| 152 | + + "ReqPerSec: " + RPS + "\n" |
| 153 | + + "BytesPerSec: " + BPS + "\n" |
| 154 | + + "BytesPerReq: " + BPR + "\n" |
| 155 | + + "BusyWorkers: " + BUSY_WORKERS + "\n" |
| 156 | + + "IdleWorkers: " + IDLE_WORKERS + "\n" |
| 157 | + + "Scoreboard: __________________K___W_K_____K______________K____" |
| 158 | + + repeat('.', OPEN_SLOTS) |
| 159 | + + "\n"; |
| 160 | + ApacheStatusPoller.StatusFetcher fetcher = () -> new ByteArrayInputStream(statusText.getBytes("UTF-8")); |
| 161 | + |
| 162 | + ApacheStatusPoller poller = new ApacheStatusPoller(fetcher); |
| 163 | + |
| 164 | + List<Metric> metrics = poller.pollImpl(TIMESTAMP); |
| 165 | + |
| 166 | + Metric accesses = counter("Total_Accesses", TOTAL_ACCESSES); |
| 167 | + Metric kBytes = counter("Total_kBytes", KBYTES); |
| 168 | + Metric uptime = counter("Uptime", UPTIME); |
| 169 | + |
| 170 | + List<Metric> counters = UnmodifiableList.of(accesses, kBytes, uptime); |
| 171 | + Metric rps = gauge("ReqPerSec", RPS); |
| 172 | + Metric bps = gauge("BytesPerSec", BPS); |
| 173 | + Metric bpr = gauge("BytesPerReq", BPR); |
| 174 | + Metric busyWorkers = gauge("BusyWorkers", BUSY_WORKERS); |
| 175 | + Metric idleWorkers = gauge("IdleWorkers", IDLE_WORKERS); |
| 176 | + List<Metric> gauges = UnmodifiableList.of(rps, bps, bpr, busyWorkers, idleWorkers); |
| 177 | + |
| 178 | + Metric waitingForConnection = scoreboard("WaitingForConnection", 45.0); |
| 179 | + Metric startingUp = scoreboard("StartingUp", 0.0); |
| 180 | + Metric readingRequest = scoreboard("ReadingRequest", 0.0); |
| 181 | + Metric sendingReply = scoreboard("SendingReply", 1.0); |
| 182 | + Metric keepalive = scoreboard("Keepalive", 4.0); |
| 183 | + Metric dnsLookup = scoreboard("DnsLookup", 0.0); |
| 184 | + Metric closingConnection = scoreboard("ClosingConnection", 0.0); |
| 185 | + Metric logging = scoreboard("Logging", 0.0); |
| 186 | + Metric gracefullyFinishing = scoreboard("GracefullyFinishing", 0.0); |
| 187 | + Metric idleCleanupOfWorker = scoreboard("IdleCleanupOfWorker", 0.0); |
| 188 | + Metric unknownState = scoreboard("UnknownState", 0.0); |
| 189 | + List<Metric> scoreboard = UnmodifiableList.of(waitingForConnection, |
| 190 | + startingUp, readingRequest, sendingReply, keepalive, dnsLookup, closingConnection, |
| 191 | + logging, gracefullyFinishing, idleCleanupOfWorker, unknownState); |
| 192 | + |
| 193 | + List<Metric> expected = new ArrayList<>(); |
| 194 | + expected.addAll(counters); |
| 195 | + expected.addAll(gauges); |
| 196 | + expected.addAll(scoreboard); |
| 197 | + |
| 198 | + assertEquals(metrics, expected); |
| 199 | + } |
130 | 200 | } |
0 commit comments