Backend and client libraries to collect and process messages: logs, metrics (performance counters) and keep-alive statuses. System can operate with Azure Queue or RabbitMQ for messages exchange.
- Prepare Azure Service Bus namespace and queue
- Prepare SQL Database and execute src/db.sql
- Fill ServiceConfiguration files in MonikCloud project
- Deploy service
- Add new nuget package source: https://www.myget.org/F/totopolis/
- Install last package Monik.Client.Azure to your project
- Sample:
////////////////////////////////
// Initialize (DI container use)
////////////////////////////////
container.Register<IMonikSender>(new AzureSender("[Service Bus connection string]", "[Queue name]"));
container.Register<IMonikSettings>(new ClientSettings()
{
SourceName = "[Source name]",
InstanceName = "[Instance name]",
AutoKeepAliveEnable = true
});
container.Register<IMonik, MonikClient>().AsSingleton();
var mon = container.Resolve<IMonik>();
mon.ApplicationInfo("Hello world!");
mon.Measure("Packets", AggregationType.Accumulator, 1);
mon.Measure("DbProcedureExecTime", AggregationType.Gauge, 0.27);
/////////////////
// Old-school way
/////////////////
var sender = new AzureSender("[Service Bus connection string]", "[Queue name]");
M.Initialize(sender, "[Source name]", "[Source instance]", aAutoKeepAliveEnable: true);
// Send message
M.SecurityInfo("User John log in");
M.ApplicationError("Some error in application");
M.LogicInfo($"{processName} completed, processid={processId}");
- AggregationType.Accumulator: num of packets, executes, etc...
- AggregationType.Gauge: time of any process (db or api method execute)
Method http://monikserver/keepalive-status can be used for Zabbix/Nagios monitoring
- SecurityVerbose:
- SecurityInfo: user XX log-in or log-out
- SecurityWarning: user XX bad username or password
- SecurityError: domain or service not accessible
- ApplicationVerbose: debug and trace
- ApplicationInfo:
- ApplicationWarning: service start or shutdown
- ApplicationError: any exceptions
- LogicVerbose:
- LogicInfo: something calculated
- LogicWarning: user request's bad params (for the service)
- LogicError: logic violation
Some server methods require a token in the Authorization header
Here is an example of token creation process with nodejs
:
Generate a secret key
node -e "console.log(require('crypto').randomBytes(256).toString('base64'));"
Put the key in the appsettings.json
and deploy with the new config
{
"AuthSecretKey": "secret-key"
}
Create a token with a subject sub
and an expiration timestamp exp
, sign it with the previously generated key
node -e "console.log(require('jsonwebtoken').sign({sub:'name', exp:1550102400}, Buffer.from('secret_key', 'base64')));"
Send the token with requests in the Authorization header
curl -X DELETE -H 'Authorization: Bearer <token>' -i http://monikserver/instances/1