|
2 | 2 | from random import seed, random
|
3 | 3 |
|
4 | 4 | import logicmonitor_data_sdk
|
| 5 | + |
| 6 | +# LogicMonitor metric data model is as below |
| 7 | +# |
| 8 | +#Company |
| 9 | +# |--- Resource (like device/service. Ex: VM) |
| 10 | +# |--- Data Source (Ex. CPU) |
| 11 | +# |--- Instance (of a Data Source on a resource. Ex. CPU-1) |
| 12 | +# |--- Data Point (the metric which is being monitored. Ex. %Used) |
| 13 | +# |- <Time> : <Metric Value> |
| 14 | +# |- <Time> : <Metric Value> |
| 15 | +# |... |
| 16 | +# |
5 | 17 | from logicmonitor_data_sdk.api.metrics import Metrics
|
6 | 18 | from logicmonitor_data_sdk.models import DataSource, \
|
7 | 19 | Resource, DataSourceInstance, DataPoint
|
8 | 20 |
|
9 |
| -# Configure API key authorization: LMv1 |
10 |
| -configuration = logicmonitor_data_sdk.Configuration(company='COMPANY', |
11 |
| - id='ACCESS_ID', |
12 |
| - key='ACCESS_KEY') |
13 |
| -# create an instance of the API class |
14 |
| -metric_api = Metrics(batch=True) |
15 |
| -seed(1) |
16 |
| -while True: |
17 |
| - metric_api.send_metrics(resource=Resource( |
18 |
| - ids={"system.hostname": "SampleDevice"}, create=True, name="SampleDevice", |
19 |
| - properties={"using.sdk": "true"}), datasource=DataSource( |
20 |
| - name="PusMetricsDS"), instance=DataSourceInstance(name="instance"), |
21 |
| - datapoint=DataPoint(name="dataPoint"), |
22 |
| - values={str(int(time.time())): str(random())}) |
23 |
| - time.sleep(10) |
| 21 | +# Configure SDK with Account and access information |
| 22 | +# On your LogicMonitor portal, create API token (LMv1) for user and get |
| 23 | +# Access Id and Access Key |
| 24 | +configuration = logicmonitor_data_sdk.Configuration(company='your_company', |
| 25 | + id='API_ACCESS_ID', |
| 26 | + key='API_ACCESS_KEY') |
| 27 | + |
| 28 | +# Create api handle for Metrics use case (we also support Logs) |
| 29 | +metric_api = Metrics() |
| 30 | + |
| 31 | +return_val = metric_api.send_metrics( |
| 32 | + resource=Resource( |
| 33 | + ids={"system.hostname": "SampleDevice"}, #Core Properties of the Resource |
| 34 | + create=True, #Auto-create resource if does not exist |
| 35 | + name="SampleDevice", #Name of the resource |
| 36 | + properties={"using.sdk": "true"}), #Additional Properties [Optional] |
| 37 | + datasource=DataSource( |
| 38 | + name="SampleDS"), #Name of data source is must. Rest optional |
| 39 | + instance=DataSourceInstance( |
| 40 | + name="SampleInstance"), #Name of instance is must. Rest optional |
| 41 | + datapoint=DataPoint( |
| 42 | + name="SampleDataPoint"), #The metric |
| 43 | + values={str(int(time.time())): str(random())} #Values at specific time(s) |
| 44 | +) |
| 45 | +print("Return Value = ",return_val) |
0 commit comments