public void push ( CollectorRegistry registry ) throws IOException { Socket s = new Socket ( host , port ) ; BufferedWriter writer = new BufferedWriter ( new PrintWriter ( s . getOutputStream ( ) ) ) ; Matcher m = INVALID_GRAPHITE_CHARS . matcher ( "" ) ; long now = System . currentTimeMillis ( ) / 1000 ; for ( Collector . MetricFamilySamples metricFamilySamples : Collections . list ( registry . metricFamilySamples ( ) ) ) { for ( Collector . MetricFamilySamples . Sample sample : metricFamilySamples . samples ) { m . reset ( sample . name ) ; writer . write ( m . replaceAll ( "_" ) ) ; for ( int i = 0 ; i < sample . labelNames . size ( ) ; ++ i ) { m . reset ( sample . labelValues . get ( i ) ) ; writer . write ( "." + sample . labelNames . get ( i ) + "." + m . replaceAll ( "_" ) ) ; } writer . write ( " " + sample . value + " " + now + "\n" ) ; } } writer . close ( ) ; s . close ( ) ; }
Push samples from the given registry to Graphite .