99import java .net .UnknownHostException ;
1010import java .net .URL ;
1111import java .net .URLEncoder ;
12- import java .util .Map ;
12+ import java .util .Collections ;
1313import java .util .HashMap ;
14+ import java .util .Map ;
1415
1516import java .io .BufferedWriter ;
1617import java .io .IOException ;
5455public class PushGateway {
5556
5657 private final String address ;
57- private final static int SECONDS_PER_MILLISECOND = 1000 ;
58+ private static final int SECONDS_PER_MILLISECOND = 1000 ;
5859 /**
5960 * Construct a Pushgateway, with the given address.
6061 * <p>
@@ -182,12 +183,11 @@ public void delete(String job, Map<String, String> groupingKey) throws IOExcepti
182183 * Pushes all metrics in a registry, replacing all those with the same job and instance.
183184 * <p>
184185 * This uses the POST HTTP method.
186+ * @deprecated use {@link #push(CollectorRegistry, String, Map)}
185187 */
186188 @ Deprecated
187189 public void push (CollectorRegistry registry , String job , String instance ) throws IOException {
188- Map <String , String > groupingKey = new HashMap <String , String >();
189- groupingKey .put ("instance" , instance );
190- doRequest (registry , job , groupingKey , "POST" );
190+ push (registry , job , Collections .singletonMap ("instance" , instance ));
191191 }
192192
193193 /**
@@ -196,24 +196,22 @@ public void push(CollectorRegistry registry, String job, String instance) throws
196196 * This is useful for pushing a single Gauge.
197197 * <p>
198198 * This uses the POST HTTP method.
199+ * @deprecated use {@link #push(Collector, String, Map)}
199200 */
200201 @ Deprecated
201202 public void push (Collector collector , String job , String instance ) throws IOException {
202- CollectorRegistry registry = new CollectorRegistry ();
203- collector .register (registry );
204- push (registry , job , instance );
203+ push (collector , job , Collections .singletonMap ("instance" , instance ));
205204 }
206205
207206 /**
208207 * Pushes all metrics in a registry, replacing only previously pushed metrics of the same name.
209208 * <p>
210209 * This uses the PUT HTTP method.
210+ * @deprecated use {@link #pushAdd(CollectorRegistry, String, Map)}
211211 */
212212 @ Deprecated
213213 public void pushAdd (CollectorRegistry registry , String job , String instance ) throws IOException {
214- Map <String , String > groupingKey = new HashMap <String , String >();
215- groupingKey .put ("instance" , instance );
216- doRequest (registry , job , groupingKey , "PUT" );
214+ pushAdd (registry , job , Collections .singletonMap ("instance" , instance ));
217215 }
218216
219217 /**
@@ -222,24 +220,22 @@ public void pushAdd(CollectorRegistry registry, String job, String instance) thr
222220 * This is useful for pushing a single Gauge.
223221 * <p>
224222 * This uses the PUT HTTP method.
223+ * @deprecated use {@link #pushAdd(Collector, String, Map)}
225224 */
226225 @ Deprecated
227226 public void pushAdd (Collector collector , String job , String instance ) throws IOException {
228- CollectorRegistry registry = new CollectorRegistry ();
229- collector .register (registry );
230- pushAdd (registry , job , instance );
227+ pushAdd (collector , job , Collections .singletonMap ("instance" , instance ));
231228 }
232229
233230 /**
234231 * Deletes metrics from the Pushgateway.
235232 * <p>
236233 * This uses the DELETE HTTP method.
234+ * @deprecated use {@link #delete(String, Map)}
237235 */
238236 @ Deprecated
239237 public void delete (String job , String instance ) throws IOException {
240- Map <String , String > groupingKey = new HashMap <String , String >();
241- groupingKey .put ("instance" , instance );
242- doRequest (null , job , groupingKey , "DELETE" );
238+ delete (job , Collections .singletonMap ("instance" , instance ));
243239 }
244240
245241 void doRequest (CollectorRegistry registry , String job , Map <String , String > groupingKey , String method ) throws IOException {
0 commit comments