|
| 1 | +# Quick Start |
| 2 | + |
| 3 | + |
| 4 | +## Download and install & start GreptimeDB |
| 5 | + |
| 6 | +Follow the [Installation Guide](/getting-started/overview.md) to install and start GreptimeDB. |
| 7 | + |
| 8 | +## Create a Pipeline |
| 9 | + |
| 10 | +GreptimeDB provides a dedicated HTTP interface for creating Pipelines. Here's how to do it: |
| 11 | + |
| 12 | +First, create a Pipeline file, for example, `pipeline.yaml`. |
| 13 | + |
| 14 | +```yaml |
| 15 | +# pipeline.yaml |
| 16 | +processors: |
| 17 | + - date: |
| 18 | + field: time |
| 19 | + formats: |
| 20 | + - "%Y-%m-%d %H:%M:%S%.3f" |
| 21 | + ignore_missing: true |
| 22 | + |
| 23 | +transform: |
| 24 | + - fields: |
| 25 | + - id1 |
| 26 | + - id2 |
| 27 | + type: int32 |
| 28 | + - fields: |
| 29 | + - type |
| 30 | + - logger |
| 31 | + type: string |
| 32 | + index: tag |
| 33 | + - fields: |
| 34 | + - log |
| 35 | + type: string |
| 36 | + index: fulltext |
| 37 | + - field: time |
| 38 | + type: time |
| 39 | + index: timestamp |
| 40 | +``` |
| 41 | +
|
| 42 | +Then, execute the following command to upload the configuration file: |
| 43 | +
|
| 44 | +```shell |
| 45 | +## Upload the pipeline file. "test" is the name of the Pipeline |
| 46 | +curl -X "POST" "http://localhost:4000/v1/events/pipelines/test" -F "file=@pipeline.yaml" |
| 47 | +``` |
| 48 | + |
| 49 | +After the successful execution of this command, a Pipeline named `test` will be created, and the result will be returned as: `{"name":"test","version":"2024-06-27 12:02:34.257312110Z"}`. |
| 50 | +Here, `name` is the name of the Pipeline, and `version` is the Pipeline version. |
| 51 | + |
| 52 | +This Pipeline includes one Processor and three Transforms. The Processor uses the Rust time format string `%Y-%m-%d %H:%M:%S%.3f` to parse the timestamp field in the logs, and then the Transforms convert the `id1` and `id2` fields to `int32` type, the `type` and `logger` fields to `string` type with an index of "tag", the `log` field to `string` type with an index of "fulltext", and the `time` field to a time type with an index of "timestamp". |
| 53 | + |
| 54 | +Refer to the [Pipeline Introduction](log-pipeline.md) for specific syntax details. |
| 55 | + |
| 56 | +## Query Pipelines |
| 57 | + |
| 58 | +You can use SQL to query the pipeline content stored in the database. The example query is as follows: |
| 59 | + |
| 60 | +```sql |
| 61 | +SELECT * FROM greptime_private.pipelines; |
| 62 | +``` |
| 63 | + |
| 64 | +The query result is as follows: |
| 65 | + |
| 66 | +```sql |
| 67 | + name | schema | content_type | pipeline | created_at |
| 68 | +------+--------+--------------+-----------------------------------+---------------------------- |
| 69 | + test | public | yaml | processors: +| 2024-06-27 12:02:34.257312 |
| 70 | + | | | - date: +| |
| 71 | + | | | field: time +| |
| 72 | + | | | formats: +| |
| 73 | + | | | - "%Y-%m-%d %H:%M:%S%.3f"+| |
| 74 | + | | | ignore_missing: true +| |
| 75 | + | | | +| |
| 76 | + | | | transform: +| |
| 77 | + | | | - fields: +| |
| 78 | + | | | - id1 +| |
| 79 | + | | | - id2 +| |
| 80 | + | | | type: int32 +| |
| 81 | + | | | - fields: +| |
| 82 | + | | | - type +| |
| 83 | + | | | - logger +| |
| 84 | + | | | type: string +| |
| 85 | + | | | index: tag +| |
| 86 | + | | | - fields: +| |
| 87 | + | | | - log +| |
| 88 | + | | | type: string +| |
| 89 | + | | | index: fulltext +| |
| 90 | + | | | - field: time +| |
| 91 | + | | | type: time +| |
| 92 | + | | | index: timestamp +| |
| 93 | + | | | | |
| 94 | +(1 row) |
| 95 | +``` |
| 96 | + |
| 97 | +## Write logs |
| 98 | + |
| 99 | +The HTTP interface for writing logs is as follows: |
| 100 | + |
| 101 | +```shell |
| 102 | +curl -X "POST" "http://localhost:4000/v1/events/logs?db=public&table=logs&pipeline_name=test" \ |
| 103 | + -H 'Content-Type: application/json' \ |
| 104 | + -d $'{"time":"2024-05-25 20:16:37.217","id1":"2436","id2":"2528","type":"I","logger":"INTERACT.MANAGER","log":"ClusterAdapter:enter sendTextDataToCluster\\n"} |
| 105 | +{"time":"2024-05-25 20:16:37.217","id1":"2436","id2":"2528","type":"I","logger":"INTERACT.MANAGER","log":"ClusterAdapter:enter sendTextDataToCluster\\n"} |
| 106 | +{"time":"2024-05-25 20:16:37.217","id1":"2436","id2":"2528","type":"I","logger":"INTERACT.MANAGER","log":"ClusterAdapter:enter sendTextDataToCluster\\n"} |
| 107 | +{"time":"2024-05-25 20:16:37.217","id1":"2436","id2":"2528","type":"I","logger":"INTERACT.MANAGER","log":"ClusterAdapter:enter sendTextDataToCluster\\n"}' |
| 108 | +``` |
| 109 | + |
| 110 | +The above command returns the following result: |
| 111 | + |
| 112 | +```json |
| 113 | +{"output":[{"affectedrows":4}],"execution_time_ms":22} |
| 114 | +``` |
| 115 | + |
| 116 | +In the above example, we successfully wrote 4 log entries to the `public.logs` table. |
| 117 | + |
| 118 | +Please refer to [Writing Logs with Pipeline](write-log.md) for specific syntax for writing logs. |
| 119 | + |
| 120 | +## `logs` table structure |
| 121 | + |
| 122 | +We can use SQL to query the structure of the `public.logs` table. |
| 123 | + |
| 124 | +```sql |
| 125 | +DESC TABLE logs; |
| 126 | +``` |
| 127 | + |
| 128 | +The query result is as follows: |
| 129 | + |
| 130 | +```sql |
| 131 | + Column | Type | Key | Null | Default | Semantic Type |
| 132 | +--------+---------------------+-----+------+---------+--------------- |
| 133 | + id1 | Int32 | | YES | | FIELD |
| 134 | + id2 | Int32 | | YES | | FIELD |
| 135 | + type | String | PRI | YES | | TAG |
| 136 | + logger | String | PRI | YES | | TAG |
| 137 | + log | String | | YES | | FIELD |
| 138 | + time | TimestampNanosecond | PRI | NO | | TIMESTAMP |
| 139 | +(6 rows) |
| 140 | +``` |
| 141 | + |
| 142 | +From the above result, we can see that based on the processed result of the pipeline, the `public.logs` table contains 6 fields: `id1` and `id2` are converted to the `Int32` type, `type`, `log`, and `logger` are converted to the `String` type, and time is converted to a `TimestampNanosecond` type and indexed as Timestamp. |
| 143 | + |
| 144 | +## Query logs |
| 145 | + |
| 146 | +We can use standard SQL to query log data. |
| 147 | + |
| 148 | +```shell |
| 149 | +# Connect to GreptimeDB using MySQL or PostgreSQL protocol |
| 150 | + |
| 151 | +# MySQL |
| 152 | +mysql --host=127.0.0.1 --port=4002 public |
| 153 | + |
| 154 | +# PostgreSQL |
| 155 | +psql -h 127.0.0.1 -p 4003 -d public |
| 156 | +``` |
| 157 | + |
| 158 | +You can query the log table using SQL: |
| 159 | + |
| 160 | +```sql |
| 161 | +SELECT * FROM public.logs; |
| 162 | +``` |
| 163 | + |
| 164 | +The query result is as follows: |
| 165 | + |
| 166 | +```sql |
| 167 | + id1 | id2 | type | logger | log | time |
| 168 | +------+------+------+------------------+--------------------------------------------+---------------------------- |
| 169 | + 2436 | 2528 | I | INTERACT.MANAGER | ClusterAdapter:enter sendTextDataToCluster+| 2024-05-25 20:16:37.217000 |
| 170 | + | | | | | |
| 171 | + 2436 | 2528 | I | INTERACT.MANAGER | ClusterAdapter:enter sendTextDataToCluster+| 2024-05-25 20:16:37.217000 |
| 172 | + | | | | | |
| 173 | + 2436 | 2528 | I | INTERACT.MANAGER | ClusterAdapter:enter sendTextDataToCluster+| 2024-05-25 20:16:37.217000 |
| 174 | + | | | | | |
| 175 | + 2436 | 2528 | I | INTERACT.MANAGER | ClusterAdapter:enter sendTextDataToCluster+| 2024-05-25 20:16:37.217000 |
| 176 | + | | | | | |
| 177 | +(4 rows) |
| 178 | +``` |
| 179 | + |
| 180 | +As you can see, the logs have been stored as structured logs after applying type conversions using the pipeline. This provides convenience for further querying and analysis of the logs. |
| 181 | + |
| 182 | +## Conclusion |
| 183 | + |
| 184 | +By following the above steps, you have successfully created a pipeline, written logs, and performed queries. This is just the tip of the iceberg in terms of the capabilities offered by GreptimeDB. |
| 185 | +Next, please continue reading [Pipeline Configuration](log-pipeline.md) and [Managing Pipelines](manage-pipeline.md) to learn more about advanced features and best practices. |
0 commit comments