tencent cloud


Writing Data

Last updated: 2024-01-29 16:01:55


    Similar to the scenario of data reporting by Flink jobs, you need to write data directly to Prometheus through APIs, as the lifecycle of these jobs may be very short, and it would be too late to wait for Prometheus to pull the data. To write data, you can directly use the remote write protocol or Pushgateway.

    Remote Write

    POST /api/v1/prom/write
    Remote write is a standard protocol of Prometheus. For more information, please see REMOTE WRITE TUNING. With remote write, you can write other Prometheus data in the VPC to TMP, which helps improve the data stability and make migration easier.


    Although the pull method is recommended in Prometheus, you may still need to use the push method in some scenarios. For more information, please see WHEN TO USE THE PUSHGATEWAY.
    TMP is natively integrated with the Pushgateway module, which can directly push data to it. Below is a simple example of pushing data in Go. You need to change the variables of $IP, $PORT, $APPID, and $TOKEN to the authentication information of your own instance, which can be queried in the console.
    We strongly recommend you replace $INSTANCE with an identifier of the current machine, such as IP/Hostname. If this groupingKey is not set, when multiple machines report data together, the data entries will overwrite each other.
    package main
    import (
    var completionTime = prometheus.NewGauge(prometheus.GaugeOpts{
    Name: "db_backup_last_completion_timestamp_seconds",
    Help: "The timestamp of the last successful completion of a DB backup.",
    func do() {
    func ExamplePusher_Push() {
    if err := push.New("http://$IP:$PORT", "db_backup").
    BasicAuth("$APPID", "$TOKEN").
    Grouping("instance", "$INSTANCE").
    Grouping("db", "customers").
    Push(); err != nil {
    fmt.Println("Could not push completion time to Pushgateway:", err)
    func main() {
    ticker := time.NewTicker(2 * time.Second)
    done := make(chan bool)
    for {
    select {
    case <-done:
    case <-ticker.C:
    You can customize the HTTP Client through the Client method for the object generated by push.New. We recommend you set an appropriate timeout period. In addition, if data is pushed, we recommend you use an async method for calls so as to avoid blocking the primary business process.
    For other reporting scenarios, please see Custom Monitoring.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support