-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DataDog/add_service_checks
Add service check to java dogstatsd client, add test
- Loading branch information
Showing
7 changed files
with
232 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
<version>5</version> | ||
</parent> | ||
|
||
<groupId>com.indeed</groupId> | ||
<groupId>com.datadog</groupId> | ||
<artifactId>java-dogstatsd-client</artifactId> | ||
<packaging>jar</packaging> | ||
<name>java-dogstatsd-client</name> | ||
<version>2.0.9-SNAPSHOT</version> | ||
<version>2.1.0</version> | ||
<description>A tiny library allowing Java applications to communicate with DataDog statsd instances easily.</description> | ||
<url>https://github.com/indeedeng/java-dogstatsd-client</url> | ||
|
||
|
@@ -34,6 +34,11 @@ | |
</scm> | ||
|
||
<developers> | ||
<developer> <!-- Additions for new Datadog features --> | ||
<id>datadog</id> | ||
<name>Datadog developers</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
<developer> <!-- Initial datadog port --> | ||
<id>duffy</id> | ||
<name>Charles Duffy</name> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package com.timgroup.statsd; | ||
|
||
/** | ||
* A service check model, which is used to format a service check message | ||
* sent to the datadog agent | ||
*/ | ||
public class ServiceCheck { | ||
public static final int OK = 0; | ||
public static final int WARNING = 1; | ||
public static final int CRITICAL = 2; | ||
public static final int UNKNOWN = 3; | ||
|
||
private String name, hostname, message; | ||
|
||
private int status, checkRunId, timestamp; | ||
|
||
private String[] tags; | ||
|
||
/** | ||
*/ | ||
public ServiceCheck() { | ||
} | ||
|
||
/** | ||
* @param name | ||
* @param status | ||
*/ | ||
public ServiceCheck(String name, int status) { | ||
this(name, status, null, null, null); | ||
} | ||
|
||
public ServiceCheck(String name, int status, String message, String[] tags) { | ||
this(name, status, message, null, tags); | ||
} | ||
|
||
public ServiceCheck(String name, int status, String message, String hostname, String[] tags) { | ||
this.name = name; | ||
this.status = status; | ||
this.message = message; | ||
this.hostname = hostname; | ||
this.tags = tags; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @param name | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
/** | ||
* @param status | ||
*/ | ||
public void setStatus(int status) { | ||
this.status = status; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String getEscapedMessage() { | ||
return message.replace("\n", "\\n").replace("m:", "m\\:"); | ||
} | ||
|
||
/** | ||
* | ||
* @param message | ||
*/ | ||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String getHostname() { | ||
return hostname; | ||
} | ||
|
||
/** | ||
* @param hostname | ||
*/ | ||
public void setHostname(String hostname) { | ||
this.hostname = hostname; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public int getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
/** | ||
* @param timestamp | ||
*/ | ||
public void setTimestamp(int timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String[] getTags() { | ||
return tags; | ||
} | ||
|
||
/** | ||
* @param tags | ||
*/ | ||
public void setTags(String... tags) { | ||
this.tags = tags; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
public String toStatsDString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(String.format("_sc|%s|%d", name, status)); | ||
if (timestamp > 0) { | ||
sb.append(String.format("|d:%d", timestamp)); | ||
} | ||
if (hostname != null) { | ||
sb.append(String.format("|h:%s", hostname)); | ||
} | ||
if (tags != null && tags.length > 0) { | ||
sb.append(String.format("|#%s", tags[0])); | ||
for(int i=1;i<tags.length;i++) { | ||
sb.append(',').append(tags[i]); | ||
} | ||
} | ||
if (message != null) { | ||
sb.append(String.format("|m:%s", this.getEscapedMessage())); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters