public StatusData < NginxMetrics > parse ( String nginxStatus ) { StatusData < NginxMetrics > status = new StatusData <> ( ) ; if ( StringUtils . isEmpty ( nginxStatus ) ) { throw new IllegalArgumentException ( "nginx status is empty!" ) ; } else { Matcher matcher = pattern . matcher ( nginxStatus ) ; if ( matcher . matches ( ) ) { status . put ( NginxMetrics . ACTIVE , Long . parseLong ( matcher . group ( 1 ) ) ) ; Long accepted = Long . parseLong ( matcher . group ( 2 ) ) ; status . put ( NginxMetrics . ACCEPTED , accepted ) ; status . put ( NginxMetrics . ACCEPTEDPERSECOND , accepted ) ; Long handled = Long . parseLong ( matcher . group ( 3 ) ) ; status . put ( NginxMetrics . HANDLED , handled ) ; status . put ( NginxMetrics . HANDLEDPERSECOND , handled ) ; Long dropped = handled - accepted ; status . put ( NginxMetrics . DROPPED , dropped ) ; status . put ( NginxMetrics . DROPPEDPERSECOND , dropped ) ; Long requests = Long . parseLong ( matcher . group ( 4 ) ) ; status . put ( NginxMetrics . REQUESTS , requests ) ; status . put ( NginxMetrics . REQUESTSPERSECOND , requests ) ; status . put ( NginxMetrics . READING , Long . parseLong ( matcher . group ( 5 ) ) ) ; status . put ( NginxMetrics . WRITING , Long . parseLong ( matcher . group ( 6 ) ) ) ; status . put ( NginxMetrics . WAITING , Long . parseLong ( matcher . group ( 7 ) ) ) ; } else { String message = "NginxStubStatusParser can't parse nginx status response: [" + nginxStatus + "]" ; throw new IllegalArgumentException ( message ) ; } } return status ; }
Parse NGINX stub status into StatusData&lt ; NginxMetrics&gt ; .