Skip to content

Commit

Permalink
Merge pull request #22 from iLert/feature/metrics
Browse files Browse the repository at this point in the history
Feature/metrics
  • Loading branch information
yacut authored Jan 18, 2023
2 parents 2514b2c + 98b15d0 commit f850101
Show file tree
Hide file tree
Showing 10 changed files with 817 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 17.01.2023, Version 2.6.0

- add metrics
- add metric data sources
- add series

## 13.01.2023, Version 2.5.1

- fix missing json params in status page group
Expand Down
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ var apiRoutes = struct {
heartbeats string
incidents string
incidentTemplates string
metrics string
metricDataSources string
numbers string
schedules string
series string
services string
statusPages string
uptimeMonitors string
Expand All @@ -232,8 +235,11 @@ var apiRoutes = struct {
heartbeats: "/api/heartbeats",
incidents: "/api/incidents",
incidentTemplates: "/api/incident-templates",
metrics: "/api/metrics",
metricDataSources: "/api/metric-data-sources",
numbers: "/api/numbers",
schedules: "/api/schedules",
series: "/api/series",
services: "/api/services",
statusPages: "/api/status-pages",
uptimeMonitors: "/api/uptime-monitors",
Expand Down
33 changes: 33 additions & 0 deletions examples/metric/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"log"

"github.com/iLert/ilert-go/v2"
)

func main() {
var apiToken = "your API token"
client := ilert.NewClient(ilert.WithAPIToken(apiToken))

createMetricInput := &ilert.CreateMetricInput{
Metric: &ilert.Metric{
Name: "example",
AggregationType: ilert.MetricAggregationType.Average,
DisplayType: ilert.MetricDisplayType.Graph,
Metadata: &ilert.MetricProviderMetadata{
Query: "your prometheus query",
},
DataSource: &ilert.MetricDataSource{
ID: 0, // your metric data source id
},
},
}

result, err := client.CreateMetric(createMetricInput)
if err != nil {
log.Println(result)
log.Fatalln("ERROR:", err)
}
log.Printf("Metric:\n\n %+v\n", result.Metric)
}
32 changes: 32 additions & 0 deletions examples/metricdatasource/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"log"

"github.com/iLert/ilert-go/v2"
)

func main() {
var apiToken = "your API token"
client := ilert.NewClient(ilert.WithAPIToken(apiToken))

createDataSourceInput := &ilert.CreateMetricDataSourceInput{
MetricDataSource: &ilert.MetricDataSource{
Name: "example",
Type: ilert.MetricDataSourceType.Prometheus,
Metadata: &ilert.MetricDataSourceMetadata{
AuthType: ilert.MetricDataSourceAuthType.Basic,
BasicUser: "your prometheus username",
BasicPass: "your prometheus password",
Url: "your prometheus url",
},
},
}

result, err := client.CreateMetricDataSource(createDataSourceInput)
if err != nil {
log.Println(result)
log.Fatalln("ERROR:", err)
}
log.Printf("Metric Data Source:\n\n %+v\n", result.MetricDataSource)
}
26 changes: 26 additions & 0 deletions examples/series/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"log"

"github.com/iLert/ilert-go/v2"
)

func main() {
var apiToken = "your API token"
client := ilert.NewClient(ilert.WithAPIToken(apiToken))

createSingleSeriesInput := &ilert.CreateSingleSeriesInput{
Series: &ilert.SingleSeries{
Value: 500,
},
MetricKey: ilert.String("your metric integration key"),
}

err := client.CreateSingleSeries(createSingleSeriesInput)
if err != nil {
log.Fatalln("ERROR:", err)
} else {
log.Println("Series submitted successfully")
}
}
File renamed without changes.
Loading

0 comments on commit f850101

Please sign in to comment.