Prvi
This commit is contained in:
30
.dockerignore
Normal file
30
.dockerignore
Normal file
@@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
25
ShellyExporter.sln
Normal file
25
ShellyExporter.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.8.34330.188
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShellyExporter", "ShellyExporter\ShellyExporter.csproj", "{B776CDAB-5CD2-48A6-AFD6-20AD763C498B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B776CDAB-5CD2-48A6-AFD6-20AD763C498B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B776CDAB-5CD2-48A6-AFD6-20AD763C498B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B776CDAB-5CD2-48A6-AFD6-20AD763C498B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B776CDAB-5CD2-48A6-AFD6-20AD763C498B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {73A9AF68-001D-4498-B27C-514CC2FCC04C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
12
ShellyExporter/.config/dotnet-tools.json
Normal file
12
ShellyExporter/.config/dotnet-tools.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "8.0.0",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
25
ShellyExporter/Dockerfile
Normal file
25
ShellyExporter/Dockerfile
Normal file
@@ -0,0 +1,25 @@
|
||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
USER app
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["ShellyExporter/ShellyExporter.csproj", "ShellyExporter/"]
|
||||
RUN dotnet restore "./ShellyExporter/./ShellyExporter.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/ShellyExporter"
|
||||
RUN dotnet build "./ShellyExporter.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./ShellyExporter.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "ShellyExporter.dll"]
|
||||
37
ShellyExporter/Metrics.cs
Normal file
37
ShellyExporter/Metrics.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ShellyExporter
|
||||
{
|
||||
public class Metrics
|
||||
{
|
||||
public static async Task<StringBuilder> Get(string path, string name)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var client = new HttpClient();
|
||||
var response = await client.GetStringAsync(path);
|
||||
|
||||
dynamic responseObject = JsonConvert.DeserializeObject(response);
|
||||
|
||||
if (responseObject == null)
|
||||
return sb;
|
||||
|
||||
if (responseObject.meters != null)
|
||||
{
|
||||
sb.AppendLine($"meters_power_wats{{item=\"{name}\"}} {responseObject.meters[0].power}");
|
||||
sb.AppendLine($"meters_overpower_wats{{item=\"{name}\"}} " + responseObject.meters[0].overpower);
|
||||
sb.AppendLine($"meters_is_valid{{item=\"{name}\"}} " + (responseObject.meters[0].is_valid == "True" ? 1 : 0));
|
||||
sb.AppendLine($"meters_timestamp{{item=\"{name}\"}} " + responseObject.meters[0].timestamp);
|
||||
sb.AppendLine($"meters_power_total{{item=\"{name}\"}} " + responseObject.meters[0].total);
|
||||
}
|
||||
|
||||
if (responseObject.temperature != null)
|
||||
{
|
||||
sb.AppendLine($"temperature{{item=\"{name}\"}} " + responseObject.temperature);
|
||||
}
|
||||
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
ShellyExporter/Program.cs
Normal file
51
ShellyExporter/Program.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using ShellyExporter;
|
||||
using System.Xml.Linq;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
if (!builder.Environment.IsDevelopment())
|
||||
{
|
||||
builder.WebHost.UseKestrel();
|
||||
builder.WebHost.UseUrls(builder.Configuration["Kst:Url"]);
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Map("/metrics", () =>
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
foreach (var host in builder.Configuration.GetSection("Hosts").GetChildren())
|
||||
{
|
||||
sb.Append(Metrics.Get($"http://{host.Value}/status", host.Path.Replace("Hosts:", "")).Result);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
app.Run();
|
||||
52
ShellyExporter/Properties/launchSettings.json
Normal file
52
ShellyExporter/Properties/launchSettings.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5197"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "https://localhost:7217;http://localhost:5197"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_HTTPS_PORTS": "8081",
|
||||
"ASPNETCORE_HTTP_PORTS": "8080"
|
||||
},
|
||||
"publishAllPorts": true,
|
||||
"useSSL": true
|
||||
}
|
||||
},
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:37965",
|
||||
"sslPort": 44300
|
||||
}
|
||||
}
|
||||
}
|
||||
28
ShellyExporter/ShellyExporter.csproj
Normal file
28
ShellyExporter/ShellyExporter.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<UserSecretsId>c4df3427-71fa-4233-816b-8788d2eaa613</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
ShellyExporter/ShellyExporter.http
Normal file
6
ShellyExporter/ShellyExporter.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@ShellyExporter_HostAddress = http://localhost:5197
|
||||
|
||||
GET {{ShellyExporter_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
8
ShellyExporter/appsettings.Development.json
Normal file
8
ShellyExporter/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
16
ShellyExporter/appsettings.json
Normal file
16
ShellyExporter/appsettings.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kst": {
|
||||
"Url": "http://192.168.111.77:5050"
|
||||
},
|
||||
"Hosts": {
|
||||
"david": "192.168.1.60",
|
||||
"nekaj": "192.168.1.60"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user