Skip to main content

Solving Python Code to Agregate types.common.TypedValue

Malam senin saya pergi ke Mall namun dengan tujuan ke Sbucks nya aja, sebenaranya ini postingan bukan tentang Sbucks dan yah gak cuma sekali itu saja ke coffe shop ini, ini untuk menjelakan proses perjalanan aja, ke Mall dengan Ojek Online dari Kos lumayan dekat bayar 15rb cash, saat itu gopay habis.

Sampai Sbucks Coffe langsung pesan Iced Cinnamon Roll Latte yang sebelumnya sudah pernah juga, lumayan sepi tapi masih ada 1 orang yang buka laptop, yang lain cuma duduk, dan yah agak aneh juga kalau hari libur buka laptop haha, dan yah coffe shop ini memang terkenal gengsi nya, namun saya sebenaranya gak terlalu memikirkan itu, bebas aja, salama bisa produktif, bisa enjoy di coffe shop nya worth it2 aja, dan sepi mungkin karena besok senin dan mau tutup juga jam 10 malam,  ukuran grande dengan harga 46.400 sudah potongan 20% yang saya dapatkan di Aplikasi, pembayaran dengan member yang sejak 11 March 2022.

Potongan kode saja mau melihat hasil titik point nya namun sebelunya dalam bentuk int64 value dalam typedValue https://cloud.google.com/monitoring/api/ref_v3/rest/v3/TypedValue

The TypedValue is a class from the Google Cloud Monitoring library, specifically from the google.cloud.monitoring_v3 module. It is used to represent a metric value along with its data type.

In the Google Cloud Monitoring API, metrics can have different value types, such as integer, double, boolean, string, and distribution. The TypedValue class is used to encapsulate the value and type information of a metric data point.

Ini hasil code nya:

from google.cloud import monitoring_v3
from datetime import datetime, timedelta

# Set up authentication
# Make sure you have the appropriate credentials configured.

# Create a client for the Monitoring API
client = monitoring_v3.MetricServiceClient()


# Set the required parameters
project_id = 'your-cloud-project'
filter_str = 'metric.type="iam.googleapis.com/service_account/authn_events_count" AND resource.labels.unique_id="your-resource-unique-id"'

# Calculate the time interval
end_time = datetime.now()
start_time = end_time - timedelta(days=90)

# Execute the request to retrieve the metric data
request = monitoring_v3.ListTimeSeriesRequest(
name=f'projects/{project_id}',
filter=filter_str,
interval=monitoring_v3.TimeInterval(
start_time=start_time,
end_time=end_time,
),
)
response = client.list_time_series(request)

total_value = 0

# Process the response
for time_series in response.time_series:
for point in time_series.points:
# print(f'Time: {point.interval.start_time}, Value: {point.value}')
variable_type = type(point.value)
# print(variable_type)
# print(f'{point.value}')
value = point.value.int64_value
print(value)
total_value += point.value.int64_value

print("Total value:", total_value)


Dengan code diatas sudah bisa membaca data time_series dari sebuah metric monitoring, pada use case kali ini saya melakukan percobaan dengan endpoint google-cloud-monitoring dengan library python google-cloud-monitoring.


Referensi:

https://medium.com/google-cloud/fetching-monitoring-metrics-data-from-gcp-into-your-application-using-python-214358b0047e




Comments

Popular posts from this blog

Soal dan pembahasan LKSN ITNSA

Berikut adalah koleksi soal-soal ITNSA dan beberapa website yang memberikan pembahasan pada event perlombaaan LKS SMK Nasional bidang lomba IT Network Systems Administration. 2014 Palembang Di tahun ini ada 1 soal packet tracer. Di website dibawah ini diberikan juga cara pembahasannya. https://agussas.wordpress.com/2015/04/02/review-soal-lks-nasional-it-network-23-packet-tracer-challenge/ Semua soal:  https://www.dropbox.com/sh/l90zyke2ib5msgv/AAA3kPOFo-zEn4wPOW4a3iMwa?dl=0 dan https://drive.google.com/file/d/18lDhtMjAnPAhkfOJ6uFHsC5j6ycg3K4I/view Pembahasan juga dalam bentuk video di youtube:  https://www.youtube.com/watch?v=8QML594nQBU 2015 Banten Pembahasan:   https://www.youtube.com/watch?v=quDbpC2xSfQ Soal:  https://drive.google.com/file/d/1B09IYfdoGENBL3txSQodpptG1zdQxBWI/view 2016 Malang Soal:   https://drive.google.com/file/d/13-2bRtb5IXO9vxAhLfhghZbDXeUzD0FI/view Pembahasan:   https://www.youtube.com/watch?v=zmUSUZguH24 20...

Dasar instalasi dan konfigurasi OpenLDAP

 ### Panduan Instalasi OpenLDAP Berikut adalah panduan sederhana untuk menginstal dan mengkonfigurasi OpenLDAP pada server dengan domain `bagussa.my.id` dan IP `10.10.10.1`.  #### 1. Instalasi OpenLDAP Pertama, instal OpenLDAP beserta paket-paket yang diperlukan: ```bash sudo apt update sudo apt install slapd ldap-utils ``` Selama instalasi, Anda mungkin akan diminta untuk memasukkan kata sandi untuk `admin` LDAP. Simpan kata sandi ini dengan aman. #### 2. Konfigurasi Manual di `/etc/hosts` Tambahkan entri untuk domain dan IP di file `/etc/hosts`: ```bash sudo nano /etc/hosts ``` Tambahkan baris berikut: ``` 10.10.10.1    bagussa.my.id ``` Simpan dan keluar dari editor. #### 3. Konfigurasi `/etc/ldap/ldap.conf` Edit file konfigurasi LDAP: ```bash sudo nano /etc/ldap/ldap.conf ``` Tambahkan atau modifikasi baris berikut: ``` BASE    dc=bagussa,dc=my,dc=id URI     ldap://10.10.10.1 ``` Simpan dan keluar dari editor. #### 4. Buat OU dan Group de...

TABLE OF CONTENTS

BASIC CONFIGURATION https://sa-bagus.blogspot.com/2023/01/soal-dan-pembahasan-lks-itnsa-network.html DYNAMIC CONFIGURATION PROTOCOL https://sa-bagus.blogspot.com/2020/05/pembahasan-lks-asc-wsc-modul-cisco-dhcp.html VIRTUAL PRIVATE NETWORK https://sa-bagus.blogspot.com/2020/06/referensi-bagus-untuk-konfigurasi.html PUBLIC KEY INFRASTRUCTURE / CERTIFICATE https://sa-bagus.blogspot.com/2023/01/pembahasan-lks-itnsa-ceritificate.html DIRECTORY SERVICES https://sa-bagus.blogspot.com/2018/01/menginstal-dan-mengkonfigurasi.html https://sa-bagus.blogspot.com/2022/11/lks-wsc-itnsa-how-to-create-user.html WEB SERVER https://sa-bagus.blogspot.com/2023/09/cara-redirect-http-ke-https-di-apache2.html