Google cloud platform 有没有办法计算谷歌云函数执行的成本?

Google cloud platform 有没有办法计算谷歌云函数执行的成本?,google-cloud-platform,google-cloud-functions,Google Cloud Platform,Google Cloud Functions,例如,当我们使用PubSub触发器部署和调用时,我们可以接收Python中的数据和上下文,如下所示: def hello_pubsub(event, context): """Background Cloud Function to be triggered by Pub/Sub. Args: event (dict): The dictionary with data specific to this type of event. The

例如,当我们使用PubSub触发器部署和调用时,我们可以接收Python中的数据和上下文,如下所示:

def hello_pubsub(event, context):
    """Background Cloud Function to be triggered by Pub/Sub.
    Args:
         event (dict):  The dictionary with data specific to this type of
         event. The `data` field contains the PubsubMessage message. The
         `attributes` field will contain custom attributes if there are any.
         context (google.cloud.functions.Context): The Cloud Functions event
         metadata. The `event_id` field contains the Pub/Sub message ID. The
         `timestamp` field contains the publish time.
    """
    import base64

    print("""This Function was triggered by messageId {} published at {}
    """.format(context.event_id, context.timestamp))

    if 'data' in event:
        name = base64.b64decode(event['data']).decode('utf-8')
    else:
        name = 'World'
    print('Hello {}!'.format(name))

是否可以使用
上下文。事件id
或上下文来确定执行结束时的总成本?

云功能的计费与执行时间和您使用的机器类型有关。这可以从中看出

您最好使用Stackdriver日志检查函数执行所需的时间,并将其用作进行近似计费的基础。我之所以说近似值,是因为即使有日志的时间戳,你的结果和谷歌在月底的账单之间也可能有点不一致

此外,为了更好地了解该月的预期总开支,您需要估计调用该函数的次数


希望您觉得这很有用。

云功能的计费与执行时间和您使用的机器类型有关。这可以从中看出

您最好使用Stackdriver日志检查函数执行所需的时间,并将其用作进行近似计费的基础。我之所以说近似值,是因为即使有日志的时间戳,你的结果和谷歌在月底的账单之间也可能有点不一致

此外,为了更好地了解该月的预期总开支,您需要估计调用该函数的次数


希望你觉得这很有用。

这不是我想要的答案,但我会接受,因为这似乎是目前唯一的解决方案,直到有人有更好的想法。这不是我想要的答案,但我会接受,因为这似乎是目前唯一的解决方案,直到有人有更好的想法。