Skip to content

Instantly share code, notes, and snippets.

@alili
Last active September 5, 2023 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alili/a7b6f7f8879b090afe0e73be5dd36071 to your computer and use it in GitHub Desktop.
Save alili/a7b6f7f8879b090afe0e73be5dd36071 to your computer and use it in GitHub Desktop.
greptime_getting_started
title
Playground新功能

Playground新功能

一些语法

这是一个链接

:::info 普通信息 支持自定义标题 :::

::: tip 提示信息框 使用方法同上 :::

:::danger 警告信息 使用方法同上 :::

:::warning 注意信息 这篇文章需要在头部加入title配置,否则无法正确显示目录 :::

:::details 折叠信息 这一部分内容是被折叠的 :::

::: code-group

auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", *username, *password)))
exporter, err := otlpmetrichttp.New(
    context.Background(),
    otlpmetrichttp.WithEndpoint(*dbHost),
    otlpmetrichttp.WithURLPath("/v1/otlp/v1/metrics"),
    otlpmetrichttp.WithHeaders(map[string]string{
        "X-Greptime-DB-Name": *dbName,
        "Authorization":      "Basic " + auth,
    }),
    otlpmetrichttp.WithTimeout(time.Second*5),
)
import SqlOperation from './operation'
import { SqlState, SqlInsertValuesState, SqlConfigState, InsertQueueConfigState } from '../type/sql'

import axios from 'axios'

const qs = require('qs')

class Sql extends SqlOperation {
  url: string
  sql: SqlState
  insertQueueConfig: InsertQueueConfigState
  insertValues: Map<string, SqlInsertValuesState>
  timeoutId: Map<string, ReturnType<typeof setTimeout>>

  constructor(dbname: string, sqlConfig: SqlConfigState) {
    super()
    this.sql = {} as SqlState
    this.insertQueueConfig = sqlConfig.insertQueueConfig
    this.insertValues = new Map()
    this.timeoutId = new Map()
    this.url = `/v1/sql?db=${dbname}`
  }

  runSQL = async function (sql) {
    let res: any = await axios.post(
      this.url,
      qs.stringify({
        sql,
      })
    )
    return await res
  }
}

export default Sql
String endpoint = String.format("https://%s/v1/otlp/v1/metrics", dbHost);
String auth = username + ":" + password;
String b64Auth = new String(Base64.getEncoder().encode(auth.getBytes()));
OtlpHttpMetricExporter exporter = OtlpHttpMetricExporter.builder()
                .setEndpoint(endpoint)
                .addHeader("X-Greptime-DB-Name", db)
                .addHeader("Authorization", String.format("Basic %s", b64Auth))
                .setTimeout(Duration.ofSeconds(5))
                .build();
auth = f"{username}:{password}"
b64_auth = base64.b64encode(auth.encode()).decode("ascii")
endpoint = f"https://{host}/v1/otlp/v1/metrics"
exporter = OTLPMetricExporter(
    endpoint=endpoint,
    headers={"Authorization": f"Basic {b64_auth}", "X-Greptime-DB-Name": db},
    timeout=5)

:::

读取自定义内容

打开https://greptime.com/playground?gistId={your_gist_id},就可以加载自定义的内容了。

测试环境可用:https://89dd1e92.greptime-website.pages.dev/playground?gistId={your_gist_id}

代码块语法

例子:

SELECT * FROM cpu_metrics ORDER BY ts DESC;
-- sql (line|usage_user|hostname,environment)
SELECT * FROM cpu_metrics ORDER BY ts DESC;

sql代码块会自动转换为可执行代码块。

bilibili_video_list_info_new{bvid=~'BV1a',__field__='view'}

PromQL代码块会自动转换为可执行代码块。

图片也是可以支持的 it's me|200 it's me|200x200|center

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment