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

ITNSA Konfigurasi Ansible WinRM Windows Server

 ### Mengonfigurasi Koneksi Ansible ke Server Windows Ansible adalah alat otomatisasi yang sangat populer dan sering digunakan untuk mengelola berbagai jenis server, termasuk server Windows. Artikel ini akan memandu Anda melalui langkah-langkah untuk mengonfigurasi Ansible agar dapat terhubung dengan server Windows menggunakan WinRM (Windows Remote Management). #### 1. Menyiapkan WinRM di Server Windows ##### Opsi 1: Menggunakan Skrip PowerShell Anda bisa menggunakan skrip PowerShell yang sudah disediakan untuk mengonfigurasi WinRM agar dapat digunakan oleh Ansible. 1. Buka PowerShell di server Windows Anda sebagai administrator. 2. Jalankan perintah berikut untuk mengunduh dan mengeksekusi skrip konfigurasi:    ```powershell    iex (New-Object Net.WebClient).DownloadString('https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')    ``` ##### Opsi 2: Pengaturan Manual 1. Buka PowerShell di server Windows Anda seb...

Soal dan pembahasan LKS ITNSA Network Infrastructure Basic

Soal tahun 2021 tingkat Nasional Soal bisa di download di https://itnsa.id Basic Configuration Configure IP Address of all network devices according to the addressing table.  Create SSH user ‘patah’ with password specified in the appendix.  Make sure the user are able to enter configuration commands in the router.  Allow server admins to SSH to all network devices.  If you need to set additional password on the Routers, use Skills39 Look at the appendix table and configure accordingly Configure IP address: csr1000v# configure terminal #change interface name according to the topology csr1000v (config)# interface GigabitEthernet0 csr1000v (config-if)# ip address  x.x.x.x y.y.y.y csr1000v (config-if)# no shutdown Create SSH user: csr1000v# configure terminal csr1000v (config) # username patah password cisco123 csr1000v (config)# privilege 15 patah Allow server admins to SSH: csr1000v# configure terminal csr1000v (config)# ip access-list standard SSH_ACL csr10...

Analisa Traffic WAF

 Tentu, berikut adalah contoh untuk setiap bagian analisis traffic WAF: #### 1. Analisis Path **Contoh**: - **Path yang Tidak Biasa**: Misalkan aplikasi Anda memiliki endpoint `/login`. Jika Anda melihat permintaan ke path seperti `/admin/../../config`, ini adalah path yang mencurigakan karena tampaknya mencoba mengakses direktori konfigurasi dengan teknik path traversal. - **Pengelompokan Traffic**: Jika banyak permintaan ke path `/api/upload` yang mencurigakan, ini bisa menunjukkan upaya eksploitasi terhadap fungsi upload file. #### 2. Analisis Method **Contoh**: - **Method GET**: Anda melihat permintaan GET dengan query string yang panjang seperti `GET /search?q=...`, di mana query string sangat panjang dan mengandung karakter yang tidak biasa. Ini bisa menjadi indikasi serangan seperti buffer overflow. - **Method POST**: Anda menerima banyak permintaan POST dengan payload yang besar dan mencurigakan, seperti `POST /update-profile` dengan data yang tidak sesuai format atau panja...