摄入 Logs
直接摄入会将请求体原始内容写入 logger。
curl -X POST "https://api.hola.cloud/v1/loggers/logger_xyz789/ingest" \
-H "Api-Key: LOGGER_API_KEY" \
-H "Api-Secret: LOGGER_API_SECRET" \
--data-binary $'line one\nline two\n'POST /v1/loggers/logger_xyz789/ingest HTTP/1.1
Host: api.hola.cloud
Api-Key: LOGGER_API_KEY
Api-Secret: LOGGER_API_SECRET
$line one\nline two\n// Go 1.21+, standard library only. Save as main.go and run: go run main.go
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := "$line one\\nline two\\n"
req, err := http.NewRequest("POST", "https://api.hola.cloud/v1/loggers/logger_xyz789/ingest", strings.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Api-Key", "LOGGER_API_KEY")
req.Header.Set("Api-Secret", "LOGGER_API_SECRET")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(resp.Status)
fmt.Println(string(responseBody))
}
<?php
// PHP 8+ with the curl extension. Save as example.php and run: php example.php
$body = '$line one\\nline two\\n';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.hola.cloud/v1/loggers/logger_xyz789/ingest',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => [
'Api-Key: LOGGER_API_KEY',
'Api-Secret: LOGGER_API_SECRET',
],
]);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch));
}
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $response, "\n";
curl_close($ch);
# Python 3.8+. Install: pip install requests. Save as example.py and run: python example.py
import requests
headers = {
"Api-Key": "LOGGER_API_KEY",
"Api-Secret": "LOGGER_API_SECRET",
}
body = "$line one\\nline two\\n"
response = requests.request(
"POST",
"https://api.hola.cloud/v1/loggers/logger_xyz789/ingest",
headers=headers,
data=body
)
print(response.status_code)
print(response.text)
// Node.js 18+. Save as example.mjs and run: node example.mjs
const body = "$line one\\nline two\\n";
const response = await fetch("https://api.hola.cloud/v1/loggers/logger_xyz789/ingest", {
method: "POST",
headers: {
"Api-Key": "LOGGER_API_KEY",
"Api-Secret": "LOGGER_API_SECRET"
},
body
});
console.log(response.status);
console.log(await response.text());
const body = "$line one\\nline two\\n";
const response = await fetch("https://api.hola.cloud/v1/loggers/logger_xyz789/ingest", {
method: "POST",
headers: {
"Api-Key": "LOGGER_API_KEY",
"Api-Secret": "LOGGER_API_SECRET"
},
body
});
console.log(response.status);
console.log(await response.text());
// Java 17+, standard library only. Save as Main.java and run: java Main.java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
var body = """
$line one\nline two\n
""";
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.hola.cloud/v1/loggers/logger_xyz789/ingest"))
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.header("Api-Key", "LOGGER_API_KEY")
.header("Api-Secret", "LOGGER_API_SECRET")
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}1{ "n": 18 }
帧摄入在 POST /v1/ingest/events 使用 logframe 数据。每个 frame 的 metadata 必须包含 project_id;响应报告接收的 events 和写入的 bytes。
评论