|
|||
Send DataYou can send logs, events, and metrics to the Cloud Monitoring service. To send data to the service, use a separate client class - SendClient. Create an instance of this class: MonitoringServiceClient.send() ![]() To send logs, use the logs method: MonitoringServiceClient.send().logs(source, logs); The log record format is as follows: { "objectType":"log", // required "timestamp":"2018-07-31T11:07:02.312", // required; formats: [ISO8601, UNIX_MS] "message":"Hello, Monitoring!", // required; plain text "severity":"DEBUG", // optional; plain text "parameters":{ // optional; you can use any names for sub-fields "logger":"xes.system", // optional … } } Note: All unspecified root-level fields are dropped. To create a log record, use the LogRecord class with a chained (or fluent) builder: new LogRecord() .withMessage("some log message 2") .withTimestamp(System.currentTimeMillis()) .withParameters(new Parameters() .put("key", "value3") .put("key2", "value4")) You can use the following parameters:
![]() To send metrics, use the metrics method: MonitoringServiceClient.send().metrics(source, metric); The metric record format is as follows: { "objectType":"metric", // required "timestamp":1533065825066, // required; formats: [ISO8601, UNIX_MS] "Memory Usage (Kb)": { // required; an object cannot have the “objectType”, “timestamp” and “parameters” names. // Can contain one or more sub-fields with arbitrary names and numeric values "AVERAGE":107696.0, // required; numeric [int, long, float, double] "MIN":67567, // optional; numeric [int, long, float, double] "MAX":147825, // optional; numeric [int, long, float, double] "COUNT":2, // optional; numeric [int, long, float, double] "SUM":215392, // optional; numeric [int, long, float, double] "LATEST":67567 // optional; numeric [int, long, float, double] }, "parameters":{ // optional; any names can be used for sub-fields "name":"profile=Default", // optional "type":"profile", // optional ... } } To create a metric record, use the MetricRecord class similar to the LogRecord class. ![]() To send events, use the events method: MonitoringServiceClient.send().events(source, events); The event record format is as follows: { "objectType": "event", // required "timestamp": "2018-07-31T12:27:02.312", // require;, formats [ISO8601, UNIX_MS] "name": "XEServer is STOPPED", // required; plain text "parameters": { // optional; you can use any names for sub-fields "system":"/", // optional "type":"XES Command Event", // optional ... } } Note: All unspecified root-level fields are dropped. To create an event record, use the EventRecord class similar to the LogRecord class. You can send logs, events, and metrics as:
SendResult logs(String source, InputStream data) Parameters: source: a source name validated using the following regular expression: [\w+\-_!.'()]{1,255} data: binary data stream in the utf-8 format. Has to be a valid JSON string. SendResult logs(String source, byte[] data) Parameters: source: a source name validated using the following regular expression: [\w+\-_!.'()]{1,255} data: binary data in the utf-8 format. Has to be a valid JSON string. SendResult logs(String source, LogRecord... records) Parameters: source: a source name validated using the following regular expression: [\w+\-_!.'()]{1,255} data: an array of LogRecord SendResult logs(String source, Collection<LogRecord> records) Parameters: source: a source name validated using the following regular expression: [\w+\-_!.'()]{1,255} data: an array of LogRecord Note: We recommend you send data to the Cloud Monitoring service as a binary data stream using the InputStream methods. When you do this, data is sent in the HTTP stream that does not require data buffering. |