전체 글 445

[ Python ] numpy를 이용한 1차원 배열 2 차원 배열로 변환

list 데이터를 처리하다 보면, 1차원 배열을 2차원 배열로 변경해야할 때가 있는데, numpy를 이용하면 쉽게 이용할 수 있다. reshape : 데이터를 변동시키지 않고, 새로운 배열을 만든다. import numpy as np # 3 X 10 a = [ x for x in range(30) ] a = np.array(a) a = a.reshape(10,3) # (2차원 원소수, 원소당 갯수) print(a) array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19, 20], [21, 22, 23], [24, 25, 26], [27, 28, 29]]) # 5 X 6 a = a.reshape(..

[ AWS ] Python boto3를 이용하여 RDS Connections 데이터 추출 하기

import boto3 from datetime import datetime from datetime import timedelta cloudwatch = boto3.client('cloudwatch') def rds_connections(): StartTime = datetime(2023,5,1) - timedelta(hours=9) # 한국시간에 맞게 -0900 # 한국기준으로 5월 1일로 지정해줬기 때문에, UTC는 4월 30일 15시 데이터 추출한다. EndTime = StartTime + timedelta(days=1) response = cloudwatch.get_metric_statistics( Namespace='AWS/RDS', MetricName='DatabaseConnections',..

AWS Infra 2023.05.11

[ AWS ] Python boto3를 이용하여 ELB Metric 모니터링

Python Boto3를 이용하여 ELB 2XX Count 통계를 추출해보고, 효율적으로 모니터링해보자. 메소드는 cloudwatch.get_metric_statistics이용하고, MetricName은 HTTPCode_Target_2XX_Count 을 사용하면 된다. ELB 콘솔 cloudwatch에서도 아래지표와 같이 볼 수 있는데, 이 데이터를 Python으로 추출해보자 from datetime import datetime from datetime import timedelta cloudwatch = boto3.client('cloudwatch') elb = 'string' # elb의 arn의 app이하 부분부터 넣어주면 된다. def elb_2XX_Count(elb): response = clo..

AWS Infra 2023.05.10

[ Python ] 날짜형식의 문자열 타입을 datetime 타입 형식으로 변환

Database, logs 등 날짜형식 데이터를 Python으로 불러와서 처리할 때, 문자열로 저장되게 된다. Python에서 날짜 데이터를 이용하여 그래프를 그리거나 연산을 하기 위해서는 형 변환이 필요하다. datime.datetime.strptime : date 문자열을 datetime 형식으로 변환 from datetime import datetime strtype = '2018-09-15 00:01:14' print(type(strtype)) logdate = datetime.strptime(strtype, '%Y-%m-%d %H:%M:%S') print(type(logdate)) print(logdate) -------------------------------------------------..

[ AWS ] Python boto3를 이용하여 Target Group Health 모니터링

import boto3 client = boto3.client('elbv2') response = client.describe_target_health( TargetGroupArn='string' ) for i in response['TargetHealthDescriptions']: print(i['TargetHealth']['State']) ----------------------------------------------- healthy . 비정상일 경우 : 'unhealthy', 'unused' print(i['TargetHealth']['State'],i['TargetHealth']['Description']) ------------------------------------------------..

AWS Infra 2023.04.25

[ Python ] xml 타입의 데이터 json 으로 변경

xmltodict 모듈설치 pip install xmltodict xml sample https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85) Sample XML File (books.xml) Table of contents Sample XML File (books.xml) Article 10/27/2016 In this article --> The following XML file is used in various samples throughout the Microsoft XML Core Services (MSXML) SDK. Gambardella, Matthew XML Developer's Guide Co..

[ Python ] difflib 모듈 ( 문자열 비교, 유사도 )

difflib.SequenceMatcher ( 유사도 ) from difflib import SequenceMatcher def similar(a, b): return round(float(SequenceMatcher(None, a, b).ratio()),2) * 100 print(similar('서울시 강남구','서울시 영등포구 ')) ----------------------------------------------------------------------- 62.0 difflib.context_diff ( 문자열 목록 비교 ) samplefile_1.txt samplefile_2.txt 1 파이썬 2 python 3 iz 4 beautiful 1 파이선 2 python 3 is 4 beautifu..

[ Python ] Remine API 사용하기

Redmine Python을 이용하면 일감관리, 노트관리, 뉴스 등을 자동화하거나 다른 서비스와 연동할 수 있다. 모듈설치 pip install python-redmine 접근방법은 "User / Password"와 "API Key" 인증 2가지가 있다. API Key를 허용하는 방법은 글 하단에 표기하였다. redmine = Redmine('url', username=' ', password=' ') redmine = Redmine('url', key=' ') 신규 일감(Issue) 생성하기 from redminelib import Redmine import datetime redmine = Redmine('url', key=' ') issue = redmine.issue.create( project_..